views:

116

answers:

3

How to detect where strings begin in Lua Bytecode using C#? I would like to list all the strings in a Lua Bytecode file.

+2  A: 

You need to parse the file. There are no special markers. See the source code in lundump.c.

lhf
How can I parse it when there are no markers?
lesderid
Reproduce what lundump.c does, skipping the data you don't want to see.
lhf
A: 

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).

Merlyn Morgan-Graham
A: 

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.

DeadMG
This 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