darknesswind / NutCracker

fork from DamianXVI's squirrel decompiler
22 stars 11 forks source link

do/while loop includes an instruction before the loop #25

Open AdamMil opened 5 years ago

AdamMil commented 5 years ago

Compile this code:

i = 1
do j = 0 while (j)

Then decompile it with NutCracker. The result is:

do
{
        this.i = 1;
        this.j = 0;
}
while (this.j);

In general, one operation before a do/while loop is included in the loop. I believe the reason is that the beginning of the loop is calculated incorrectly. In PreprocessDoWhileInfo there's this line:

int beginPos = endPos + curInst.arg1;

I think it should be replaced with:

int beginPos = endPos + 1 + curInst.arg1;
pabloko commented 5 years ago

a real mvp shares this fix! thanks @AdamMil