librz/bin/luac: fix code to work on big endian machines (#6167)

This commit is contained in:
SSharshunov 2026-04-07 20:25:04 +05:00 committed by GitHub
parent 4ad23db90e
commit b34c97efe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 13 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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;