mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed cases when dead code is added to the inner code of eval expressions (#1062)
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1053
This commit is contained in:
+29
@@ -1090,5 +1090,34 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
assert.equal(matchesLength, expectedMatchesLength);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #13 - correct integration with `EvalCallExpressionTransformer`', () => {
|
||||
const evalWithDeadCodeRegExp: RegExp = new RegExp(
|
||||
`eval\\(\'if *\\(${variableMatch}`,
|
||||
'g'
|
||||
);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/eval-call-expression-transformer-integration.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
console.log(obfuscatedCode);
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t add dead code to the eval call expression', () => {
|
||||
assert.notMatch(obfuscatedCode, evalWithDeadCodeRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
(function(){
|
||||
if (true) {
|
||||
var foo = function () {
|
||||
return true;
|
||||
};
|
||||
var bar = function () {
|
||||
return true;
|
||||
};
|
||||
var baz = function () {
|
||||
return true;
|
||||
};
|
||||
var bark = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
if (true) {
|
||||
eval('const eval = 1');
|
||||
}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
bark();
|
||||
}
|
||||
})();
|
||||
@@ -50,6 +50,24 @@ describe('NodeMetadata', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isEvalHostNode', () => {
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let node: ESTree.FunctionExpression,
|
||||
value: boolean | undefined;
|
||||
|
||||
before(() => {
|
||||
node = NodeFactory.functionExpressionNode([], NodeFactory.blockStatementNode([]));
|
||||
node.metadata = {};
|
||||
node.metadata.evalHostNode = true;
|
||||
value = NodeMetadata.isEvalHostNode(node);
|
||||
});
|
||||
|
||||
it('should return metadata value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isForceTransformNode', () => {
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user