Skip to content

Commit 25698c0

Browse files
committed
patterns: Add Lua 5.0 pattern
Based on Lua 5.1 pattern.
1 parent 4646e4b commit 25698c0

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
117117
| LOC | | [`patterns/loc.hexpat`](patterns/loc.hexpat) | Minecraft Legacy Console Edition Language file |
118118
| Lua 4.0 | | [`patterns/lua40.hexpat`](patterns/lua40.hexpat) | Lua 4.0 bytecode |
119119
| LUC | | [`patterns/popcap_luc.hexpat`](patterns/popcap_luc.hexpat) | PopCap's proprietary Lua bytecode |
120+
| Lua 5.0 | | [`patterns/lua50.hexpat`](patterns/lua50.hexpat) | Lua 5.0 bytecode |
120121
| Lua 5.1 | | [`patterns/lua51.hexpat`](patterns/lua51.hexpat) | Lua 5.1 bytecode |
121122
| Lua 5.2 | | [`patterns/lua52.hexpat`](patterns/lua52.hexpat) | Lua 5.2 bytecode |
122123
| Lua 5.3 | | [`patterns/lua53.hexpat`](patterns/lua53.hexpat) | Lua 5.3 bytecode |

patterns/lua50.hexpat

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#pragma description Lua 5.0 bytecode
2+
#pragma magic [ 1B 4C 75 61 50 ] @ 0x00
3+
4+
import std.io;
5+
6+
namespace impl {
7+
fn format_LuaString(auto string) {
8+
if (string.size == 0) {
9+
return "None";
10+
}
11+
return std::format("\"{}\"", string.data);
12+
};
13+
14+
fn format_Constant(auto constant) {
15+
return constant.data;
16+
};
17+
18+
fn format_Version(auto ver) {
19+
return std::format("Ver. {}.{}", ver.major, ver.minor);
20+
};
21+
}
22+
using LuaFunction;
23+
24+
bitfield Version {
25+
minor : 4;
26+
major : 4;
27+
} [[format("impl::format_Version")]];
28+
29+
struct LuaBinaryHeader {
30+
char magic[4];
31+
Version version_number;
32+
u8 endianness;
33+
u8 size_of_int;
34+
u8 size_of_size_t;
35+
u8 size_of_Instruction;
36+
u8 size_of_op;
37+
u8 size_of_a;
38+
u8 size_of_b;
39+
u8 size_of_c;
40+
u8 size_of_lua_Number;
41+
double test_number;
42+
};
43+
44+
struct LuaString {
45+
if (header.size_of_size_t == 4) {
46+
u32 size;
47+
} else {
48+
u64 size;
49+
}
50+
if (size > 0) {
51+
char data[size];
52+
}
53+
}[[format("impl::format_LuaString")]];
54+
55+
struct LuaConstant {
56+
u8 type;
57+
if (type == 0) { // LUA_TNIL
58+
// NULL
59+
} else if (type == 1) { // LUA_TBOOLEAN
60+
u8 data;
61+
} else if (type == 3) { // LUA_TNUMBER
62+
double data;
63+
} else if (type == 4) { // LUA_TSTRING
64+
LuaString data;
65+
}
66+
}[[format("impl::format_Constant")]];
67+
68+
struct Vector<T> {
69+
u32 size;
70+
if (size > 0) {
71+
T values[size];
72+
}
73+
};
74+
75+
struct LocalVar {
76+
LuaString varname;
77+
u32 startpc;
78+
u32 endpc;
79+
};
80+
81+
struct LuaDebugInfo {
82+
Vector<u32> lineInfo;
83+
Vector<LocalVar> localVar;
84+
Vector<LuaString> upvalues;
85+
};
86+
87+
struct LuaConstants{
88+
Vector<LuaConstant> constants;
89+
u32 sizep; // size of proto
90+
if (sizep > 0) {
91+
LuaFunction protos[sizep];
92+
}
93+
};
94+
95+
struct LuaFunction {
96+
LuaString source;
97+
u32 linedefined;
98+
u8 nups; // number of upvalues
99+
u8 numparams;
100+
u8 is_vararg;
101+
u8 maxstacksize;
102+
LuaDebugInfo debugInfo;
103+
LuaConstants luaConstants;
104+
Vector<u32> code;
105+
};
106+
107+
LuaBinaryHeader header @ 0;
108+
LuaFunction toplevelFunction @ 22;

0 commit comments

Comments
 (0)