Fixed stringArrayWrappersCount behaviour with arrow function scope without statements

This commit is contained in:
sanex
2020-09-12 13:59:07 +03:00
parent 78383e7cb3
commit 09e89f8fe6
13 changed files with 121 additions and 57 deletions
+4 -29
View File
@@ -8,42 +8,17 @@ import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
const foo = 'aaa';
function test (a, b) {
const bar = 'bbb';
function test1 (a, b) {
const baz = 'ccc';
function test2 (a, b) {
const bark = 'ddd';
return bark;
}
return baz + test2();
}
return bar + test1();
}
function test3 (a, b) {
const hawk = 'eee';
return hawk;
}
foo + test() + test3();
[].map(v => 'vvv');
`,
{
...NO_ADDITIONAL_NODES_PRESET,
compact: false,
identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
renameGlobals: true,
stringArray: true,
transformObjectKeys: true,
stringArrayThreshold: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersChainedCalls: false,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
@@ -198,7 +198,67 @@ describe('StringArrayTransformer', function () {
});
});
describe('Variant #3: prevailing kind of variables', () => {
describe('Variant #3: prohibited scopes', () => {
describe('Variant #1: if statement scope', () => {
const stringArrayCallRegExp: RegExp = new RegExp(
'var c *= *b;' +
'if *\\(!!\\[]\\) *{' +
'var foo *= *c\\(\'0x0\'\\);' +
'}'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/string-array-wrappers-count-prohibited-scope-1.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should not add scope calls wrappers to a prohibited scope', () => {
assert.match(obfuscatedCode, stringArrayCallRegExp);
});
});
describe('Variant #2: arrow function scope without statements', () => {
const stringArrayCallRegExp: RegExp = new RegExp(
'var c *= *b;' +
'\\[]\\[c\\(\'0x0\'\\)]\\(\\(\\) *=> *c\\(\'0x1\'\\)\\);'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/string-array-wrappers-count-prohibited-scope-2.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1
}
).getObfuscatedCode();
});
it('should not add scope calls wrappers to a prohibited scope', () => {
assert.match(obfuscatedCode, stringArrayCallRegExp);
});
});
});
describe('Variant #4: prevailing kind of variables', () => {
const stringArrayCallRegExp: RegExp = new RegExp(
'return _0x([a-f0-9]){4,6};' +
'};' +
@@ -230,7 +290,7 @@ describe('StringArrayTransformer', function () {
});
});
describe('Variant #4: correct evaluation of the scope calls wrappers', () => {
describe('Variant #5: correct evaluation of the scope calls wrappers', () => {
const expectedEvaluationResult: string = 'aaabbbcccdddeee';
let evaluationResult: string;
@@ -255,7 +315,7 @@ describe('StringArrayTransformer', function () {
});
});
describe('Variant #5: `stringArrayWrappersChainedCalls` option is enabled', () => {
describe('Variant #6: `stringArrayWrappersChainedCalls` option is enabled', () => {
describe('Variant #1: correct chained calls', () => {
describe('Variant #1: `Mangled` identifier names generator', () => {
const stringArrayCallRegExp: RegExp = new RegExp(
@@ -39,6 +39,7 @@ describe('JavaScriptObfuscator runtime eval', function () {
StringArrayEncoding.Base64,
StringArrayEncoding.Rc4
],
stringArrayWrappersChainedCalls: true,
stringArrayWrappersCount: 5,
stringArrayThreshold: 1,
transformObjectKeys: true,
@@ -71,9 +72,6 @@ describe('JavaScriptObfuscator runtime eval', function () {
{
identifierNamesGenerator: IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator,
renameGlobals: true
},
{
stringArrayWrappersChainedCalls: true
}
];