luadec
A Lua 5.1 bytecode decompiler written in Rust.
luadec takes compiled Lua 5.1 bytecode (.luac files) and reconstructs readable Lua source code. It performs control-flow analysis, dominator-tree construction, loop detection, and liveness analysis to produce structured output with proper if/elseif/while/for constructs.
Features
- Decompiles Lua 5.1 bytecode to readable Lua source
- Reconstructs control flow:
if/elseif/else,while,repeat/until, numericfor, genericfor - Handles local variable recovery (with or without debug info)
- Supports varargs, closures, and table constructors
- Usable as a library or via the CLI tool
Installation
From Source
The binary will be at target/release/luadec.
Usage
Command Line
# Decompile a .luac file and print to stdout
# Decompile and write to a file
# Read from stdin
|
As a Library
Add luadec-rust to your Cargo.toml:
[]
= "1"
Simple usage:
let bytecode = read.unwrap;
let source = decompile.unwrap;
println!;
For more control over the decompilation pipeline:
use lua_bytecode;
use Lifter;
use emit;
let data = read.unwrap;
let = lua_bytecode.unwrap;
// Decompile to AST
let func = decompile;
// Emit as Lua source
let source = emit_chunk;
Project Structure
| Crate | Description |
|---|---|
luadec-rust |
Core decompiler library. Exposes luadec_rust::decompile() and the lua51 module for fine-grained access. |
luadec-cli |
Command-line interface. Thin wrapper around the library. |
Internal Modules (luadec_rust::lua51)
| Module | Purpose |
|---|---|
opcodes |
Lua 5.1 opcode definitions |
instruction |
Instruction decoding and representation |
cfg |
Control-flow graph construction |
dominator |
Dominator tree and natural loop detection |
liveness |
Register liveness analysis |
ast |
AST node types for decompiled output |
lifter |
Bytecode → AST decompilation |
emit |
AST → Lua source code generation |
Acknowledgments
The bytecode parser uses luac-parser-rs by metaworm. Thank you for the excellent work on Lua bytecode parsing.
License
MIT