@@ -935,10 +935,14 @@ class StringArrayCallsReplacer{
935
935
replace ( ) {
936
936
this . _initializeVariableAndFunctionWrappers ( ) ;
937
937
938
+ var i = 0 ;
938
939
var thisObj = this ;
939
940
estraverse . traverse ( this . ast , {
940
941
enter : function ( node ) {
941
942
if ( astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
943
+ i ++ ;
944
+ console . log ( `Replacing calls in scope nr. ${ i } .` ) ;
945
+ thisObj . logger . info ( `Replacing calls in scope nr. ${ i } .` ) ;
942
946
thisObj . _fixStringArrayCallsInLexicalScope ( node ) ;
943
947
}
944
948
} ,
@@ -1200,19 +1204,22 @@ class StringArrayCallsReplacer{
1200
1204
let wrapperNamesSearchedInCurrentScope = this . _getVariableWrapperNamesToSearchInCurrentScope ( nodeWithBody ,
1201
1205
curentNodeWrapperNames , allWrapperNames ) ;
1202
1206
1203
-
1204
- for ( let i = 0 ; i < wrapperNamesSearchedInCurrentScope . length ; i ++ ) {
1205
- const identifierNodesFromCalls = esquery ( nodeWithBody , `CallExpression[callee.type='Identifier'] > `
1206
- + `Identifier[name='${ wrapperNamesSearchedInCurrentScope [ i ] } ']` ) ;
1207
- identifierNodesFromCalls . forEach ( ( identifierNode ) => {
1208
- const lexicalScope = astOperations . ASTRelations . getParentNodeWithLexicalScope ( identifierNode ) ;
1209
- if ( nodeWithBody == lexicalScope ) {
1210
- const callExpression = identifierNode . parent ;
1211
- wrapperCalls . push ( callExpression ) ;
1207
+ var firstNode = true ;
1208
+ estraverse . traverse ( nodeWithBody , {
1209
+ enter : function ( node , parent ) {
1210
+ if ( ! firstNode && astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
1211
+ this . skip ( ) ;
1212
1212
}
1213
- } ) ;
1214
- }
1213
+ firstNode = false ;
1215
1214
1215
+ if ( ( node . type == 'Identifier' ) && ( parent . type == 'CallExpression' ) ) {
1216
+ let identifierName = node . name ;
1217
+ if ( wrapperNamesSearchedInCurrentScope . includes ( identifierName ) ) {
1218
+ wrapperCalls . push ( parent ) ;
1219
+ }
1220
+ }
1221
+ } ,
1222
+ } ) ;
1216
1223
return wrapperCalls ;
1217
1224
}
1218
1225
@@ -1246,36 +1253,61 @@ class StringArrayCallsReplacer{
1246
1253
}
1247
1254
1248
1255
_wrapperIsRedefinedInCurrentScopeAsNewVariable ( wrapperName , nodeWithBody ) {
1249
- const allVariableDeclarators = esquery ( nodeWithBody , `VariableDeclarator[id.type='Identifier'][id.name='${ wrapperName } ']` ) ;
1250
- for ( let i = 0 ; i < allVariableDeclarators . length ; i ++ ) {
1251
- const lexicalScope = astOperations . ASTRelations . getParentNodeWithLexicalScope ( allVariableDeclarators [ i ] ) ;
1252
- if ( lexicalScope == nodeWithBody ) {
1253
- return true ;
1254
- }
1255
- }
1256
- return false ;
1256
+ var firstNode = true ;
1257
+ var foundRedefined = false ;
1258
+ estraverse . traverse ( nodeWithBody , {
1259
+ enter : function ( node , parent ) {
1260
+ if ( ! firstNode && astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
1261
+ this . skip ( ) ;
1262
+ }
1263
+ firstNode = false ;
1264
+
1265
+ if ( ( node . type == 'Identifier' ) && ( node . name == wrapperName ) && ( parent . type == 'VariableDeclarator' ) ) {
1266
+ foundRedefined = true ;
1267
+ this . break ( ) ;
1268
+ }
1269
+ } ,
1270
+ } ) ;
1271
+ return foundRedefined ;
1257
1272
}
1258
1273
1259
1274
_wrapperIsRedefinedInCurrentScopeAsNewFunction ( wrapperName , nodeWithBody ) {
1260
- const allFunctionDeclarations = esquery ( nodeWithBody , `FunctionDeclaration[id.type='Identifier'][id.name='${ wrapperName } ']` ) ;
1261
- for ( let i = 0 ; i < allFunctionDeclarations . length ; i ++ ) {
1262
- const lexicalScope = astOperations . ASTRelations . getParentNodeWithLexicalScope ( allFunctionDeclarations [ i ] ) ;
1263
- if ( lexicalScope == nodeWithBody ) {
1264
- return true ;
1265
- }
1266
- }
1267
- return false ;
1275
+ var firstNode = true ;
1276
+ var foundRedefined = false ;
1277
+ estraverse . traverse ( nodeWithBody , {
1278
+ enter : function ( node , parent ) {
1279
+ if ( ! firstNode && astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
1280
+ this . skip ( ) ;
1281
+ }
1282
+ firstNode = false ;
1283
+
1284
+ if ( ( node . type == 'Identifier' ) && ( node . name == wrapperName ) && ( parent . type == 'FunctionDeclaration' ) ) {
1285
+ foundRedefined = true ;
1286
+ this . break ( ) ;
1287
+ }
1288
+ } ,
1289
+ } ) ;
1290
+ return foundRedefined ;
1268
1291
}
1269
1292
1270
1293
_wrapperIsRedefinedInCurrentScopeAsAssignmentExpression ( wrapperName , nodeWithBody ) {
1271
- const allAssignmentExpressions = esquery ( nodeWithBody , `AssignmentExpression[left.type='Identifier'][left.name='${ wrapperName } ']` ) ;
1272
- for ( let i = 0 ; i < allAssignmentExpressions . length ; i ++ ) {
1273
- const lexicalScope = astOperations . ASTRelations . getParentNodeWithLexicalScope ( allAssignmentExpressions [ i ] ) ;
1274
- if ( lexicalScope == nodeWithBody ) {
1275
- return true ;
1276
- }
1277
- }
1278
- return false ;
1294
+ var firstNode = true ;
1295
+ var foundRedefined = false ;
1296
+ estraverse . traverse ( nodeWithBody , {
1297
+ enter : function ( node , parent ) {
1298
+ if ( ! firstNode && astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
1299
+ this . skip ( ) ;
1300
+ }
1301
+ firstNode = false ;
1302
+
1303
+ if ( ( node . type == 'Identifier' ) && ( node . name == wrapperName )
1304
+ && ( parent . type == 'AssignmentExpression' ) && parent . left && ( parent . left . name == wrapperName ) ) {
1305
+ foundRedefined = true ;
1306
+ this . break ( ) ;
1307
+ }
1308
+ } ,
1309
+ } ) ;
1310
+ return foundRedefined ;
1279
1311
}
1280
1312
1281
1313
_wrapperWasDefinedInAScopeThatIsParentOfCurrentScope ( wrapper , nodeWithBody ) {
@@ -1430,17 +1462,22 @@ class StringArrayCallsReplacer{
1430
1462
let wrapperNamesForSearching = this . _getFunctionWrapperNamesToSearchInCurrentScope ( nodeWithBody ,
1431
1463
curentNodeWrapperNames , allWrapperNames ) ;
1432
1464
1433
- for ( let i = 0 ; i < wrapperNamesForSearching . length ; i ++ ) {
1434
- const identifierNodesFromCalls = esquery ( nodeWithBody , `CallExpression[callee.type='Identifier'] > `
1435
- + `Identifier[name='${ wrapperNamesForSearching [ i ] } ']` ) ;
1436
- identifierNodesFromCalls . forEach ( ( node ) => {
1437
- const lexicalScope = astOperations . ASTRelations . getParentNodeWithLexicalScope ( node ) ;
1438
- if ( nodeWithBody == lexicalScope ) {
1439
- const callExpression = node . parent ;
1440
- wrapperCalls . push ( callExpression ) ;
1465
+ var firstNode = true ;
1466
+ estraverse . traverse ( nodeWithBody , {
1467
+ enter : function ( node , parent ) {
1468
+ if ( ! firstNode && astOperations . NodeChecker . nodeHasBodyWithLexicalScope ( node ) ) {
1469
+ this . skip ( ) ;
1441
1470
}
1442
- } ) ;
1443
- }
1471
+ firstNode = false ;
1472
+
1473
+ if ( ( node . type == 'Identifier' ) && ( parent . type == 'CallExpression' ) ) {
1474
+ let identifierName = node . name ;
1475
+ if ( wrapperNamesForSearching . includes ( identifierName ) ) {
1476
+ wrapperCalls . push ( parent ) ;
1477
+ }
1478
+ }
1479
+ } ,
1480
+ } ) ;
1444
1481
1445
1482
return wrapperCalls ;
1446
1483
}
@@ -1505,9 +1542,11 @@ class StringArraySyntheticTransformer extends stageDeobfuscator.TransformerDeobf
1505
1542
}
1506
1543
1507
1544
_replaceStringArrayCallsWithCorrespondingString ( ) {
1545
+ this . logger . info ( 'Replacing stringarray calls with actual strings - START.' ) ;
1508
1546
this . stringArrayCallsReplacer = new StringArrayCallsReplacer ( this . logger , this . obfuscatedSourceCode ,
1509
1547
this . ast , this . stringArrayCallWrapperTemplateFunctionNames ) ;
1510
1548
this . stringArrayCallsReplacer . replace ( ) ;
1549
+ this . logger . info ( 'Replacing stringarray calls with actual strings - FINISH.' ) ;
1511
1550
}
1512
1551
1513
1552
}
0 commit comments