darknesswind / NutCracker

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

Crash when generating DoWhileStatement #15

Closed Psimage closed 7 years ago

Psimage commented 7 years ago

In some cases void NutFunction::DecompileDoWhileLoop( VMState& state, int endPos) const endPos > state.IP() which causes ExpressionPtr condition; to be null and crash later when printing DoWhileStatement.

Tested on: script.zip

Psimage commented 7 years ago

Can this be due to OP_LINE between OP_JZ/OP_JCMP and OP_JMP?

darknesswind commented 7 years ago

It seens that there are three do-while statement in one function, they jump back to thie same pos, but the current code only consider the outer loop. PS: As you canot split the word 'while' in two lines, it's impossible that OP_LINE appear between OP_JZ/OP_JCMP and OP_JMP.

darknesswind commented 7 years ago

there is a 'break' operation in the inner loop using OP_JCMP, it cause the crash

Psimage commented 7 years ago

Yeah. Broke it with this image

darknesswind commented 7 years ago

Can this be due to OP_LINE between OP_JZ/OP_JCMP and OP_JMP?

emmmm... , maybe this will happen in some case?

darknesswind commented 7 years ago

I think the pattern of this function will looks like while (++i < 20) { if (...) continue; if (...) continue; if (...) continue; if (...) continue; }