Decompiler for Luau (https://luau-lang.org/) written by xgladius
luauDec is a decompiler for the Luau language created by Roblox, leveraging built-in Luau tooling to generate AST, and then transpile that AST into readable code.
The decompiler was designed to have a few things in mind,
No dependencies - Other than the Luau language, luauDec has 0 dependencies other than the C++ STL.
Easy to understand and use - The code is written in a way that anyone can understand it, given they understand C++ of course.
Speed - The decompiler does not invoke the Luau VM, (like some other decompilers), allowing for it to be incredibly fast.
Multi-platform - Works on all platforms.
git clone --recursive https://github.com/xgladius/luauDec.git
cd luauDec
cmake . && make
- Luau bytecode is fed into the decompiler
- The decompiler calls luau_load to produce an LClosure with a Proto member
- The decompiler iterates over each child Proto (Proto->p) which are passed to the decompiler's BlockGen class (BlockGen meaning non-main Proto)
- The BlockGen class creates a AstExprFunction for each child Proto, which is added to a vector
- Proto->code is iterated here to create Ast expressions of the relevant code
- The BlockGen class creates a AstExprFunction for each child Proto, which is added to a vector
- The decompiler passes the main Proto, along with the vector of child Proto AstExprFunction to the decompilers BlockGen class (BlockGen meaning main Proto)
- The BlockGen class creates a AstStatBlock containing all uses of code in Proto->code and child Protos
- The AstStatBlock is passed to Luau's built-in transpiler, which is turned into valid Luau code
- StatBlock AST generation
- Basic arithmetic AST generation (+, -, *, /, %, etc)
- Reading and writing from constants table AST generation (Proto->k[idx] to AST)
- Call AST generation (print())
- Arguments (print(1,2,3,4,5,6)
- Vararg argument (print(...))
- Function AST generation (Proto->p nested subprotos) (function x() print'a' end x())
- Newclosure AST generation
- Return AST generation
- Normal returns (return 1)
- Vararg return (return 1,2,3,4)
- Table AST generation
- Setlist support (x = {1, 2, 3, 4})
- Newtable support (x = {})
- Settable support (x[1] = 1)
- Local variable AST generation
- "Smart" local variable names
- Numeric for loops (for i=1, 10 do end)
- Nested numeric for loops (for i=1, 10 do for x=1, 100 do end end)
- Range based for loops (for i,v in pairs() do end)
- Nested range based for loops
- if statements
- if then (if true then end)
- Nested if statements
- else
- elseif
- while statements
- Nested while statements