|
@@ -5,6 +5,7 @@ import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/id
|
|
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
|
|
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
|
|
|
|
|
|
import { readFileAsString } from '../../../../helpers/readFileAsString';
|
|
import { readFileAsString } from '../../../../helpers/readFileAsString';
|
|
|
|
+import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
|
|
|
|
|
|
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
|
|
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
|
|
|
|
|
|
@@ -76,5 +77,90 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ describe('Variant #2: should not generate same prefixed name for identifier in code as prefixed name of string array', function () {
|
|
|
|
+ this.timeout(10000);
|
|
|
|
+
|
|
|
|
+ const samplesCount: number = 20;
|
|
|
|
+
|
|
|
|
+ describe('Variant #1: `renameGlobals` option is disabled', () => {
|
|
|
|
+ const stringArrayStorageRegExp: RegExp = /const ([abAB]{1,3}) *= *\['first', *'abc'];/;
|
|
|
|
+ const variableDeclarationIdentifierNameRegExp: RegExp = /const ([abAB]{1,3}){1,2} *= *[abAB]{1,3}\('0x0'\);/;
|
|
|
|
+
|
|
|
|
+ let isIdentifiersAreConflicted: boolean = false;
|
|
|
|
+
|
|
|
|
+ before(() => {
|
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js');
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < samplesCount; i++) {
|
|
|
|
+ const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
|
|
|
+ code,
|
|
|
|
+ {
|
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
|
+ identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
|
|
|
|
+ identifiersDictionary: ['a', 'b', 'aa'],
|
|
|
|
+ identifiersPrefix: 'a',
|
|
|
|
+ transformObjectKeys: true,
|
|
|
|
+ stringArray: true,
|
|
|
|
+ stringArrayThreshold: 1
|
|
|
|
+ }
|
|
|
|
+ ).getObfuscatedCode();
|
|
|
|
+
|
|
|
|
+ const stringArrayStorageName: string = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp);
|
|
|
|
+ const variableDeclarationIdentifierName: string = getRegExpMatch(obfuscatedCode, variableDeclarationIdentifierNameRegExp);
|
|
|
|
+
|
|
|
|
+ if (stringArrayStorageName === variableDeclarationIdentifierName) {
|
|
|
|
+ isIdentifiersAreConflicted = true;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('Should not generate same name for string array and last variable', () => {
|
|
|
|
+ assert.equal(isIdentifiersAreConflicted, false);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ describe('Variant #2: `renameGlobals` option is enabled', () => {
|
|
|
|
+ const stringArrayStorageRegExp: RegExp = /const ([abAB]{1,3}) *= *\['first', *'abc'];/;
|
|
|
|
+ const variableDeclarationIdentifierNameRegExp: RegExp = /const ([abAB]{1,3}){1,2} *= *[abAB]{1,3}\('0x0'\);/;
|
|
|
|
+
|
|
|
|
+ let isIdentifiersAreConflicted: boolean = false;
|
|
|
|
+
|
|
|
|
+ before(() => {
|
|
|
|
+ const code: string = readFileAsString(__dirname + '/fixtures/string-array-storage-name-conflict-2.js');
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < samplesCount; i++) {
|
|
|
|
+ const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
|
|
|
+ code,
|
|
|
|
+ {
|
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
|
+ identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
|
|
|
|
+ identifiersDictionary: ['a', 'b', 'aa'],
|
|
|
|
+ identifiersPrefix: 'a',
|
|
|
|
+ renameGlobals: true,
|
|
|
|
+ transformObjectKeys: true,
|
|
|
|
+ stringArray: true,
|
|
|
|
+ stringArrayThreshold: 1
|
|
|
|
+ }
|
|
|
|
+ ).getObfuscatedCode();
|
|
|
|
+
|
|
|
|
+ const stringArrayStorageName: string = getRegExpMatch(obfuscatedCode, stringArrayStorageRegExp);
|
|
|
|
+ const variableDeclarationIdentifierName: string = getRegExpMatch(obfuscatedCode, variableDeclarationIdentifierNameRegExp);
|
|
|
|
+
|
|
|
|
+ if (stringArrayStorageName === variableDeclarationIdentifierName) {
|
|
|
|
+ isIdentifiersAreConflicted = true;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('Should not generate same name for string array and last variable', () => {
|
|
|
|
+ assert.equal(isIdentifiersAreConflicted, false);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
});
|
|
});
|
|
});
|
|
});
|