From ff0029f6f034c58142a95ab2efa177fcea1be677 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Tue, 3 Jan 2017 20:58:18 +0300 Subject: [PATCH] increased runtime speed with encoding: fixed test --- dist/index.js | 4 +--- src/Obfuscator.ts | 2 -- .../StringArrayBase64DecodeNodeTemplate.ts | 2 +- .../string-array-nodes/StringArrayCallsWrapper.spec.ts | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index c94186b3..5d6fdab4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2435,9 +2435,7 @@ var Obfuscator = Obfuscator_1 = function () { if (this.options.controlFlowFlattening) { astTree = this.transformAstTree(astTree, VisitorDirection_1.VisitorDirection.leave, this.nodeTransformersFactory(Obfuscator_1.nodeControlFlowTransformersMap)); } - console.time(); astTree = this.transformAstTree(astTree, VisitorDirection_1.VisitorDirection.enter, this.nodeTransformersFactory(Obfuscator_1.nodeObfuscatorsMap)); - console.timeEnd(); this.obfuscationEventEmitter.emit(ObfuscationEvents_1.ObfuscationEvents.AfterObfuscation, astTree, stackTraceData); return astTree; } @@ -7609,7 +7607,7 @@ exports.SelfDefendingTemplate = SelfDefendingTemplate; function StringArrayBase64DecodeNodeTemplate() { - return " \n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {stringArrayCallsWrapperName}.base64DecodeUnicode = function (str) {\n var string = atob(str);\n var newStringChars = [];\n \n for (var i = 0, length = string.length; i < length; i++) {\n newStringChars += '%' + ('00' + string.charCodeAt(i).toString(16)).slice(-2);\n }\n \n return decodeURIComponent(newStringChars);\n };\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n if (!{stringArrayCallsWrapperName}.data[index]) {\n {selfDefendingCode}\n \n value = {stringArrayCallsWrapperName}.base64DecodeUnicode(value);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = {stringArrayCallsWrapperName}.data[index];\n } \n "; + return " \n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {stringArrayCallsWrapperName}.base64DecodeUnicode = function (str) {\n var string = atob(str);\n var newStringChars = [];\n \n for (var i = 0, length = string.length; i < length; i++) {\n newStringChars += '%' + ('00' + string.charCodeAt(i).toString(16)).slice(-2);\n }\n \n return decodeURIComponent(newStringChars);\n };\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n if ({stringArrayCallsWrapperName}.data[index] === undefined) {\n {selfDefendingCode}\n \n value = {stringArrayCallsWrapperName}.base64DecodeUnicode(value);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = {stringArrayCallsWrapperName}.data[index];\n } \n "; } exports.StringArrayBase64DecodeNodeTemplate = StringArrayBase64DecodeNodeTemplate; diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index 354c14da..1b550806 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -137,13 +137,11 @@ export class Obfuscator implements IObfuscator { } // second pass: nodes obfuscation - console.time(); astTree = this.transformAstTree( astTree, VisitorDirection.enter, this.nodeTransformersFactory(Obfuscator.nodeObfuscatorsMap) ); - console.timeEnd(); this.obfuscationEventEmitter.emit(ObfuscationEvents.AfterObfuscation, astTree, stackTraceData); diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts b/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts index 641af33b..a1a7e48a 100644 --- a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts +++ b/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts @@ -22,7 +22,7 @@ export function StringArrayBase64DecodeNodeTemplate (): string { {stringArrayCallsWrapperName}.initialized = true; } - if (!{stringArrayCallsWrapperName}.data[index]) { + if ({stringArrayCallsWrapperName}.data[index] === undefined) { {selfDefendingCode} value = {stringArrayCallsWrapperName}.base64DecodeUnicode(value); diff --git a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts index 56287a93..8d349f0e 100644 --- a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts +++ b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts @@ -20,7 +20,7 @@ describe('StringArrayCallsWrapper', () => { assert.match( obfuscationResult.getObfuscatedCode(), - /var *_0x([a-z0-9]){4,6} *= *parseInt\(_0x([a-z0-9]){4,6}, *0x10\);/ + /_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4,6} *- *0x0\;/ ); }); });