PerimeterX / restringer

A Javascript Deobfuscator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

resolveRedundantLogicalExpressions removes nodes with assignments

jorants opened this issue · comments

Consider the following minimal example:

var x = 2;
if((x = 3) && 0){
    console.log("Not here")
}
console.log(x)

resolveRedundantLogicalExpressions will test the right hand of the && and conclude that the left hand is redundant as the right hand is always zero.
The result is:

var x = 2;
console.log(2);

However, the assignment should still be ran.
In general, even if the right hand evaluates to False, the left might have effect.
For example:

function f(){
    console.log("Doing important stuff")
}
var x = 2;
if(f() && 0){
    console.log("Not here")
}
console.log(x)

A good solution would be to, when a constant right hand is found, add the left hand side as a statement just above the if. If it does not have any effect than other modules can optimize it away.
So:

function f(){
    console.log("Doing important stuff")
}
var x = 2;
f(x)
if(false){
    console.log("Not here")
}
console.log(x)

in the last example.

PS: as you might notice, I am struggling with some rather evil obfuscation. Sorry for the flood of issues.

@jorants I really appreciate all the attention you're giving the project 🙏
This is definitely a bug, and the module should verify there are no assignments in the logical expression it looks to resolve.