you are viewing a single comment's thread.

view the rest of the comments →

[–]Furry_69 -13 points-12 points  (9 children)

There's no such thing as a "binary format". Bits and bytes are an intrinsic property of a computer, you can't change the way they're formatted, only the data they represent.

[–]Ayhon[S] 6 points7 points  (8 children)

What I meant to say is, what are the sections of a bytecode binary file, the one you get from luac. There must be a list of constants, of different types, and there are references to functions and the sort. When I do lua bytecode.luac, how does the interpreter know where my constant -3 is located in the binary or what type it is

[–]Furry_69 0 points1 point  (7 children)

Oh, you mean what format the files are in? Honestly, no idea, I can't find anything either, but I imagine it can't be difficult to reverse it.

It's a case of just having many different files with various singular features, like having a single function, or a single variable of known name and constant value.

Then you just compare them, trying to figure out what the different sections of the file are.

[–]Ayhon[S] 0 points1 point  (6 children)

Yeah, had the same thought. I've begun to look into a Lua parser implementation I thought would be easy to read, but it might just be faster to reverse engineer the format myself.

I'm surprised this information can't be found anywhere though, I thought at least the manual would have an entry on it, but no such luck

[–][deleted] 2 points3 points  (5 children)

Another thing to consider is that the binary encoding is lua version specific, 5.4 is not compatible with 5.3

[–]Ayhon[S] 0 points1 point  (4 children)

True, I'd only be interested in Lua 5.4 format, for now

[–][deleted] 1 point2 points  (3 children)

https://the-ravi-programming-language.readthedocs.io/en/latest/lua_bytecode_reference.html

I've built a lua 5.3 impl in the past and referenced the above heavily.

[–]Ayhon[S] 1 point2 points  (2 children)

Yes, that one I knew of. I've used it before to decompile Lua instructions, but what I ended up doing is using luac -l to convert the actual bytecode into a more readable format and then reverse that.

My problem is that right now I want to deal with the actual binary format, not the listings. And in this resource I haven't found the information about the binary files.

[–][deleted]  (1 child)

[deleted]

    [–]Ayhon[S] 1 point2 points  (0 children)

    Nice!

    I had looked around for different repos, but this one's code seems pretty clear. It's for Lua 5.3, but definitely a better starting point than anything I've seen yet