|
@@ -18,7 +18,7 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|
|
/**
|
|
|
* @type {Map<string, string>}
|
|
|
*/
|
|
|
- private variableName: Map <string, string> = new Map <string, string> ();
|
|
|
+ private variableNames: Map <string, string> = new Map <string, string> ();
|
|
|
|
|
|
/**
|
|
|
* @param variableDeclarationNode
|
|
@@ -46,8 +46,8 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|
|
|
|
|
estraverse.replace(node.id, {
|
|
|
enter: (node) => {
|
|
|
- this.variableName.set(node.name, Utils.getRandomVariableName());
|
|
|
- node.name = this.variableName.get(node.name);
|
|
|
+ this.variableNames.set(node.name, Utils.getRandomVariableName());
|
|
|
+ node.name = this.variableNames.get(node.name);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -60,8 +60,7 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|
|
* @param variableParentNode
|
|
|
*/
|
|
|
private replaceVariableCalls (variableDeclarationNode: any, variableParentNode: any): void {
|
|
|
- let scopeNode: any,
|
|
|
- statementNode: any;
|
|
|
+ let scopeNode: any;
|
|
|
|
|
|
if (variableDeclarationNode.kind === 'var') {
|
|
|
scopeNode = NodeUtils.getNodeScope(
|
|
@@ -71,9 +70,42 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|
|
scopeNode = variableParentNode;
|
|
|
}
|
|
|
|
|
|
+ let isNodeAfterVariableDeclaratorFlag: boolean = false,
|
|
|
+ isNodeBeforeVariableDeclaratorFlag: boolean = true,
|
|
|
+ functionParentScope: any,
|
|
|
+ functionNextNode: any,
|
|
|
+ functionIndex: number = -1;
|
|
|
+
|
|
|
estraverse.replace(scopeNode, {
|
|
|
enter: (node, parentNode) => {
|
|
|
- this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableName);
|
|
|
+ if (node.parentNode && (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression')) {
|
|
|
+ functionParentScope = NodeUtils.getNodeScope(
|
|
|
+ node
|
|
|
+ );
|
|
|
+
|
|
|
+ functionIndex = functionParentScope.body.indexOf(node);
|
|
|
+
|
|
|
+ if (functionIndex >= 0) {
|
|
|
+ functionNextNode = functionParentScope.body[functionIndex + 1];
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|