浏览代码

Additional tests

sanex3339 5 年之前
父节点
当前提交
65d4fd1602
共有 18 个文件被更改,包括 250 次插入19 次删除
  1. 46 0
      test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts
  2. 5 0
      test/functional-tests/javascript-obfuscator/fixtures/prevailing-kind-of-variables-let.js
  3. 43 4
      test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts
  4. 9 0
      test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js
  5. 27 4
      test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts
  6. 0 0
      test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-const.js
  7. 3 0
      test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-let.js
  8. 0 0
      test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-var.js
  9. 32 5
      test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/ObjectExpressionKeysTransformer.spec.ts
  10. 0 0
      test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-const.js
  11. 6 0
      test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-let.js
  12. 0 0
      test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-var.js
  13. 25 2
      test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec.ts
  14. 1 0
      test/functional-tests/templates/string-array-nodes/string-array-calls-wrapper-node-template/fixtures/prevailing-kind-of-variables-let.js
  15. 26 2
      test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec.ts
  16. 1 0
      test/functional-tests/templates/string-array-nodes/string-array-rotate-function-template/fixtures/prevailing-kind-of-variables-let.js
  17. 25 2
      test/functional-tests/templates/string-array-nodes/string-array-template/StringArrayTemplate.spec.ts
  18. 1 0
      test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js

+ 46 - 0
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));
+                    });
+                });
+            });
         });
     });
 });

+ 5 - 0
test/functional-tests/javascript-obfuscator/fixtures/prevailing-kind-of-variables-let.js

@@ -0,0 +1,5 @@
+function test() {
+    let foo = 'foo';
+    return foo;
+}
+test();

+ 43 - 4
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);
                     });
                 });

+ 9 - 0
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);
+})();

+ 27 - 4
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);
                 });
             });

+ 0 - 0
test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-2.js → test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-const.js


+ 3 - 0
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;
+})();

+ 0 - 0
test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-1.js → test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/prevailing-kind-of-variables-var.js


+ 32 - 5
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);
             });
         });

+ 0 - 0
test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-2.js → test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-const.js


+ 6 - 0
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'
+    };
+})();

+ 0 - 0
test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-1.js → test/functional-tests/node-transformers/converting-transformers/object-expression-keys-transformer/fixtures/prevailing-kind-of-variables-var.js


+ 25 - 2
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);
             });
         });

+ 1 - 0
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';

+ 26 - 2
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);
             });
         });

+ 1 - 0
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';

+ 25 - 2
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);
             });
         });

+ 1 - 0
test/functional-tests/templates/string-array-nodes/string-array-template/fixtures/prevailing-kind-of-variables-let.js

@@ -0,0 +1 @@
+let foo = 'foo';