mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
patterns: Added Lua 5.3 bytecode pattern (#285)
This commit is contained in:
@@ -82,6 +82,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi
|
|||||||
| JPEG | `image/jpeg` | [`patterns/jpeg.hexpat`](patterns/jpeg.hexpat) | JPEG Image Format |
|
| JPEG | `image/jpeg` | [`patterns/jpeg.hexpat`](patterns/jpeg.hexpat) | JPEG Image Format |
|
||||||
| Lua 5.1 | | [`patterns/lua51.hexpat`](patterns/lua51.hexpat) | Lua 5.1 bytecode |
|
| Lua 5.1 | | [`patterns/lua51.hexpat`](patterns/lua51.hexpat) | Lua 5.1 bytecode |
|
||||||
| Lua 5.2 | | [`patterns/lua52.hexpat`](patterns/lua52.hexpat) | Lua 5.2 bytecode |
|
| Lua 5.2 | | [`patterns/lua52.hexpat`](patterns/lua52.hexpat) | Lua 5.2 bytecode |
|
||||||
|
| Lua 5.3 | | [`patterns/lua53.hexpat`](patterns/lua53.hexpat) | Lua 5.3 bytecode |
|
||||||
| Lua 5.4 | | [`patterns/lua54.hexpat`](patterns/lua54.hexpat) | Lua 5.4 bytecode |
|
| Lua 5.4 | | [`patterns/lua54.hexpat`](patterns/lua54.hexpat) | Lua 5.4 bytecode |
|
||||||
| LCE Savefile | | [`patterns/lcesave.hexpat`](patterns/lcesave.hexpat) | Minecraft Legacy Console Edition save file |
|
| LCE Savefile | | [`patterns/lcesave.hexpat`](patterns/lcesave.hexpat) | Minecraft Legacy Console Edition save file |
|
||||||
| Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable |
|
| Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable |
|
||||||
|
|||||||
107
patterns/lua53.hexpat
Normal file
107
patterns/lua53.hexpat
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#pragma description Lua 5.3 bytecode
|
||||||
|
|
||||||
|
import std.io;
|
||||||
|
import type.base;
|
||||||
|
|
||||||
|
namespace impl {
|
||||||
|
fn format_LuaString(auto string) {
|
||||||
|
if (string.size == 0) {
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
return std::format("\"{}\"", string.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
fn format_Constant(auto constant) {
|
||||||
|
return constant.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
fn format_Version(auto ver) {
|
||||||
|
return std::format("Ver. {}.{}", ver.major, ver.minor);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
using LuaFunction;
|
||||||
|
|
||||||
|
bitfield Version {
|
||||||
|
minor : 4;
|
||||||
|
major : 4;
|
||||||
|
} [[format("impl::format_Version")]];
|
||||||
|
|
||||||
|
struct LuaBinaryHeader {
|
||||||
|
char magic[4];
|
||||||
|
Version version_number;
|
||||||
|
u8 format_version;
|
||||||
|
char LUAC_DATA[6];
|
||||||
|
u8 size_of_int;
|
||||||
|
u8 size_of_size_t;
|
||||||
|
u8 size_of_Instruction;
|
||||||
|
u8 size_of_lua_Integer;
|
||||||
|
u8 sizeof_lua_Number;
|
||||||
|
type::Hex<u64> LUAC_INT;
|
||||||
|
double LUAC_NUM;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LuaString {
|
||||||
|
u8 size;
|
||||||
|
if (size > 0) {
|
||||||
|
char data[size-1];
|
||||||
|
}
|
||||||
|
}[[format("impl::format_LuaString")]];
|
||||||
|
|
||||||
|
struct LuaConstant {
|
||||||
|
u8 type;
|
||||||
|
if (type == 0) { // LUA_TNIL
|
||||||
|
// NULL
|
||||||
|
} else if (type == 1) { // LUA_TBOOLEAN
|
||||||
|
u8 data;
|
||||||
|
} else if (type == 3) { // LUA_TNUMFLT
|
||||||
|
double data;
|
||||||
|
} else if (type == 0x13) { // LUA_TNUMINT
|
||||||
|
u64 data;
|
||||||
|
} else if (type == 4 || type == 0x14 ) { // LUA_TSHRSTR LUA_TLNGSTR
|
||||||
|
LuaString data;
|
||||||
|
}
|
||||||
|
}[[format("impl::format_Constant")]];
|
||||||
|
|
||||||
|
struct LuaUpvalue {
|
||||||
|
u8 instack;
|
||||||
|
u8 idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Vector<T> {
|
||||||
|
u32 size;
|
||||||
|
T values[size];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LocalVar {
|
||||||
|
LuaString varname;
|
||||||
|
u32 startpc;
|
||||||
|
u32 endpc;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LuaDebugInfo {
|
||||||
|
Vector<u32> lineInfo;
|
||||||
|
Vector<LocalVar> local_vars;
|
||||||
|
Vector<LuaString> upvalues;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LuaFunction {
|
||||||
|
LuaString source;
|
||||||
|
u32 line_defined;
|
||||||
|
u32 last_line_defined;
|
||||||
|
u8 number_of_parameters;
|
||||||
|
u8 is_vararg;
|
||||||
|
u8 maxstacksize;
|
||||||
|
Vector<u32> code;
|
||||||
|
Vector<LuaConstant> constants;
|
||||||
|
Vector<LuaUpvalue> upvalues;
|
||||||
|
Vector<LuaFunction> protos;
|
||||||
|
LuaDebugInfo debugInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LuaFile {
|
||||||
|
LuaBinaryHeader header;
|
||||||
|
u8 sizeupvalues;
|
||||||
|
LuaFunction func;
|
||||||
|
};
|
||||||
|
|
||||||
|
LuaFile file @ 0;
|
||||||
BIN
tests/patterns/test_data/lua53.hexpat.lua
Normal file
BIN
tests/patterns/test_data/lua53.hexpat.lua
Normal file
Binary file not shown.
Reference in New Issue
Block a user