Skip to content

Commit

Permalink
patterns/lua5.1: Fixed a bug in the Lua 5.1 bytecode pattern (#298)
Browse files Browse the repository at this point in the history
* Fixed a bug in the Lua 5.1 bytecode pattern

Lua 5.1 bytecode upvalue fields were incorrectly defined as a `Vector<u32>` instead of `Vector<LuaString>`.

* Fixed another bug in the lua 5.1 bytecode pattern

Lua 5.1 bytecode string sizes were incorrectly parsed as a 64-bit integer, instead of a 32-bit integer.

* Updated the Lua 5.1 bytecode pattern for 32-bit compilers.

Updated the pattern to allow for 32-bit and 64-bit integers for the size of the string length field.
  • Loading branch information
Guest257351 authored Nov 17, 2024
1 parent abbd25e commit 323898d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions patterns/lua51.hexpat
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ struct LuaBinaryHeader {
u8 lua_Number;
u8 is_lua_Number_integral;
};

LuaBinaryHeader header @ 0;

struct LuaString {
u64 size;
if (header.size_of_size_t == 4) {
u32 size;
} else {
u64 size;
}
if (size > 0) {
char data[size];
}
Expand Down Expand Up @@ -72,7 +79,7 @@ struct LocalVar {
struct LuaDebugInfo {
Vector<u32> lineInfo;
Vector<LocalVar> localVar;
Vector<u32> upvalues;
Vector<LuaString> upvalues;
};

struct LuaConstants{
Expand All @@ -96,9 +103,4 @@ struct LuaFunction {
LuaDebugInfo debugInfo;
};

struct LuaFile {
LuaBinaryHeader header;
LuaFunction func;
};

LuaFile file @ 0;
LuaFunction toplevelFunction @ 12; // Lua header size is always 12 bytes

0 comments on commit 323898d

Please sign in to comment.