Fix for incorrect obfuscation of function names

This commit is contained in:
sanex3339
2016-06-17 21:08:10 +03:00
parent 0735f57771
commit d125f8d4ea
5 changed files with 58 additions and 46 deletions
@@ -26,14 +26,14 @@ export class CatchClauseObfuscator extends NodeObfuscator {
* @param catchClauseNode
*/
public obfuscateNode (catchClauseNode: ICatchClauseNode): void {
this.storeCatchClauseParam(catchClauseNode);
this.replaceCatchClauseParam(catchClauseNode);
this.replaceCatchClauseParamInBlockStatement(catchClauseNode);
}
/**
* @param catchClauseNode
*/
private replaceCatchClauseParam (catchClauseNode: ICatchClauseNode): void {
private storeCatchClauseParam (catchClauseNode: ICatchClauseNode): void {
estraverse.traverse(catchClauseNode.param, {
leave: (node: INode): any => this.storeIdentifiersNames(node, this.catchClauseParam)
});
@@ -42,7 +42,7 @@ export class CatchClauseObfuscator extends NodeObfuscator {
/**
* @param catchClauseNode
*/
private replaceCatchClauseParamInBlockStatement (catchClauseNode: ICatchClauseNode): void {
private replaceCatchClauseParam (catchClauseNode: ICatchClauseNode): void {
estraverse.replace(catchClauseNode, {
leave: (node: INode, parentNode: INode): any => {
this.replaceIdentifiersWithRandomNames(node, parentNode, this.catchClauseParam);
@@ -32,14 +32,14 @@ export class FunctionDeclarationObfuscator extends NodeObfuscator {
return;
}
this.storeFunctionName(functionDeclarationNode);
this.replaceFunctionName(functionDeclarationNode);
this.replaceFunctionCalls(functionDeclarationNode);
}
/**
* @param functionDeclarationNode
*/
private replaceFunctionName (functionDeclarationNode: IFunctionDeclarationNode): void {
private storeFunctionName (functionDeclarationNode: IFunctionDeclarationNode): void {
estraverse.traverse(functionDeclarationNode.id, {
leave: (node: INode): any => this.storeIdentifiersNames(node, this.functionName)
});
@@ -48,7 +48,7 @@ export class FunctionDeclarationObfuscator extends NodeObfuscator {
/**
* @param functionDeclarationNode
*/
private replaceFunctionCalls (functionDeclarationNode: IFunctionDeclarationNode): void {
private replaceFunctionName (functionDeclarationNode: IFunctionDeclarationNode): void {
let scopeNode: INode = NodeUtils.getBlockScopeOfNode(
functionDeclarationNode
);
+22 -14
View File
@@ -26,29 +26,37 @@ export class FunctionObfuscator extends NodeObfuscator {
* @param functionNode
*/
public obfuscateNode (functionNode: IFunctionNode): void {
this.storeFunctionParams(functionNode);
this.replaceFunctionParams(functionNode);
this.replaceFunctionParamsInBlockStatement(functionNode);
}
/**
* @param functionNode
*/
private storeFunctionParams (functionNode: IFunctionNode): void {
functionNode.params
.forEach((paramsNode: INode) => {
estraverse.traverse(paramsNode, {
leave: (node: INode): any => this.storeIdentifiersNames(node, this.functionParams)
});
});
}
/**
* @param functionNode
*/
private replaceFunctionParams (functionNode: IFunctionNode): void {
functionNode.params.forEach((paramsNode: INode) => {
estraverse.traverse(paramsNode, {
leave: (node: INode): any => this.storeIdentifiersNames(node, this.functionParams)
});
});
}
/**
* @param functionNode
*/
private replaceFunctionParamsInBlockStatement (functionNode: IFunctionNode): void {
estraverse.replace(functionNode, {
let replaceVisitor: estraverse.Visitor = {
leave: (node: INode, parentNode: INode): any => {
this.replaceIdentifiersWithRandomNames(node, parentNode, this.functionParams);
}
});
};
functionNode.params
.forEach((paramsNode: INode) => {
estraverse.replace(paramsNode, replaceVisitor);
});
estraverse.replace(functionNode.body, replaceVisitor);
}
}
@@ -36,14 +36,14 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
return;
}
this.replaceVariableName(variableDeclarationNode);
this.replaceVariableCalls(variableDeclarationNode, parentNode);
this.storeVariableNames(variableDeclarationNode);
this.replaceVariableNames(variableDeclarationNode, parentNode);
}
/**
* @param variableDeclarationNode
*/
private replaceVariableName (variableDeclarationNode: IVariableDeclarationNode): void {
private storeVariableNames (variableDeclarationNode: IVariableDeclarationNode): void {
variableDeclarationNode.declarations
.forEach((declarationNode: IVariableDeclaratorNode) => {
estraverse.traverse(declarationNode.id, {
@@ -56,7 +56,7 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
* @param variableDeclarationNode
* @param variableParentNode
*/
private replaceVariableCalls (variableDeclarationNode: IVariableDeclarationNode, variableParentNode: INode): void {
private replaceVariableNames (variableDeclarationNode: IVariableDeclarationNode, variableParentNode: INode): void {
let scopeNode: INode = variableDeclarationNode.kind === 'var' ? NodeUtils.getBlockScopeOfNode(
variableDeclarationNode
) : variableParentNode,