How to detect where strings begin in Lua Bytecode using C#? I would like to list all the strings in a Lua Bytecode file.
-
I think you'd have to write some portion of a LUA compiler to ensure you were finding strings 100% correctly. You could use regular expressions, but I'm sure there are some cases where they would fail (e.g. multi-line strings) – Merlyn Morgan-Graham Sep 11 '10 at 09:52
-
3@Merl: The OP said "bytecode", not "source code". RegExp's are not that useful with binary data. – Steven Sudit Sep 11 '10 at 10:17
3 Answers
Can't find the reference to the same statement on LUA's site, but here is a quote I found elsewhere:
there is no official specification of the Lua virtual machine instruction set, there is no need for one; the only official specification is of the Lua language
This document does try to break up the instruction set and provide a pseudo-spec from reverse engineering:
http://luaforge.net/docman/index.php?group_id=83&selected_doc_group_id=102&language_id=1
In that doc, it says that strings are constants attached to each function (w/ the exception of globals, which are in a table).

- 58,163
- 16
- 128
- 183
As far as I know, literal strings are stored in bytecode in the same format as they are in sourcecode- that is, "sometexthere". However, I suggest that you just compile a Lua file with nothing but a function with a string returned and see what it looks like in bytecode.

- 144,682
- 38
- 256
- 465
-
1This is not correct. See http://stackoverflow.com/questions/3660387/is-it-possible-to-change-strings-content-and-size-in-lua-bytecode-so-that-it-wi/3661621#3661621 – lhf Sep 13 '10 at 16:56