mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed stringArrayCallsWrapper option with mangled names generator
This commit is contained in:
+19
-11
@@ -1,28 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
|
||||
import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
|
||||
|
||||
(function () {
|
||||
const JavaScriptObfuscator: any = require('../../index');
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
const foo = 'foo';
|
||||
const bar = 'bar';
|
||||
|
||||
function test () {
|
||||
const baz = 'baz';
|
||||
const bark = 'bark';
|
||||
|
||||
function test1() {
|
||||
const hawk = 'hawk';
|
||||
const eagle = 'eagle';
|
||||
}
|
||||
const foo = 'aaa';
|
||||
|
||||
function test (a, b) {
|
||||
const bar = 'bbb';
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function test1 (a, b) {
|
||||
const bar = 'bbb';
|
||||
|
||||
return a + b;
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
var baz = 5;
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
compact: false,
|
||||
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
|
||||
renameGlobals: true,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
stringArrayWrappersChainedCalls: true,
|
||||
|
||||
+45
-2
@@ -256,13 +256,56 @@ describe('StringArrayTransformer', function () {
|
||||
});
|
||||
|
||||
describe('Variant #5: `stringArrayWrappersChainedCalls` option is enabled', () => {
|
||||
describe('Variant #1: correct evaluation of the string array wrappers chained calls', () => {
|
||||
describe('Variant #1: correct chained calls', () => {
|
||||
describe('Variant #1: base', () => {
|
||||
const stringArrayCallRegExp: RegExp = new RegExp(
|
||||
'const h *= *b;' +
|
||||
'const foo *= *h\\(\'0x0\'\\);' +
|
||||
'function test\\( *\\) *{' +
|
||||
'const i *= *h;' +
|
||||
'const c *= *i\\(\'0x1\'\\);' +
|
||||
'const d *= *i\\(\'0x2\'\\);' +
|
||||
'function e\\( *\\) *{' +
|
||||
'const j *= *i;' +
|
||||
'const f *= *j\\(\'0x3\'\\);' +
|
||||
'const g *= *j\\(\'0x4\'\\);' +
|
||||
'return f *\\+ *g;' +
|
||||
'}' +
|
||||
'return c *\\+ *d *\\+ *e\\(\\);' +
|
||||
'}'
|
||||
);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/string-array-wrappers-chained-calls.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
stringArrayWrappersChainedCalls: true,
|
||||
stringArrayWrappersCount: 1
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should add correct scope calls wrappers', () => {
|
||||
assert.match(obfuscatedCode, stringArrayCallRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: correct evaluation of the string array wrappers chained calls', () => {
|
||||
const samplesCount: number = 50;
|
||||
const expectedEvaluationResult: string = 'aaabbbcccdddeee';
|
||||
let isEvaluationSuccessful: boolean = true;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/string-array-wrappers-chained-calls-eval.js');
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/string-array-wrappers-chained-calls.js');
|
||||
|
||||
for (let i = 0; i < samplesCount; i++) {
|
||||
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
|
||||
Reference in New Issue
Block a user