diff options
| author | ruki <[email protected]> | 2025-12-11 23:36:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-12 09:00:44 +0800 |
| commit | b0eb30a4becb5b6d925aa77418ce30c7f1f79d69 (patch) | |
| tree | 4a812f15e6ee9af5370d8b6bed8733e3bfb52ce1 /core/src | |
| parent | 4ccb8514f37fdf7108b41dbcd8ca77143841e1cd (diff) | |
update format
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/binutils/ar/prefix.h | 2 | ||||
| -rw-r--r-- | core/src/xmake/binutils/macho/prefix.h | 4 | ||||
| -rw-r--r-- | core/src/xmake/binutils/macho/readsyms.c | 80 |
3 files changed, 43 insertions, 43 deletions
diff --git a/core/src/xmake/binutils/ar/prefix.h b/core/src/xmake/binutils/ar/prefix.h index 392e0c37e..6f4d0f35b 100644 --- a/core/src/xmake/binutils/ar/prefix.h +++ b/core/src/xmake/binutils/ar/prefix.h @@ -64,7 +64,7 @@ typedef struct __xm_ar_header_t { */ static __tb_inline__ tb_int64_t xm_binutils_ar_parse_decimal(tb_char_t const *str, tb_size_t len) { tb_assert_and_check_return_val(str && len > 0, -1); - + tb_int64_t result = 0; for (tb_size_t i = 0; i < len; i++) { if (str[i] == ' ' || str[i] == '\0') { diff --git a/core/src/xmake/binutils/macho/prefix.h b/core/src/xmake/binutils/macho/prefix.h index f3c6e2302..3ef32763d 100644 --- a/core/src/xmake/binutils/macho/prefix.h +++ b/core/src/xmake/binutils/macho/prefix.h @@ -334,7 +334,7 @@ static __tb_inline__ tb_uint32_t xm_binutils_macho_parse_version(tb_char_t const */ static __tb_inline__ tb_bool_t xm_binutils_macho_detect_format(tb_uint8_t const *magic_bytes, tb_bool_t *is_32bit, tb_bool_t *swap_bytes) { tb_assert_and_check_return_val(magic_bytes && is_32bit && swap_bytes, tb_false); - + // check for little-endian magic numbers if (magic_bytes[0] == 0xce && magic_bytes[1] == 0xfa && magic_bytes[2] == 0xed && magic_bytes[3] == 0xfe) { *is_32bit = tb_true; @@ -355,7 +355,7 @@ static __tb_inline__ tb_bool_t xm_binutils_macho_detect_format(tb_uint8_t const *swap_bytes = tb_true; return tb_true; } - + return tb_false; } diff --git a/core/src/xmake/binutils/macho/readsyms.c b/core/src/xmake/binutils/macho/readsyms.c index fac925d22..dde7739e8 100644 --- a/core/src/xmake/binutils/macho/readsyms.c +++ b/core/src/xmake/binutils/macho/readsyms.c @@ -94,7 +94,7 @@ static __tb_inline__ tb_void_t xm_binutils_macho_swap_nlist_64(xm_macho_nlist_64 tb_bool_t xm_binutils_macho_read_symbols_32(tb_stream_ref_t istream, lua_State *lua, tb_bool_t swap_bytes) { tb_assert_and_check_return_val(istream && lua, tb_false); - + // read Mach-O header xm_macho_header_t header; if (!tb_stream_seek(istream, 0)) { @@ -104,16 +104,16 @@ tb_bool_t xm_binutils_macho_read_symbols_32(tb_stream_ref_t istream, lua_State * return tb_false; } xm_binutils_macho_swap_header_32(&header, swap_bytes); - + // find LC_SYMTAB command xm_macho_symtab_command_t symtab_cmd; tb_bool_t found_symtab = tb_false; - + tb_uint32_t offset = sizeof(header); for (tb_uint32_t i = 0; i < header.ncmds; i++) { tb_uint32_t cmd; tb_uint32_t cmdsize; - + if (!tb_stream_seek(istream, offset)) { return tb_false; } @@ -123,7 +123,7 @@ tb_bool_t xm_binutils_macho_read_symbols_32(tb_stream_ref_t istream, lua_State * if (!tb_stream_bread(istream, (tb_byte_t*)&cmdsize, 4)) { return tb_false; } - + if (cmd == XM_MACHO_LC_SYMTAB) { if (!tb_stream_seek(istream, offset)) { return tb_false; @@ -134,23 +134,23 @@ tb_bool_t xm_binutils_macho_read_symbols_32(tb_stream_ref_t istream, lua_State * found_symtab = tb_true; break; } - + offset += cmdsize; } - + if (!found_symtab) { lua_newtable(lua); return tb_true; } - + // create result table lua_newtable(lua); - + // read symbols if (!tb_stream_seek(istream, symtab_cmd.symoff)) { return tb_false; } - + tb_uint32_t result_count = 0; for (tb_uint32_t i = 0; i < symtab_cmd.nsyms; i++) { xm_macho_nlist_t nlist; @@ -158,49 +158,49 @@ tb_bool_t xm_binutils_macho_read_symbols_32(tb_stream_ref_t istream, lua_State * return tb_false; } xm_binutils_macho_swap_nlist_32(&nlist, swap_bytes); - + // skip NULL symbols if (nlist.strx == 0) { continue; } - + // get symbol name tb_char_t name[256]; if (!xm_binutils_macho_read_string(istream, symtab_cmd.stroff, nlist.strx, name, sizeof(name)) || !name[0]) { continue; } - + // skip internal symbols (starting with .) if (name[0] == '.') { continue; } - + // create symbol table entry lua_pushinteger(lua, result_count + 1); lua_newtable(lua); - + // name lua_pushstring(lua, "name"); lua_pushstring(lua, name); lua_settable(lua, -3); - + // type (nm-style: T/t/D/d/B/b/U) tb_char_t type_char = xm_binutils_macho_get_symbol_type_char(nlist.type, nlist.sect); tb_char_t type_str[2] = {type_char, '\0'}; lua_pushstring(lua, "type"); lua_pushstring(lua, type_str); lua_settable(lua, -3); - + lua_settable(lua, -3); result_count++; } - + return tb_true; } tb_bool_t xm_binutils_macho_read_symbols_64(tb_stream_ref_t istream, lua_State *lua, tb_bool_t swap_bytes) { tb_assert_and_check_return_val(istream && lua, tb_false); - + // read Mach-O header xm_macho_header_64_t header; if (!tb_stream_seek(istream, 0)) { @@ -210,16 +210,16 @@ tb_bool_t xm_binutils_macho_read_symbols_64(tb_stream_ref_t istream, lua_State * return tb_false; } xm_binutils_macho_swap_header_64(&header, swap_bytes); - + // find LC_SYMTAB command xm_macho_symtab_command_t symtab_cmd; tb_bool_t found_symtab = tb_false; - + tb_uint32_t offset = sizeof(header); for (tb_uint32_t i = 0; i < header.ncmds; i++) { tb_uint32_t cmd; tb_uint32_t cmdsize; - + if (!tb_stream_seek(istream, offset)) { return tb_false; } @@ -229,12 +229,12 @@ tb_bool_t xm_binutils_macho_read_symbols_64(tb_stream_ref_t istream, lua_State * if (!tb_stream_bread(istream, (tb_byte_t*)&cmdsize, 4)) { return tb_false; } - + if (swap_bytes) { cmd = tb_bits_swap_u32(cmd); cmdsize = tb_bits_swap_u32(cmdsize); } - + if (cmd == XM_MACHO_LC_SYMTAB) { if (!tb_stream_seek(istream, offset)) { return tb_false; @@ -246,23 +246,23 @@ tb_bool_t xm_binutils_macho_read_symbols_64(tb_stream_ref_t istream, lua_State * found_symtab = tb_true; break; } - + offset += cmdsize; } - + if (!found_symtab) { lua_newtable(lua); return tb_true; } - + // create result table lua_newtable(lua); - + // read symbols if (!tb_stream_seek(istream, symtab_cmd.symoff)) { return tb_false; } - + tb_uint32_t result_count = 0; for (tb_uint32_t i = 0; i < symtab_cmd.nsyms; i++) { xm_macho_nlist_64_t nlist; @@ -270,62 +270,62 @@ tb_bool_t xm_binutils_macho_read_symbols_64(tb_stream_ref_t istream, lua_State * return tb_false; } xm_binutils_macho_swap_nlist_64(&nlist, swap_bytes); - + // skip NULL symbols if (nlist.strx == 0) { continue; } - + // get symbol name tb_char_t name[256]; if (!xm_binutils_macho_read_string(istream, symtab_cmd.stroff, nlist.strx, name, sizeof(name)) || !name[0]) { continue; } - + // skip internal symbols (starting with .) if (name[0] == '.') { continue; } - + // create symbol table entry lua_pushinteger(lua, result_count + 1); lua_newtable(lua); - + // name lua_pushstring(lua, "name"); lua_pushstring(lua, name); lua_settable(lua, -3); - + // type (nm-style: T/t/D/d/B/b/U) tb_char_t type_char = xm_binutils_macho_get_symbol_type_char(nlist.type, nlist.sect); tb_char_t type_str[2] = {type_char, '\0'}; lua_pushstring(lua, "type"); lua_pushstring(lua, type_str); lua_settable(lua, -3); - + lua_settable(lua, -3); result_count++; } - + return tb_true; } tb_bool_t xm_binutils_macho_read_symbols(tb_stream_ref_t istream, lua_State *lua) { tb_assert_and_check_return_val(istream && lua, tb_false); - + // read and check magic tb_uint8_t magic_bytes[4]; if (!xm_binutils_read_magic(istream, magic_bytes, 4)) { return tb_false; } - + // detect Mach-O format tb_bool_t is_32bit = tb_false; tb_bool_t swap_bytes = tb_false; if (!xm_binutils_macho_detect_format(magic_bytes, &is_32bit, &swap_bytes)) { return tb_false; } - + if (is_32bit) { return xm_binutils_macho_read_symbols_32(istream, lua, swap_bytes); } else { |
