Disassembling a compiled lua module using a questionable method
Most of the times, one could use a lua script with an intepreter and be done with it. Then there’s the times that one want to compile it. For example: corona framework.
One time, I was provided with a resource.car
package and a request: “Somewhere in that package is a list of items. Extract it.”
At the time, I’m not that fluent with lua. I knew the language but had never worked with it before. It seemed that my chance had come.
Extracting the package itself was easy. I grabbed the corona-archiver and extract it:
corona-archiver -u resource.car data\
Inside the extracted folder was a bunch of *.lu
files. Reading them directly would be just like reading an Elder Scroll with a telescope. So I searched around, and found the luadec.
luadec
could disassemble any compiled lua module, but the output read like a kudzu forest.
But I didn’t know better. So I imported a pure lua JSON library on the top of the file and output it at the end.
It kinda worked. But data is subtly wrong because the decompiler often get confused when dealing with list construct.
In my frustration, I tried to see what was it that caused the error.
luadec -dis data.MaterialData.lua > dis.txt
Hah, the disassembled file read even better than the generated lua. For one, I liked the naming R1
better than local l_0_0 = nil
.
The format was awefully familiar. If you strip the first part with regex: .*;
and then replace the :=
with =
, the leftover was undoubtedly javascript.
Except the part that denote a loop R2[(1–1)*FPF+i] = R(2+i), 1 <= i <= 2
That part is equivalent to:
for (var i = 1; i <= 2; i++) {
R2[i] = window['R' + (2 + i)];
}
So I wrote a piece of code to convert this loop. It only worked with this kind of simple loop though.
With this final touch, the disassembled file can be converted to javascript. And extracting data from a javascript file is a piece of cake.