Browse Source

Merge remote-tracking branch 'origin/dev'

sanex3339 9 năm trước cách đây
mục cha
commit
df783473ee

+ 6 - 20
src/node-obfuscators/VariableDeclarationObfuscator.js

@@ -35,35 +35,21 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
     }
     replaceVariableCalls(variableDeclarationNode, variableParentNode) {
         let scopeNode;
-        if (variableDeclarationNode.kind === 'var') {
-            scopeNode = NodeUtils_1.NodeUtils.getNodeScope(variableDeclarationNode);
-        }
-        else {
-            scopeNode = variableParentNode;
-        }
-        let isNodeAfterVariableDeclaratorFlag = false, isNodeBeforeVariableDeclaratorFlag = true, functionParentScope, functionNextNode, functionIndex = -1;
+        scopeNode = variableDeclarationNode.kind === 'var' ? NodeUtils_1.NodeUtils.getNodeScope(variableDeclarationNode) : variableParentNode;
+        let isNodeAfterVariableDeclaratorFlag = false;
         estraverse.replace(scopeNode, {
             enter: (node, parentNode) => {
                 if (node.type === 'FunctionDeclaration' ||
                     node.type === 'FunctionExpression' ||
                     node.type === 'ArrowFunctionExpression') {
-                    functionParentScope = NodeUtils_1.NodeUtils.getNodeScope(node);
-                    if (NodeUtils_1.NodeUtils.isBlockStatementNode(functionParentScope)) {
-                        functionIndex = functionParentScope.body.indexOf(node);
-                        if (functionIndex >= 0) {
-                            functionNextNode = functionParentScope.body[functionIndex + 1];
+                    estraverse.replace(node, {
+                        enter: (node, parentNode) => {
+                            this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
                         }
-                    }
-                    isNodeAfterVariableDeclaratorFlag = true;
-                }
-                if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
-                    isNodeAfterVariableDeclaratorFlag = false;
-                    functionNextNode = undefined;
-                    functionIndex = -1;
+                    });
                 }
                 if (node === variableDeclarationNode) {
                     isNodeAfterVariableDeclaratorFlag = true;
-                    isNodeBeforeVariableDeclaratorFlag = false;
                 }
                 if (isNodeAfterVariableDeclaratorFlag) {
                     this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);

+ 9 - 31
src/node-obfuscators/VariableDeclarationObfuscator.ts

@@ -68,21 +68,12 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
     private replaceVariableCalls (variableDeclarationNode: IVariableDeclarationNode, variableParentNode: ITreeNode): void {
         let scopeNode: ITreeNode;
 
-        if (variableDeclarationNode.kind === 'var') {
-            scopeNode = NodeUtils.getNodeScope(
-                variableDeclarationNode
-            );
-        } else {
-            scopeNode = variableParentNode;
-        }
+        scopeNode = variableDeclarationNode.kind === 'var' ? NodeUtils.getNodeScope(
+            variableDeclarationNode
+        ) : variableParentNode;
 
-        let isNodeAfterVariableDeclaratorFlag: boolean = false,
-            isNodeBeforeVariableDeclaratorFlag: boolean = true,
-            functionParentScope: ITreeNode,
-            functionNextNode: ITreeNode,
-            functionIndex: number = -1;
+        let isNodeAfterVariableDeclaratorFlag: boolean = false;
 
-        //TODO: REFACTOR THIS
         estraverse.replace(scopeNode, {
             enter: (node: ITreeNode, parentNode: ITreeNode) => {
                 if (
@@ -90,28 +81,15 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
                     node.type === 'FunctionExpression' ||
                     node.type === 'ArrowFunctionExpression'
                 ) {
-                    functionParentScope = NodeUtils.getNodeScope(node);
-
-                    if (NodeUtils.isBlockStatementNode(functionParentScope)) {
-                        functionIndex = functionParentScope.body.indexOf(node);
-
-                        if (functionIndex >= 0) {
-                            functionNextNode = functionParentScope.body[functionIndex + 1];
+                    estraverse.replace(node, {
+                        enter: (node: ITreeNode, parentNode: ITreeNode) => {
+                            this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
                         }
-                    }
-
-                    isNodeAfterVariableDeclaratorFlag = true;
-                }
-
-                if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
-                    isNodeAfterVariableDeclaratorFlag = false;
-                    functionNextNode = undefined;
-                    functionIndex = -1;
+                    });
                 }
 
                 if (node === variableDeclarationNode) {
                     isNodeAfterVariableDeclaratorFlag = true;
-                    isNodeBeforeVariableDeclaratorFlag = false;
                 }
 
                 if (isNodeAfterVariableDeclaratorFlag) {
@@ -120,4 +98,4 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
             }
         });
     }
-}
+}

+ 1 - 1
tests/dev-test.js

@@ -1,6 +1,6 @@
 var JavaScriptObfuscator = require('../index.js');
 var obfuscatedCode = JavaScriptObfuscator.obfuscate(`
-   (function(){
+    (function(){
         var result = 1,
             term1 = 0,
             term2 = 1,

+ 1 - 1
tests/dev-test.ts

@@ -2,7 +2,7 @@ var JavaScriptObfuscator = require('../index.js');
 
 var obfuscatedCode = JavaScriptObfuscator.obfuscate(
     `
-   (function(){
+    (function(){
         var result = 1,
             term1 = 0,
             term2 = 1,