Currently, I am trying to read a Lua file, and the file says .lua, but when I open it, it appears to be some oddly formatted byte code. Currently, the only readily readable byte code starts as \27LuaQ with no minor code and no endianness, etc.
Exception in thread "main" java.lang.IllegalStateException: The input chunk reports a non-standard lua format: 1
at unluac.parse.LHeaderType.parse_format(LHeaderType.java:87)
at unluac.parse.LHeaderType51.parse_main(LHeaderType.java:338)
at unluac.parse.LHeaderType.parse(LHeaderType.java:67)
at unluac.parse.BHeader.<init>(BHeader.java:84)
at unluac.Main.file_to_function(Main.java:116)
at unluac.Main.main(Main.java:58)
I have spent a few hours messing around, assigning a functional byte code to see if there was an error upon compilation. However, no matter what I do, none of the decompilers work. I've used unluac, chunkspy, and luadec and all of them result in a poorly formatted bytecode header. Not a single one could decomp or analyze. Looking at the file that is in question, I can see that for a bytecode file, there is quite a lot of padding (0x00) that is replaced with 0x20 which I believe is a ' '. You will also notice that the file has LuaQ which was my doing and I forgot to edit it back. The original was LupQ, which I thought was possibly a security measure, but not 100% sure I'm correct about that.
Currently, I have concluded that it is probably I who has missed something important and fundamental and any information helps. I have included a link to which you can download the code file.
This file belongs to Star Wars: Empire at War, an old PC game by Petroglyph from 2006, so it is likely any compilation was done with Lua 5.1 Here is the header, and then some (136 bits, cut off at the first piece of discernable code):
1B4C 7561 5101 0404 0406 0809 0908 B609
9368 E7F5 7D41 0800 0000 3D28 6E6F 6E65
2900 0000 0000 0100 0000 0000 0002 0000
0000 0000 0000 0000 0000 0700 0000 0410
0000 0044
Here is a link to the file (it is being hosted on my student Gmail account): pgdebug.lua
Petrolution Mod-Tools says this:
This format is used in the games Empire at War and Forces of Corruption.
Each Petroglyph Lua object file is basically a normal Lua 5.0 object file except for three differences:
- The signature for Lua 5.0 object files is "\033Lua". For Petroglyph's Lua object files this is "\033Lup"
- The byte that indicates the file version is 0x50 for the Lua 5.0 object files. Petroglyph's Lua object files use 0x51 (it really IS a 5.0 file though).
- In each function header, Petroglyph's Lua object files have an additional integer right after the "lineDefined" integer that can be ignored.
The additional integer seems to start at 1 for the first function in the file, and then increases by one for every other function, disregarding function nesting. This integer is supposedly used to allow for persistent Lua state during save-games.
It looks like unluac, although primarily for Lua 5.1, also mostly works for Lua 5.0. You'll have to either make slight modifications to it to account for those three differences, or edit the files to undo those changes before running unluac.
Also, Petrolution also has some tools that look like they can do at least some of what you're trying to do.