LuaDecompy/README.md

57 lines
1.8 KiB
Markdown
Raw Normal View History

2022-08-11 20:54:19 +00:00
# LuaDecompy
2022-08-11 21:00:41 +00:00
An experimental Lua 5.1 dump decompiler (typically dumped using `luac -o <out.luac> <script.lua>`).
2022-08-11 20:54:19 +00:00
2022-08-11 21:56:42 +00:00
You will quickly find that only **extremely** simple scripts are decompiled successfully right now. This is an experimental project and not all opcodes are properly handled for now. If you need a real decompiler I would recommend any of the handful of ones that exist already.
## Why?
Lua has a relatively small instruction set (only 38 different opcodes!). This makes it pretty feasible for a weekend decompiler project. (real) Decompilers are extremely complex pieces of software, so being able to write a simpler one helps show the theory without *much* of the headache.
2022-08-11 20:54:19 +00:00
## Example usage
```sh
2022-08-11 21:00:41 +00:00
> cat example.lua && luac5.1 -o example.luac example.lua
i = 0
2022-08-11 21:00:41 +00:00
while i < 10 do
print(i)
i = i + 1
2022-08-11 21:00:41 +00:00
end
> python main.py example.luac
2022-08-11 20:54:19 +00:00
example.luac
==== [[example.lua's constants]] ====
0: [STRING] i
1: [NUMBER] 0.0
2: [NUMBER] 10.0
3: [STRING] print
4: [NUMBER] 1.0
2022-08-11 20:54:19 +00:00
==== [[example.lua's dissassembly]] ====
[ 0] LOADK : R[0] K[1] ; load 0.0 into R[0]
[ 1] SETGLOBAL : R[0] K[0] ;
[ 2] GETGLOBAL : R[0] K[0] ;
[ 3] LT : R[0] R[0] K[2] ;
[ 4] JMP : R[0] 7 ;
[ 5] GETGLOBAL : R[0] K[3] ;
[ 6] GETGLOBAL : R[1] K[0] ;
[ 7] CALL : R[0] 2 1 ;
[ 8] GETGLOBAL : R[0] K[0] ;
[ 9] ADD : R[0] R[0] K[4] ;
[ 10] SETGLOBAL : R[0] K[0] ;
[ 11] JMP : R[0] -10 ;
[ 12] RETURN : R[0] 1 0 ;
2022-08-11 20:54:19 +00:00
==== [[example.lua's decompiled source]] ====
i = 0.0
while i < 10.0 do
print(i)
i = (i + 1.0)
2022-08-11 20:54:19 +00:00
end
2022-08-11 20:54:19 +00:00
```