Skip to content
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

Incorrect and-or construct decompilation #16

Open
toxamin opened this issue Oct 13, 2023 · 3 comments
Open

Incorrect and-or construct decompilation #16

toxamin opened this issue Oct 13, 2023 · 3 comments
Labels
good first issue Good for newcomers wontfix This will not be worked on

Comments

@toxamin
Copy link
Contributor

toxamin commented Oct 13, 2023

When given the following script:

local fenv = getfenv and getfenv() or _ENV
print(fenv._VERSION)

Metaworm's luadec fails to identify the and-or construct, and instead produces this code:

local r0_0 = getfenv
if r0_0 then
  r0_0 = bozo or _ENV
else
  goto label_6	-- block#2 is visited secondly
end
print(r0_0._VERSION)
@metaworm
Copy link
Owner

You found the key problem, yes, the decompilation of and-or statements is a big problem, lua compiles the "and/or" operators as conditional jumps instead of handling them with special instructions, and in many cases the decompilation fails for statements containing "and/or", thus showing the original conditional jumps as they are, i.e., if-else, which is what I've been thinking about , how to restore and-or statements more accurately

@metaworm metaworm added wontfix This will not be worked on good first issue Good for newcomers labels Oct 13, 2023
@marsinator358
Copy link

@metaworm I've had the same problem when writing my decompiler and I've managed to find a perfect solution.
Go check out this paper, specifically the part where they build a control flow graph and then search for "boolean atoms".
It is meant for java but with a few adjustments it also works for lua/luajit bytecode.

@metaworm
Copy link
Owner

metaworm commented Nov 4, 2023

@marsinator358 Thank you for your advice. The handling of this part is really a little complicated. I will try to improve it when I have a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants