views:

68

answers:

2

Is it possible to change strings (content and size) in Lua bytecode so that it will still be correct? It's about translating strings in Lua bytecode. Of course, not every language has the same size for each word...

+2  A: 

Yes, it is if you know what you're doing. Strings are prefixed by their size stored as an int. The size and endianness of that int is platform-dependent. But why do you have to edit bytecode? Have you lost the sources?

lhf
Where are there sizes stored? Is there any application which automatically changes the lengths after them being edited? I didn't make the sources. The bytecode is available to the general public for free and the changes that I'll make are going to be for personal use.
lesderid
Like I said, the strings are prefixed by their size. Try an hexdump of the bytecode files you have.
lhf
So if you just change the prefix, it should work? No errors with calling those strings or something (because of the changed locations)?
lesderid
If you change the strings and correct the size accordingly, then it should work. Note that strings contain a NUL byte at the end.
lhf
Isn't there any hashing to check the strings?
lesderid
Strings are hashed when loaded.
lhf
A: 

You can try using the decompiler LuaDec. The decompiler would allow the strings to be modified in generated Lua code similar to the original source.

ChunkSpy has A No-Frills Introduction to Lua 5.1 VM Instructions that may help you understand the compiled chunk format and make the changes directly to bytecode if necessary.

gwell