Fixed conflicts between generated names and names from untouched identifiers from source code.

Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/550
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/549
This commit is contained in:
sanex3339
2020-02-08 21:57:29 +03:00
parent 43b8fc9d7c
commit db908f7bce
25 changed files with 371 additions and 77 deletions
@@ -618,7 +618,8 @@ describe('JavaScriptObfuscator', () => {
});
describe('dictionary identifier names generator', () => {
const regExp: RegExp = /var [abc] *= *0x1; *var [ABC] *= *0x2; *var [ABC] *= *0x3;/;
const regExp1: RegExp = /var [abc] *= *0x1; *var [abc] *= *0x2; *var [abc] *= *0x3;/;
const regExp2: RegExp = /var [ABC] *= *0x4; *var [ABC] *= *0x5; *var [ABC] *= *0x6;/;
let obfuscatedCode: string;
@@ -635,8 +636,12 @@ describe('JavaScriptObfuscator', () => {
).getObfuscatedCode();
});
it('should generate identifier based on the dictionary', () => {
assert.match(obfuscatedCode, regExp);
it('Match #1: should generate identifier based on the dictionary', () => {
assert.match(obfuscatedCode, regExp1);
});
it('Match #2: should generate identifier based on the dictionary', () => {
assert.match(obfuscatedCode, regExp2);
});
});
@@ -726,16 +731,20 @@ describe('JavaScriptObfuscator', () => {
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/custom-nodes-identifier-names-collision.js');
obfuscateFunc = (identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>) => JavaScriptObfuscator.obfuscate(
code,
{
identifierNamesGenerator,
compact: false,
renameGlobals: true,
identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'foozmos', 'cow', 'chikago'],
stringArray: true
}
).getObfuscatedCode();
obfuscateFunc = (identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>) => {
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
identifierNamesGenerator,
compact: false,
renameGlobals: true,
identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'foozmos', 'cow', 'chikago'],
stringArray: true
}
).getObfuscatedCode();
return obfuscatedCode;
};
[