mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Dead code injection unwrap stage now runs before string array transformers
This commit is contained in:
+32
-12
@@ -5,22 +5,42 @@
|
||||
|
||||
let obfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
function foo() {
|
||||
global.baz = 3;
|
||||
}
|
||||
(function(){
|
||||
if (true) {
|
||||
var foo = function () {
|
||||
console.log('abc');
|
||||
};
|
||||
var bar = function () {
|
||||
console.log('def');
|
||||
};
|
||||
var baz = function () {
|
||||
console.log('ghi');
|
||||
};
|
||||
var bark = function () {
|
||||
console.log('jkl');
|
||||
};
|
||||
var hawk = function () {
|
||||
console.log('mno');
|
||||
};
|
||||
|
||||
function bar(...args) {
|
||||
console.log(2);
|
||||
}
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
bark();
|
||||
hawk();
|
||||
}
|
||||
})();
|
||||
`,
|
||||
{
|
||||
compact: false,
|
||||
identifierNamesCache: {
|
||||
globalIdentifiers: {},
|
||||
propertyIdentifiers: {}
|
||||
},
|
||||
renameGlobals: true,
|
||||
renameProperties: true
|
||||
simplify: false,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
stringArrayWrappersChainedCalls: true,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1,
|
||||
identifierNamesGenerator: 'mangled',
|
||||
seed: 1
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
+41
@@ -998,5 +998,46 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #12 - correct integration with `stringArrayWrappersChainedCalls` option', () => {
|
||||
const regExp: RegExp = new RegExp(
|
||||
`var ${variableMatch} *= *${variableMatch}; *` +
|
||||
`if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{`+
|
||||
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
|
||||
`\\} *else *\\{`+
|
||||
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
|
||||
`\\}`,
|
||||
'g'
|
||||
);
|
||||
const expectedMatchesLength: number = 5;
|
||||
|
||||
let matchesLength: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input-1.js');
|
||||
|
||||
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
stringArrayWrappersCount: 1,
|
||||
stringArrayWrappersChainedCalls: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
const matches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(regExp);
|
||||
|
||||
if (matches) {
|
||||
matchesLength = matches.length;
|
||||
}
|
||||
});
|
||||
|
||||
it('should unwrap dead code injection root AST host node before the string array transformer', () => {
|
||||
assert.equal(matchesLength, expectedMatchesLength);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user