lua-users home
lua-l archive

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


In short, what is the state of decompilers for Lua such and for Lua version 5.4?  I gather the need for a  decompiler is just a nice-to-have kind of thing, but too much effort for anyone to work on it seriously for any sustained period of time. And possibly it is not well understood how to write a good decompiler.

For the last 5 years or so I have been maintaining a decompiler for Python which I have been doing as a hobby. In that, I have come to understand what I think has been a good methodology  for thinking about decompilation of high-level dynamic languages which use high-level bytecode. And over the years, I have improved the technology I use.

It strikes me that Lua and its bytecode fall into this category of high-level dynamic languages with high-level bytecode. I can't find any effort for a decompiler for lua 5.4.x. Has Lua bytecode or its compilation changed significantly?  

It looks to me like luadec, some C-based code, originally by Hisham Muhammad has more or less been the only decompiler out there. 

https://github.com/viruscamp/luadec seems to pull together as a single project this code on github, although it doesn't look like this has been worked on in a while and the project seems mostly about organizing the code rather than actively working on it or fixing bugs. Looking at the class of bugs reported and the Readme for LuaDec51 by Zsolt Sz. Sztupak,  it strikes me that the weakness of decompiling code with complex branching and control flow has been a problem right from the start. It has also plagued the Python decompiler, but I now think I have a good handle on that.

 https://www.lua.org/wshop05/Muhammad.pdf  describes how this works, and I just posted a short description of iit in StackOverflow. See https://stackoverflow.com/a/70284539/546218

Lastly, I will mention that I've written about how this kind of decompiler is structured in https://github.com/rocky/python-uncompyle6/wiki/How-does-this-code-work%3F and a longer (older) version is https://rocky.github.io/Deparsing-Paper.pdf