New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do/while loop detection is faulty #26

AdamMil opened this Issue Feb 4, 2019 · 0 comments


None yet
1 participant
Copy link

AdamMil commented Feb 4, 2019

If a while loop contains a continue statement, NutCracker may misinterpret the loop as a do/while loop. For example, take this code:

local i,x
  if(x) continue;

If you compile and decompile it, you get this:

	local i;
	local x;
	// [002]  OP_JZ             4      4    0    0
while (x);

The problem is that PreprocessDoWhileInfo sees the backwards jump from the conditional continue statement and thinks that's the end of a do/while loop and it gets decompiled that way even though later instructions wouldn't make sense if it was a do/while loop.

The right fix is probably to rewrite NutCracker to do a proper basic block analysis rather than just looking for patterns in the instruction stream, but a hacky fix could be to abort do/while loop decompilation and retry as a non-do/while loop if NutCracker gets into a situation it doesn't understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment