mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed stringArrayWrappersCount behaviour with arrow function scope without statements
This commit is contained in:
+4
-29
@@ -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();
|
||||
|
||||
+63
-3
@@ -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(
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
if (true) {
|
||||
var foo = 'foo';
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
[].map(() => 'test');
|
||||
@@ -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
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user