diff options
| author | ruki <[email protected]> | 2026-02-12 00:56:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-12 00:56:34 +0800 |
| commit | 3acfe25582459f8eb3237d7ff64baaef706284f3 (patch) | |
| tree | 4569171854032d98ac149badb363915d12fc328a /core/src | |
| parent | b445dc4e25b5acceacaabcea627fba3703050e15 (diff) | |
improve readsyms
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/binutils/ar/readsyms.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/binutils/elf/prefix.h | 6 |
2 files changed, 11 insertions, 5 deletions
diff --git a/core/src/xmake/binutils/ar/readsyms.c b/core/src/xmake/binutils/ar/readsyms.c index 3af3f8a62..9249d0a0a 100644 --- a/core/src/xmake/binutils/ar/readsyms.c +++ b/core/src/xmake/binutils/ar/readsyms.c @@ -41,15 +41,15 @@ static tb_int_t xm_binutils_ar_detect_member_format(tb_stream_ref_t istream, tb_ } tb_stream_seek(istream, base_offset); - if (magic[0] == 0x00 && magic[1] == 0x61 && magic[2] == 0x73 && magic[3] == 0x6d) { + if (magic[0] == XM_WASM_MAGIC0 && magic[1] == XM_WASM_MAGIC1 && magic[2] == XM_WASM_MAGIC2 && magic[3] == XM_WASM_MAGIC3) { return XM_BINUTILS_FORMAT_WASM; } - if (magic[0] == 0x7f && magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') { + if (magic[0] == XM_ELF_MAGIC0 && magic[1] == XM_ELF_MAGIC1 && magic[2] == XM_ELF_MAGIC2 && magic[3] == XM_ELF_MAGIC3) { return XM_BINUTILS_FORMAT_ELF; } - if ((magic[0] == 0xfe && magic[1] == 0xed && magic[2] == 0xfa && (magic[3] == 0xce || magic[3] == 0xcf)) || - (magic[0] == 0xce && magic[1] == 0xfa && magic[2] == 0xed && magic[3] == 0xfe) || - (magic[0] == 0xcf && magic[1] == 0xfa && magic[2] == 0xed && magic[3] == 0xfe)) { + tb_uint32_t macho_magic = tb_bits_get_u32_be(magic); + if (macho_magic == XM_MACHO_MAGIC_32 || macho_magic == XM_MACHO_MAGIC_64 || + macho_magic == XM_MACHO_MAGIC_32_BE || macho_magic == XM_MACHO_MAGIC_64_BE) { return XM_BINUTILS_FORMAT_MACHO; } return XM_BINUTILS_FORMAT_UNKNOWN; diff --git a/core/src/xmake/binutils/elf/prefix.h b/core/src/xmake/binutils/elf/prefix.h index 2561b41cb..6bf64b2ed 100644 --- a/core/src/xmake/binutils/elf/prefix.h +++ b/core/src/xmake/binutils/elf/prefix.h @@ -29,6 +29,12 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ +// ELF file magic: 0x7f 'E' 'L' 'F' +#define XM_ELF_MAGIC0 0x7f +#define XM_ELF_MAGIC1 'E' +#define XM_ELF_MAGIC2 'L' +#define XM_ELF_MAGIC3 'F' + // ELF class #define XM_ELF_EI_CLASS 4 #define XM_ELF_CLASS32 1 |
