lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have a collection of luac files that were compiled with Lua 5.0.2. Unfortunately I do not have the original source code files anymore. In an attempt to recover the original source code I investigated the available Lua decompilers. The only decompiler I found that works for Lua 5.0 binaries is luadec [1],[2]. It was only able to decompile about 60% of my files. On the remaining files it either asserts or complains about unsupported constructs in the code. Even the successfully decompiled files do not seem 100% correct.

The Lua 5.1 decompilers seem to have evolved significantly in terms of correctness, robustness and the quality of the generated code, for example luadec51 [3]. If I want to utilise these decompilers I'll have to somehow convert the Lua 5.0 binaries to Lua 5.1 binaries.

My question to the community is whether this has been done before? If so, can you provide any pointers to it? 

If the answer is no, I would appreciate some pointers on how to go about implementing such a conversion myself. I have found a few possible approaches. 

* The ChunkSpy [4] utility supports rewriting of chunks from one platform format to another. Maybe one can hook into the rewrite function to do such a conversion? Some pointers as to the differences between Lua 5.0 and 5.1 bytecodes are provided in chapter 15 of the document "A No-Frills Introduction to Lua 5.1 VM Instructions" [5].

* Another approach might be to base a converter the lundump.c and ldump.c files. The implementation would probably consist of modifying the lundump.c file from Lua 5.0 to read the chunks and create some intermediate data structures. Then one can modify the ldump.c file from Lua 5.1 to convert this intermediate representation and write out 5.1 chunks.

The approach may seem simple, but I suspect the difficulty will be in handling cases where the behaviors of existing opcodes have changed.

Regards
J

[1] http://luadec.luaforge.net/
[2] http://files.luaforge.net/releases/luadec/luadec
[3] https://github.com/sztupy/luadec51
[4] http://chunkspy.luaforge.net/
[5] http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf