Decompile Luac
Requires a Java Runtime Environment (JRE) installed on your system. 2. LuaDec (Best for Legacy Lua 5.1 - 5.3)
Any notes or comments written by the original author are permanently erased during compilation.
luac -l -p input.luac
| Problem | Likely cause | Fix | |---------|--------------|-----| | unrecognized version | Wrong Lua version | Detect and use correct tool | | no debug info | Stripped locals/names | Decompiled code has generic names (e.g., _1 , _2 ) | | compressed luac | Stripped or pre-compressed | Try lua-lz or unluac --rawstring | | invalid instruction | Corrupted file or encrypted | Check file header, XOR/obfuscation? | | unluac fails on 5.4 | Newer opcodes | Use --rawstring or wait for updates | decompile luac
java -jar unluac2023-04-11.jar my_script.luac > decompiled.lua
With Luadec, Alex could now take a luac file and, with some degree of accuracy, recover the original Lua source code. He was thrilled to see his tool in action, watching as it successfully decompiled scripts that had been compiled months ago.
./luadec your_file.luac > decompiled.lua Requires a Java Runtime Environment (JRE) installed on
The most frequent challenge is stripped debugging information. This data contains the names of local variables and exact line numbers. Without it, the decompiler lacks the context to restore original, meaningful variable names. Instead, it assigns generic placeholders like v0 , v1 , etc., which, while logically correct, can be difficult to follow. unluac relies on debugging info to determine which VM registers correspond to local variables, and without a good fallback, can produce suboptimal results for stripped files.
Decompiled code is rarely identical to the original script. Local variable names and comments are completely discarded during compilation unless explicit debug flags (like luac -s ) were omitted. Key Challenges in LUAC Decompilation
Reverse engineering and decompiling third-party software may violate Terms of Service (ToS) or End User License Agreements (EULAs). Ensure you have the legal right or authorization to decompile target binaries before proceeding. If you want to dive deeper into this process, let me know: What game or application you are trying to decompile? luac -l -p input
Developers frequently compile bytecode using the -s flag ( luac -s script.lua ). This strips out:
A user possesses a compiled luac file from an embedded system (unknown version). The feature analyzes the header, determines it is Lua 5.1 64-bit Little Endian, identifies a FORPREP instruction loop, and outputs the corresponding for i = 1, 10 do ... end Lua syntax, ready for modification or auditing.
For a more stable and feature-rich option, luadec is a strong candidate. Developed in C, it supports Lua versions 5.1, 5.2, and 5.3. Beyond its core decompiler ( luadec ), the package includes utilities like luaopswap for manipulating opcodes in obfuscated bytecode and ChunkSpy for detailed disassembly. The tool's development focuses on robustness, with known forks like hengtek/luadecz introducing reliable decompilation for bytecode with stripped debug information on Lua 5.2 and 5.3.