From b34c97efe4c9799cd1f8ec2ee18bd412ab0d050a Mon Sep 17 00:00:00 2001 From: SSharshunov Date: Tue, 7 Apr 2026 20:25:04 +0500 Subject: [PATCH] librz/bin/luac: fix code to work on big endian machines (#6167) --- librz/arch/isa/luac/lua_arch.c | 2 +- librz/arch/p/asm/asm_luac.c | 2 +- librz/bin/format/luac/parse.c | 16 +++++----------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/librz/arch/isa/luac/lua_arch.c b/librz/arch/isa/luac/lua_arch.c index 3d232665cb..bc54660fee 100644 --- a/librz/arch/isa/luac/lua_arch.c +++ b/librz/arch/isa/luac/lua_arch.c @@ -92,7 +92,7 @@ static char *get_const_string_b(const LuacBinInfo *lbi, ut64 addr, ut32 index, s *data_len = const_entrie->data_len; switch (const_entrie->tag) { case LUA_VNUMINT: - sprintf(out_buffer, "%d", *(int *)const_entrie->data); + sprintf(out_buffer, "%" PFMT64u, *(ut64 *)const_entrie->data); return out_buffer; case LUA_VNUMFLT: { const double r = *(double *)const_entrie->data; diff --git a/librz/arch/p/asm/asm_luac.c b/librz/arch/p/asm/asm_luac.c index 98b343de11..d930a02e47 100644 --- a/librz/arch/p/asm/asm_luac.c +++ b/librz/arch/p/asm/asm_luac.c @@ -81,7 +81,7 @@ int rz_luac_asm(const RzAsm *a, RzAsmOp *opstruct, const char *str) { if (instruction == LUA_INVALID_INSTRUCTION) { return -1; } - + rz_write_le32(&instruction, instruction); rz_strbuf_setbin(&opstruct->buf, (const ut8 *)&instruction, 4); return 4; } diff --git a/librz/bin/format/luac/parse.c b/librz/bin/format/luac/parse.c index 92e174dd93..37c4629448 100644 --- a/librz/bin/format/luac/parse.c +++ b/librz/bin/format/luac/parse.c @@ -44,14 +44,6 @@ static int read8_check_val(RzBuffer *buffer, ut64 *offset, const ut16 val, const read8_check_val(buffer, offset, val, err); \ CHECK_SIZE; -static void lua_load_block(RzBuffer *buffer, void *dest, size_t size, ut64 offset, ut64 data_size) { - if (offset + size > data_size) { - RZ_LOG_ERROR("Truncated load block at 0x%llx\n", offset); - return; - } - rz_buf_read_at(buffer, offset, dest, size); -} - static ut64 lua_load_integer(RzBuffer *buffer, ut64 offset) { ut64 x = 0; rz_buf_read_le64_at(buffer, offset, &x); @@ -265,8 +257,9 @@ static ut64 lua_parse_const_entry(const LuaProto *proto, RzBuffer *buffer, int i case LUA_VNUMINT: data_len = sizeof(LUA_NUMBER); recv_data = RZ_NEWS(ut8, data_len); - lua_load_block(buffer, recv_data, data_len, offset, data_size); + rz_buf_read_le64_at(buffer, offset, (ut64 *)recv_data); if (offset + data_len > data_size) { + RZ_FREE(recv_data); return 0; } delta_offset = data_len; @@ -280,7 +273,7 @@ static ut64 lua_parse_const_entry(const LuaProto *proto, RzBuffer *buffer, int i const double fractionalPart = modf(r, &intPart1); if (fractionalPart == 0.0) { current_entry->tag = LUA_VNUMINT; // keep the same with 5.4 tag - rz_write_le64(recv_data, (long long)intPart1); + *(ut64 *)recv_data = (ut64)intPart1; } else { current_entry->tag = LUA_VNUMFLT; // keep the same with 5.4 tag } @@ -303,8 +296,9 @@ static ut64 lua_parse_const_entry(const LuaProto *proto, RzBuffer *buffer, int i } #endif recv_data = RZ_NEWS(ut8, data_len); - lua_load_block(buffer, recv_data, data_len, offset, data_size); + rz_buf_read_le64_at(buffer, offset, (ut64 *)recv_data); if (offset + data_len > data_size) { + RZ_FREE(recv_data); return 0; } delta_offset = data_len;