소스 검색

Added runtime StringArrayRotateFunctionTransformer tests

sanex 4 년 전
부모
커밋
81ff464320

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/index.cli.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -82,7 +82,7 @@
     "rimraf": "3.0.2",
     "sinon": "9.2.2",
     "threads": "1.6.3",
-    "ts-loader": "8.0.12",
+    "ts-loader": "8.0.13",
     "ts-node": "9.1.1",
     "typescript": "4.1.3",
     "webpack": "5.11.1",

+ 76 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/StringArrayRotateFunctionTransformer.spec.ts

@@ -4,6 +4,11 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/N
 
 import { readFileAsString } from '../../../../helpers/readFileAsString';
 
+import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
+import { StringArrayEncoding } from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
+import { StringArrayIndexesType } from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayIndexesType';
+import { StringArrayWrappersType } from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayWrappersType';
+
 import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
 
 describe('StringArrayRotateFunctionTransformer', () => {
@@ -119,5 +124,76 @@ describe('StringArrayRotateFunctionTransformer', () => {
                 assert.notMatch(obfuscatedCode, regExp);
             });
         });
+
+        describe('Code evaluation', function () {
+            this.timeout(100000);
+
+            const samplesCount: number = 100;
+
+            let hasRuntimeErrors: boolean = false;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/code-evaluation.js');
+
+                const obfuscateFunc = () => {
+                    return JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            controlFlowFlattening: true,
+                            controlFlowFlatteningThreshold: 1,
+                            deadCodeInjection: true,
+                            deadCodeInjectionThreshold: 1,
+                            debugProtection: true,
+                            disableConsoleOutput: true,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator,
+                            numbersToExpressions: true,
+                            simplify: true,
+                            renameProperties: true,
+                            rotateStringArray: true,
+                            selfDefending: true,
+                            splitStrings: true,
+                            splitStringsChunkLength: 3,
+                            stringArray: true,
+                            stringArrayEncoding: [
+                                StringArrayEncoding.None,
+                                StringArrayEncoding.Base64,
+                                StringArrayEncoding.Rc4
+                            ],
+                            stringArrayIndexesType: [
+                                StringArrayIndexesType.HexadecimalNumber,
+                                StringArrayIndexesType.HexadecimalNumericString
+                            ],
+                            stringArrayIndexShift: true,
+                            stringArrayWrappersChainedCalls: true,
+                            stringArrayWrappersCount: 5,
+                            stringArrayWrappersParametersMaxCount: 5,
+                            stringArrayWrappersType: StringArrayWrappersType.Function,
+                            stringArrayThreshold: 1,
+                            transformObjectKeys: true,
+                            unicodeEscapeSequence: true
+                        }
+                    ).getObfuscatedCode();
+                };
+
+
+                for (let i = 0; i < samplesCount; i++) {
+                    try {
+                        const evaluationResult = eval(obfuscateFunc());
+
+                        if (evaluationResult !== 'fooooooo') {
+                            hasRuntimeErrors = true;
+                            break;
+                        }
+                    } catch {
+                        hasRuntimeErrors = true;
+                        break;
+                    }
+                }
+            });
+
+            it('It should correctly evaluate obfuscated code', () => {
+                assert.equal(hasRuntimeErrors, false);
+            });
+        });
     });
 });

+ 32 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-rotate-function-transformer/fixtures/code-evaluation.js

@@ -0,0 +1,32 @@
+const foo = 'foo';
+const bar = 'bar';
+const baz = 'baz';
+const bark = 'bark';
+const hawk = 'hawk';
+
+function test() {
+    var foo = 'foo';
+
+    if (true) {
+        foo += 'o';
+    }
+
+    if (true) {
+        foo += 'o';
+    }
+
+    if (true) {
+        foo += 'o';
+    }
+
+    if (true) {
+        foo += 'o';
+    }
+
+    if (true) {
+        foo += 'o';
+    }
+
+    return foo;
+}
+test();

+ 4 - 4
yarn.lock

@@ -4057,10 +4057,10 @@ to-regex-range@^5.0.1:
   dependencies:
     is-number "^7.0.0"
 
[email protected]2:
-  version "8.0.12"
-  resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-8.0.12.tgz#1de9f1de65176318c1e6d187bfc496182f8dc2a0"
-  integrity sha512-UIivVfGVJDdwwjgSrbtcL9Nf10c1BWnL1mxAQUVcnhNIn/P9W3nP5v60Z0aBMtc7ZrE11lMmU6+5jSgAXmGaYw==
[email protected]3:
+  version "8.0.13"
+  resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-8.0.13.tgz#2bebeb833570ca46bb9338322a9a29900e988535"
+  integrity sha512-1o1nO6aqouA23d2nlcMSEyPMAWRhnYUU0EQUJSc60E0TUyBNX792RHFYUN1ZM29vhMUNayrsbj2UVdZwKhXCDA==
   dependencies:
     chalk "^2.3.0"
     enhanced-resolve "^4.0.0"

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.