From d764720e62d476771e6a530b8869e24efbc6da36 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Thu, 1 Sep 2016 17:46:37 +0300 Subject: [PATCH] fixed tests and codestyle --- dist/index.js | 8 ++++---- src/node-obfuscators/CatchClauseObfuscator.ts | 4 +--- .../FunctionDeclarationObfuscator.ts | 4 +--- src/node-obfuscators/FunctionObfuscator.ts | 4 +--- .../VariableDeclarationObfuscator.ts | 4 +--- .../VariableDeclarationObfuscator.spec.ts | 12 ++++++------ 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index 276eee00..00ecb006 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2413,7 +2413,7 @@ var CatchClauseObfuscator = function (_AbstractNodeObfuscat) { NodeUtils_1.NodeUtils.typedReplace(catchClauseNode.param, NodeType_1.NodeType.Identifier, { leave: function leave(node) { - _this2.identifierReplacer.storeNames(node.name); + return _this2.identifierReplacer.storeNames(node.name); } }); } @@ -2487,7 +2487,7 @@ var FunctionDeclarationObfuscator = function (_AbstractNodeObfuscat) { NodeUtils_1.NodeUtils.typedReplace(functionDeclarationNode.id, NodeType_1.NodeType.Identifier, { leave: function leave(node) { - _this2.identifierReplacer.storeNames(node.name); + return _this2.identifierReplacer.storeNames(node.name); } }); } @@ -2560,7 +2560,7 @@ var FunctionObfuscator = function (_AbstractNodeObfuscat) { functionNode.params.forEach(function (paramsNode) { NodeUtils_1.NodeUtils.typedReplace(paramsNode, NodeType_1.NodeType.Identifier, { leave: function leave(node) { - _this2.identifierReplacer.storeNames(node.name); + return _this2.identifierReplacer.storeNames(node.name); } }); }); @@ -2943,7 +2943,7 @@ var VariableDeclarationObfuscator = function (_AbstractNodeObfuscat) { variableDeclarationNode.declarations.forEach(function (declarationNode) { NodeUtils_1.NodeUtils.typedReplace(declarationNode.id, NodeType_1.NodeType.Identifier, { leave: function leave(node) { - _this2.identifierReplacer.storeNames(node.name); + return _this2.identifierReplacer.storeNames(node.name); } }); }); diff --git a/src/node-obfuscators/CatchClauseObfuscator.ts b/src/node-obfuscators/CatchClauseObfuscator.ts index ec379afc..e09da399 100644 --- a/src/node-obfuscators/CatchClauseObfuscator.ts +++ b/src/node-obfuscators/CatchClauseObfuscator.ts @@ -50,9 +50,7 @@ export class CatchClauseObfuscator extends AbstractNodeObfuscator { */ private storeCatchClauseParam (catchClauseNode: ICatchClauseNode): void { NodeUtils.typedReplace(catchClauseNode.param, NodeType.Identifier, { - leave: (node: IIdentifierNode) => { - this.identifierReplacer.storeNames(node.name) - } + leave: (node: IIdentifierNode) => this.identifierReplacer.storeNames(node.name) }); } diff --git a/src/node-obfuscators/FunctionDeclarationObfuscator.ts b/src/node-obfuscators/FunctionDeclarationObfuscator.ts index e30f37bf..89810dd0 100644 --- a/src/node-obfuscators/FunctionDeclarationObfuscator.ts +++ b/src/node-obfuscators/FunctionDeclarationObfuscator.ts @@ -56,9 +56,7 @@ export class FunctionDeclarationObfuscator extends AbstractNodeObfuscator { */ private storeFunctionName (functionDeclarationNode: IFunctionDeclarationNode): void { NodeUtils.typedReplace(functionDeclarationNode.id, NodeType.Identifier, { - leave: (node: IIdentifierNode) => { - this.identifierReplacer.storeNames(node.name) - } + leave: (node: IIdentifierNode) => this.identifierReplacer.storeNames(node.name) }); } diff --git a/src/node-obfuscators/FunctionObfuscator.ts b/src/node-obfuscators/FunctionObfuscator.ts index 36f8bc03..2ec3340a 100644 --- a/src/node-obfuscators/FunctionObfuscator.ts +++ b/src/node-obfuscators/FunctionObfuscator.ts @@ -52,9 +52,7 @@ export class FunctionObfuscator extends AbstractNodeObfuscator { functionNode.params .forEach((paramsNode: INode) => { NodeUtils.typedReplace(paramsNode, NodeType.Identifier, { - leave: (node: IIdentifierNode) => { - this.identifierReplacer.storeNames(node.name) - } + leave: (node: IIdentifierNode) => this.identifierReplacer.storeNames(node.name) }); }); } diff --git a/src/node-obfuscators/VariableDeclarationObfuscator.ts b/src/node-obfuscators/VariableDeclarationObfuscator.ts index a47d8a39..6f9a9dde 100644 --- a/src/node-obfuscators/VariableDeclarationObfuscator.ts +++ b/src/node-obfuscators/VariableDeclarationObfuscator.ts @@ -60,9 +60,7 @@ export class VariableDeclarationObfuscator extends AbstractNodeObfuscator { variableDeclarationNode.declarations .forEach((declarationNode: IVariableDeclaratorNode) => { NodeUtils.typedReplace(declarationNode.id, NodeType.Identifier, { - leave: (node: IIdentifierNode) => { - this.identifierReplacer.storeNames(node.name) - } + leave: (node: IIdentifierNode) => this.identifierReplacer.storeNames(node.name) }); }); } diff --git a/test/functional-tests/node-obfuscators/VariableDeclarationObfuscator.spec.ts b/test/functional-tests/node-obfuscators/VariableDeclarationObfuscator.spec.ts index ac7ba2a8..cfbf7d10 100644 --- a/test/functional-tests/node-obfuscators/VariableDeclarationObfuscator.spec.ts +++ b/test/functional-tests/node-obfuscators/VariableDeclarationObfuscator.spec.ts @@ -18,8 +18,8 @@ describe('VariableDeclarationObfuscator', () => { Object.assign({}, NO_CUSTOM_NODES_PRESET) ); - assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){6} *= *'\\x61\\x62\\x63';/); - assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){6}\);/); + assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){5,6} *= *'\\x61\\x62\\x63';/); + assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){5,6}\);/); }); it('should obfuscate variable call (`identifier` node) outside of block scope of node in which this variable was declared with `var` kind', () => { @@ -35,7 +35,7 @@ describe('VariableDeclarationObfuscator', () => { Object.assign({}, NO_CUSTOM_NODES_PRESET) ); - assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){6}\);/); + assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){5,6}\);/); }); it('should not obfuscate variable call (`identifier` node) outside of block scope of node in which this variable was declared with `let` kind', () => { @@ -78,7 +78,7 @@ describe('VariableDeclarationObfuscator', () => { }); it('should obfuscate variable call (`identifier` node) before variable declaration if this call is inside function body', () => { - assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){6}\['\\x69\\x74\\x65\\x6d'\]\);/); + assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){5,6}\['\\x69\\x74\\x65\\x6d'\]\);/); }); it('should not obfuscate variable call (`identifier` node) before variable declaration', () => { @@ -103,7 +103,7 @@ describe('VariableDeclarationObfuscator', () => { Object.assign({}, NO_CUSTOM_NODES_PRESET) ); - assert.match(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){6} *= *\{'\\x74\\x65\\x73\\x74/); + assert.match(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){5,6} *= *\{'\\x74\\x65\\x73\\x74/); }); it('shouldn\'t replace computed member expression identifier', () => { @@ -123,7 +123,7 @@ describe('VariableDeclarationObfuscator', () => { Object.assign({}, NO_CUSTOM_NODES_PRESET) ); - assert.match(obfuscationResult.getObfuscatedCode(), /_0x([a-z0-9]){6}\['\\x74\\x65\\x73\\x74'\]/); + assert.match(obfuscationResult.getObfuscatedCode(), /_0x([a-z0-9]){5,6}\['\\x74\\x65\\x73\\x74'\]/); }); }); });