Procházet zdrojové kódy

Merge pull request #825 from javascript-obfuscator/string-array-wrappers-prefix

Fixed missing prefix of root identifiers added by `stringArrayWrapper…
Timofey Kachalov před 4 roky
rodič
revize
9c98de7cde

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 Change Log
 
+v2.9.4
+---
+* Fixed missing prefix of root identifiers added by `stringArrayWrappersCount` option when `identifiersPrefix` option is set
+
 v2.9.3
 ---
 * **CLI**: Fixed wrong name of obfuscated files when input directory path is the `.` symbol. https://github.com/javascript-obfuscator/javascript-obfuscator/issues/816

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
dist/index.browser.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
dist/index.cli.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
dist/index.js


+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "2.9.3",
+  "version": "2.9.4",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -69,7 +69,7 @@
     "chai-exclude": "2.0.2",
     "coveralls": "3.1.0",
     "cross-env": "7.0.2",
-    "eslint": "7.13.0",
+    "eslint": "7.14.0",
     "eslint-plugin-import": "2.22.1",
     "eslint-plugin-jsdoc": "30.7.8",
     "eslint-plugin-no-null": "1.0.2",

+ 4 - 1
src/node-transformers/string-array-transformers/StringArrayTransformer.ts

@@ -331,7 +331,10 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
             return stringArrayScopeCallsWrapperNamesDataByEncoding;
         }
 
-        const nextScopeCallsWrapperName: string = this.identifierNamesGenerator.generateNext();
+        // have to use `generateForGlobalScope` for program node for correct attach prefix to the calls wrapper name
+        const nextScopeCallsWrapperName: string = NodeGuards.isProgramNode(currentLexicalScopeBodyNode)
+            ? this.identifierNamesGenerator.generateForGlobalScope()
+            : this.identifierNamesGenerator.generateNext();
 
         stringArrayScopeCallsWrapperNamesDataByEncoding[encoding] = {
             encoding,

+ 66 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-scope-calls-wrapper-transformer/StringArrayScopeCallsWrapperTransformer.spec.ts

@@ -112,6 +112,38 @@ describe('StringArrayScopeCallsWrapperTransformer', function () {
                     assert.match(obfuscatedCode, stringArrayCallRegExp);
                 });
             });
+
+            describe('Variant #4: `identifiersPrefix` option is set', () => {
+                const stringArrayCallRegExp: RegExp = new RegExp(
+                    'const foo_d *= *foo_b;' +
+                    'const foo_e *= *foo_b;' +
+                    'const foo *= *foo_[d|e]\\(0x0\\);' +
+                    'const bar *= *foo_[d|e]\\(0x1\\);' +
+                    'const baz *= *foo_[d|e]\\(0x2\\);'
+                );
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                            identifiersPrefix: 'foo_',
+                            stringArray: true,
+                            stringArrayThreshold: 1,
+                            stringArrayWrappersCount: 2
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should add scope calls wrappers', () => {
+                    assert.match(obfuscatedCode, stringArrayCallRegExp);
+                });
+            });
         });
 
         describe('Variant #2: function scope', () => {
@@ -244,6 +276,40 @@ describe('StringArrayScopeCallsWrapperTransformer', function () {
                     assert.match(obfuscatedCode, stringArrayCallRegExp);
                 });
             });
+
+            describe('Variant #5: `identifiersPrefix` option is set', () => {
+                const stringArrayCallRegExp: RegExp = new RegExp(
+                    'function test *\\( *\\) *{' +
+                        'const f *= *foo_b;' +
+                        'const g *= *foo_b;' +
+                        'const a *= *[f|g]\\(0x3\\);' +
+                        'const b *= *[f|g]\\(0x4\\);' +
+                        'const c *= *[f|g]\\(0x5\\);' +
+                    '}'
+                );
+
+                let obfuscatedCode: string;
+
+                before(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/wrappers-count-const.js');
+
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            ...NO_ADDITIONAL_NODES_PRESET,
+                            identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                            identifiersPrefix: 'foo_',
+                            stringArray: true,
+                            stringArrayThreshold: 1,
+                            stringArrayWrappersCount: 2
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should add scope calls wrappers', () => {
+                    assert.match(obfuscatedCode, stringArrayCallRegExp);
+                });
+            });
         });
 
         describe('Variant #3: prohibited scopes', () => {

+ 4 - 4
yarn.lock

@@ -1910,10 +1910,10 @@ eslint-visitor-keys@^2.0.0:
   resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
   integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==
 
[email protected]3.0:
-  version "7.13.0"
-  resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.13.0.tgz#7f180126c0dcdef327bfb54b211d7802decc08da"
-  integrity sha512-uCORMuOO8tUzJmsdRtrvcGq5qposf7Rw0LwkTJkoDbOycVQtQjmnhZSuLQnozLE4TmAzlMVV45eCHmQ1OpDKUQ==
[email protected]4.0:
+  version "7.14.0"
+  resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.14.0.tgz#2d2cac1d28174c510a97b377f122a5507958e344"
+  integrity sha512-5YubdnPXrlrYAFCKybPuHIAH++PINe1pmKNc5wQRB9HSbqIK1ywAnntE3Wwua4giKu0bjligf1gLF6qxMGOYRA==
   dependencies:
     "@babel/code-frame" "^7.0.0"
     "@eslint/eslintrc" "^0.2.1"

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů