Fix a pile of decompiler output bugs + add a cross-platform CLI - #28
Open
Jeremiah-Jahnke wants to merge 7 commits into
Open
Fix a pile of decompiler output bugs + add a cross-platform CLI#28Jeremiah-Jahnke wants to merge 7 commits into
Jeremiah-Jahnke wants to merge 7 commits into
Conversation
so any call like print("hi", ...) or return fmt(...) got decompiled as var1()
with no args, cause the B==0 branch looped `for(i=A; i<B)` which never runs when
B is 0. B==0 actually means "args go from A+1 up to the top of the stack", so now
we walk back to the VARARG/CALL that set the top and count from there.
also pulled the arg building into a lil WriteArgs() helper so CALL and TAILCALL
share it instead of copy pasting the same broken loop twice.
local a, b = ... was decompiling as "local var1var2 = ..." (no comma) and
print("hi", ...) gave "local = ..." with an empty name.
the B==0 loop was `for(i=A; i<A+B-1)` which is `i<A-1` when B is 0, so it never
ran, and the comma check used B-2 instead of A+B-2 so the separators never fired
either. rewrote it to just count targets: B>=1 gives B-1 names, B==0 is a variable
amount so we show one var = ... and move on.
stuff like local x = a + b came out as local x = local a + local b whenever a/b were declared somewhere that doesnt register them as 'used' (varargs, call results, etc). WriteConstant was calling WriteIndex without telling it these are reads, so WriteIndex slapped a 'local' on the first time it saw em. WriteIndex already takes a useLocalKeyword flag, so just pass false from WriteConstant since arithmetic operands are always reads.
closures got their name from the child function's ScriptFunction, but the child didnt exist yet when we built the parent lines (parents get created first, kids after), so UpdateClosures ran too early and everything came out as IDK_SHIT_WENT_MISSING_BRO. also fixed WriteF only naming direct children (grandchildren came out blank) by just recursing WriteF on the child instead of creating it + looping its kids separately.
GETUPVAL came out as "unk0" and SETUPVAL had its operands backwards + treated the value as a constant. turns out luac stashes the upvalue names in the debug info and the decoder already reads em into DebugUpvalues, we just never used it lol.
- CALL/TAILCALL args, vararg names, local-in-expressions, closure names, upvalue names - adds cli/ (luadec file.luac) since the demos are all windows-path hardcoded - .gitignore now ignores bin/obj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Been digging through the decompiler and fixed a bunch of bugs that were making it spit out invalid Lua. Each fix is its own commit for readability.
Bugs fixed
...or another call (e.g.print("hi", ...),f(g())) dropped all their args and came out asfoo(). TheB == 0("args run to the top of the stack") branch loopedfor (i = A; i < B; ...), which never runs whenBis 0. Now it walks back to the VARARG/CALL that set the top and counts from there -print("hi", ...)goes fromvar1()tovar1(var2, var3).local a, b = ...decompiled aslocal var1var2 = ...(missing comma) and the...in a call came out with a blank name.localleaking into expressions -local x = a + bcame out aslocal x = local a + local b.IDK_SHIT_WENT_MISSING_BRObecause the child function didn't exist yet when the parent's line was built. Now resolved after every function is created, and nested functions get named too."unk0"and had their operands backwards; they now use the real names from the debug info.