diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index 4665bbd9..8ac254a6 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -797,6 +797,52 @@ describe('JavaScriptObfuscator', () => { }); }); }); + + describe('`let` kind', function () { + describe('Variant #1: StringArrayEncoding: rc4', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: StringArrayEncoding.Rc4 + } + ).getObfuscatedCode(); + + }); + + it('does not break on run', () => { + assert.doesNotThrow(() => eval(obfuscatedCode)); + }); + }); + + describe('Variant #2: StringArrayEncoding: base64', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + ...baseParams, + stringArrayEncoding: StringArrayEncoding.Rc4 + } + ).getObfuscatedCode(); + + }); + + it('does not break on run', () => { + assert.doesNotThrow(() => eval(obfuscatedCode)); + }); + }); + }); }); }); }); diff --git a/test/functional-tests/javascript-obfuscator/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/javascript-obfuscator/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..da7d221b --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1,5 @@ +function test() { + let foo = 'foo'; + return foo; +} +test(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts index 9ba9f496..08bdb914 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts @@ -681,11 +681,11 @@ describe('BlockStatementControlFlowTransformer', function () { switchCaseMap = switchCaseMapMatch.split('|').sort(); }); - it('should create switch-case map variable', () => { + it('should use correct kind of variable for switch-case map', () => { assert.match(obfuscatedCode, switchCaseMapVariableRegExp); }); - it('should create valid switch-case map variable with order of switch cases sequence', () => { + it('should use correct kind of variable for switch cases sequence', () => { assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence); }); }); @@ -720,11 +720,50 @@ describe('BlockStatementControlFlowTransformer', function () { switchCaseMap = switchCaseMapMatch.split('|').sort(); }); - it('should create switch-case map variable', () => { + it('should use correct kind of variable for switch-case map', () => { assert.match(obfuscatedCode, switchCaseMapVariableRegExp); }); - it('should create valid switch-case map variable with order of switch cases sequence', () => { + it('should use correct kind of variable for switch cases sequence', () => { + assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence); + }); + }); + }); + + describe('`let` kind', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + } + ).getObfuscatedCode(); + }); + + describe('switch-case map', () => { + const switchCaseMapVariableRegExp: RegExp = /let *_0x(?:[a-f0-9]){4,6} *= *_0x(?:[a-f0-9]){4,6}\['.*'\]\['split'\]\('\|'\)/; + const switchCaseMapStringRegExp: RegExp = /let *_0x(?:[a-f0-9]){4,6} *= *\{'.*' *: *'(.*)'\};/; + const expectedSwitchCasesSequence: string[] = ['0', '1', '2', '3', '4']; + + let switchCaseMap: string[]; + + before(() => { + const switchCaseMapMatch: string = getRegExpMatch(obfuscatedCode, switchCaseMapStringRegExp); + + switchCaseMap = switchCaseMapMatch.split('|').sort(); + }); + + it('should use correct kind of variable for switch-case map', () => { + assert.match(obfuscatedCode, switchCaseMapVariableRegExp); + }); + + it('should use correct kind of variable for switch cases sequence', () => { assert.deepEqual(switchCaseMap, expectedSwitchCasesSequence); }); }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..14ee3f58 --- /dev/null +++ b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1,9 @@ +let test = 0; + +(function () { + console.log(1); + console.log(2); + console.log(3); + console.log(4); + console.log(5); +})(); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts index 989d3b34..3e5f6d33 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts @@ -276,7 +276,7 @@ describe('FunctionControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-1.js'); + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); obfuscatedCode = JavaScriptObfuscator.obfuscate( code, @@ -288,7 +288,7 @@ describe('FunctionControlFlowTransformer', function () { ).getObfuscatedCode(); }); - it('should add `control flow storage` node to the obfuscated code', () => { + it('should use correct kind of variables for `control flow storage`', () => { assert.match(obfuscatedCode, regexp); }); }); @@ -299,7 +299,7 @@ describe('FunctionControlFlowTransformer', function () { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-2.js'); + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); obfuscatedCode = JavaScriptObfuscator.obfuscate( code, @@ -311,7 +311,30 @@ describe('FunctionControlFlowTransformer', function () { ).getObfuscatedCode(); }); - it('should add `control flow storage` node to the obfuscated code', () => { + it('should use correct kind of variables for `control flow storage`', () => { + assert.match(obfuscatedCode, regexp); + }); + }); + + describe('Variant #3 - `let` kind', () => { + const regexp: RegExp = new RegExp(`let *${variableMatch} *= *\\{`); + + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + } + ).getObfuscatedCode(); + }); + + it('should use correct kind of variables for `control flow storage`', () => { assert.match(obfuscatedCode, regexp); }); }); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-2.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-const.js similarity index 100% rename from test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-const.js diff --git a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..fe5247fa --- /dev/null +++ b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1,3 @@ +(function () { + let variable = 1 + 2; +})(); diff --git a/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-1.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-var.js similarity index 100% rename from test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-var.js diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts index 5d5dc418..1aa6e6e3 100644 --- a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts +++ b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts @@ -1000,7 +1000,7 @@ describe('ObjectExpressionKeysTransformer', () => { let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-1.js'); + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js'); obfuscatedCode = JavaScriptObfuscator.obfuscate( code, @@ -1011,7 +1011,7 @@ describe('ObjectExpressionKeysTransformer', () => { ).getObfuscatedCode(); }); - it('should correctly transform object keys', () => { + it('should use correct kind of variables', () => { assert.match(obfuscatedCode, regExp); }); }); @@ -1021,13 +1021,13 @@ describe('ObjectExpressionKeysTransformer', () => { `const *${variableMatch} *= *{};` + `${variableMatch}\\['foo'] *= *'bar';` + `${variableMatch}\\['baz'] *= *'bark';` + - ``; + ``; const regExp: RegExp = new RegExp(match); let obfuscatedCode: string; before(() => { - const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-2.js'); + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js'); obfuscatedCode = JavaScriptObfuscator.obfuscate( code, @@ -1038,7 +1038,34 @@ describe('ObjectExpressionKeysTransformer', () => { ).getObfuscatedCode(); }); - it('should correctly transform object keys', () => { + it('should use correct kind of variables', () => { + assert.match(obfuscatedCode, regExp); + }); + }); + + describe('Variant #3: `let` kind`', () => { + const match: string = `` + + `let *${variableMatch} *= *{};` + + `${variableMatch}\\['foo'] *= *'bar';` + + `${variableMatch}\\['baz'] *= *'bark';` + + ``; + const regExp: RegExp = new RegExp(match); + + let obfuscatedCode: string; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + + obfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + transformObjectKeys: true + } + ).getObfuscatedCode(); + }); + + it('should use correct kind of variables', () => { assert.match(obfuscatedCode, regExp); }); }); diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-2.js b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-const.js similarity index 100% rename from test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-2.js rename to test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-const.js diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..79d2e283 --- /dev/null +++ b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1,6 @@ +(function(){ + let object = { + foo: 'bar', + baz: 'bark' + }; +})(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-1.js b/test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-var.js similarity index 100% rename from test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-1.js rename to test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-var.js diff --git a/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts b/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts index dd9b275f..7e088816 100644 --- a/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts +++ b/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts @@ -136,7 +136,7 @@ describe('StringArrayCallsWrapperNodeTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array calls wrapper', () => { + it('Should return correct kind of variables for string array calls wrapper', () => { assert.match(obfuscatedCode, stringArrayCallsWrapperRegExp); }); }); @@ -159,7 +159,30 @@ describe('StringArrayCallsWrapperNodeTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array calls wrapper', () => { + it('Should return correct kind of variables for string array calls wrapper', () => { + assert.match(obfuscatedCode, stringArrayCallsWrapperRegExp); + }); + }); + + describe('`let` kind', () => { + let obfuscatedCode: string, + stringArrayCallsWrapperRegExp: RegExp = /const (_0x(\w){4}) *= *function/; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + } + ); + + obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); + }); + + it('Should return correct kind of variables for string array calls wrapper', () => { assert.match(obfuscatedCode, stringArrayCallsWrapperRegExp); }); }); diff --git a/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..88bf437a --- /dev/null +++ b/test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1 @@ +let foo = 'foo'; \ No newline at end of file diff --git a/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts b/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts index 2f014d39..fe7ab558 100644 --- a/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts +++ b/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts @@ -30,7 +30,7 @@ describe('StringArrayRotateFunctionTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array rotate function', () => { + it('Should return correct kind of variables for string array rotate function', () => { assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp); }); }); @@ -54,7 +54,31 @@ describe('StringArrayRotateFunctionTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array rotate function', () => { + it('Should return correct kind of variables for string array rotate function', () => { + assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp); + }); + }); + + describe('`let` kind', () => { + let obfuscatedCode: string, + stringArrayRotateFunctionRegExp: RegExp = /function\(_0x([a-f0-9]){4,6}, *_0x([a-f0-9]){4,6}\){const _0x([a-f0-9]){4,6} *= *function/; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1, + rotateStringArray: true + } + ); + + obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); + }); + + it('Should return correct kind of variables for string array rotate function', () => { assert.match(obfuscatedCode, stringArrayRotateFunctionRegExp); }); }); diff --git a/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..88bf437a --- /dev/null +++ b/test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1 @@ +let foo = 'foo'; \ No newline at end of file diff --git a/test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts b/test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts index 76c7c7de..fa2a9b27 100644 --- a/test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts +++ b/test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts @@ -29,7 +29,7 @@ describe('StringArrayTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array', () => { + it('Should return correct kind of variables for string array', () => { assert.match(obfuscatedCode, stringArrayRegExp); }); }); @@ -52,7 +52,30 @@ describe('StringArrayTemplate', () => { obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); }); - it('Should return correct variable kind for string array', () => { + it('Should return correct kind of variables for string array', () => { + assert.match(obfuscatedCode, stringArrayRegExp); + }); + }); + + describe('`let` kind', () => { + let obfuscatedCode: string, + stringArrayRegExp: RegExp = /const (_0x(\w){4}) *= *\['.*'];/; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js'); + const obfuscatedCodeObject: IObfuscatedCode = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_ADDITIONAL_NODES_PRESET, + stringArray: true, + stringArrayThreshold: 1 + } + ); + + obfuscatedCode = obfuscatedCodeObject.getObfuscatedCode(); + }); + + it('Should return correct kind of variables for string array', () => { assert.match(obfuscatedCode, stringArrayRegExp); }); }); diff --git a/test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js b/test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js new file mode 100644 index 00000000..88bf437a --- /dev/null +++ b/test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js @@ -0,0 +1 @@ +let foo = 'foo'; \ No newline at end of file