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...
views:
68answers:
2
+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
2010-09-07 18:42:14
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
2010-09-08 16:44:39
Like I said, the strings are prefixed by their size. Try an hexdump of the bytecode files you have.
lhf
2010-09-08 20:04:54
So if you just change the prefix, it should work? No errors with calling those strings or something (because of the changed locations)?
lesderid
2010-09-09 15:25:55
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
2010-09-09 17:22:04
Isn't there any hashing to check the strings?
lesderid
2010-09-10 19:42:46
Strings are hashed when loaded.
lhf
2010-09-10 20:35:57
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
2010-09-08 22:45:06