1111#include <rz_lib.h>
1212#include <rz_list.h>
1313
14+ // #define RZ_DEBUG
1415/* Macros for bin_luac.c */
1516/* Macros/Typedefs used in luac */
1617typedef double LUA_NUMBER ;
@@ -88,6 +89,7 @@ typedef ut32 LUA_INT;
8889#define LUAC_55_NUMBER_VALID_OFFSET 0x17
8990#define LUAC_55_UPVALUES_NUMBER_OFFSET 0x1F
9091
92+ #define LUAC_MAGIC "\x1b\x4c\x75\x61" ///< "\033Lua"
9193#define LUAC_FORMAT 0 /* this is the official format */
9294#define LUAC_DATA "\x19\x93\r\n\x1a\n"
9395#define LUAC_INT_VALIDATION luac_cast_int(0x5678)
@@ -103,8 +105,6 @@ typedef ut32 LUA_INSTRUCTION;
103105#define LUAC_VERSION_OFFSET 0x04
104106#define LUAC_VERSION_SIZE 1
105107
106- #define LUAC_MAGIC "\x1b\x4c\x75\x61" ///< "\033Lua"
107-
108108/* Body */
109109#define LUAC51_FILENAME_OFFSET 0x13
110110#define LUAC52_FILENAME_OFFSET 0x00
@@ -161,6 +161,7 @@ typedef struct lua_proto_ex {
161161 RzList /*<LuaUpvalueEntry *>*/ * upvalue_entries ; ///< A list to store upvalue entries
162162 ut64 upvalue_offset ; ///< upvalue section offset
163163 ut64 upvalue_size ; ///< upvalue section size
164+ ut64 size_upvalues ; ///< upvalue size (v5.5)
164165
165166 /* store protos defined in this proto */
166167 RzList /*<LuaProto *>*/ * proto_entries ; ///< A list to store sub proto entries
@@ -179,6 +180,26 @@ typedef struct lua_proto_ex {
179180
180181typedef LuaProtoHeavy LuaProto ;
181182
183+ /**
184+ * \struct lua_header_info
185+ * \brief Store header information of luac file
186+ */
187+ typedef struct lua_header_info {
188+ st32 major ; ///< major version
189+ st32 minor ; ///< minor version
190+ // ut8 version; ///< type of this constant, see LUA_V* macros in luac_common.h
191+ ut8 format ; ///< type of this constant, see LUA_V* macros in luac_common.h
192+ ut8 endianness ; ///< type of this constant, see LUA_V* macros in luac_common.h
193+ st32 int_size ; ///< type of this constant, see LUA_V* macros in luac_common.h
194+ ut8 size_t_size ; ///< type of this constant, see LUA_V* macros in luac_common.h
195+ st32 instruction_size ; ///< type of this constant, see LUA_V* macros in luac_common.h
196+ st32 integer_size ; ///< type of this constant, see LUA_V* macros in luac_common.h
197+ st32 number_size ; ///< type of this constant, see LUA_V* macros in luac_common.h
198+ ut8 is_number_integral ; ///< is lua_Number integral? (< 5.3)
199+ size_t psize ; ///< Physical size of header in bytes
200+ char * src_file_name ;
201+ } LuaHeaderInfo ;
202+
182203/**
183204 * \struct lua_constant_entry
184205 * \brief Store constant type, data, and offset of this constant in luac file
@@ -246,18 +267,17 @@ typedef struct lua_dbg_upvalue_entry {
246267} LuaDbgUpvalueEntry ;
247268
248269/**
249- * \struct lua_bin_info
270+ * \struct luac_bin_info
250271 * \brief A context info structure for luac plugin.
251272 */
252273typedef struct luac_bin_info {
253- st32 major ; ///< major version
254- st32 minor ; ///< minor version
255274 LuaProto * proto ;
256275 RzPVector /*<RzBinSection *>*/ * section_vec ; ///< list of sections
257276 RzList /*<RzBinSymbol *>*/ * symbol_list ; ///< list of symbols
258277 RzPVector /*<RzBinAddr *>*/ * entry_vec ; ///< list of entries
259278 RzList /*<RzBinString *>*/ * string_list ; ///< list of strings
260279 RzBinInfo * general_info ; ///< general binary info from luac header
280+ LuaHeaderInfo * header ;
261281} LuacBinInfo ;
262282
263283/* ========================================================
@@ -294,23 +314,18 @@ void _luac_build_info(LuaProto *proto, LuacBinInfo *info);
294314 * Export version specified Api to bin_luac.c
295315 * Implemented in bin/format/luac/v[version]/bin_[version]
296316 * ======================================================== */
297- RzBinInfo * lua_parse_header_54 (RzBinFile * bf , st8 major , st8 minor );
317+ RzBinInfo * lua_parse_header_54 (RzBinFile * bf , ut8 major , ut8 minor );
298318LuaProto * lua_parse_body_54 (RzBuffer * buffer , ut64 offset , ut64 data_size );
299319
300- RzBinInfo * lua_parse_header_53 (RzBinFile * bf , st8 major , st8 minor );
320+ RzBinInfo * lua_parse_header_53 (RzBinFile * bf , ut8 major , ut8 minor );
301321LuaProto * lua_parse_body_53 (RzBuffer * buffer , ut64 offset , ut64 data_size );
302322
303- RzBinInfo * lua_parse_header_52 (RzBinFile * bf , st8 major , st8 minor );
323+ RzBinInfo * lua_parse_header_52 (RzBinFile * bf , ut8 major , ut8 minor );
304324LuaProto * lua_parse_body_52 (RzBuffer * buffer , ut64 offset , ut64 data_size );
305325
306- ut8 luac_header_size (const ut8 minor );
307- // static void lua_load_block(RzBuffer *buffer, void *dest, size_t size, ut64 offset, ut64 data_size);
308- // static ut64 lua_load_integer(RzBuffer *buffer, ut64 offset);
309- // static double lua_load_number(RzBuffer *buffer, ut64 offset);
310- // static ut32 lua_load_int(RzBuffer *buffer, ut64 offset);
311- // static ut64 lua_parse_name(LuaProto *proto, RzBuffer *buffer, ut64 offset, ut64 data_size, st8 minor);
312- LuaProto * lua_parse_body (RzBuffer * buffer , ut64 base_offset , ut64 data_size , st8 minor );
313- RzBinInfo * lua_parse_header (const RzBinFile * bf , st8 major , st8 minor );
326+ LuaProto * lua_parse_body (RzBuffer * buffer , LuaHeaderInfo * header , ut64 base_offset , ut64 data_size );
327+ RzBinInfo * lua_parse_header (const RzBinFile * bf , const LuaHeaderInfo * header );
328+ size_t parse_header (const RzBinFile * bf , LuaHeaderInfo * header );
314329
315330#define lua_check_error_offset (offset ) \
316331 if ((offset) == 0) { \
0 commit comments