From c4ed5950d86d512974898b8fb44fae5db6d4e24f Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 11 Oct 2024 02:10:40 +0200 Subject: [PATCH] fii --- libr/bin/format/elf/elf.c | 7 +++++-- libr/core/cbin.c | 26 ++++++++++++++---------- test/db/anal/thumb | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 57fe6a8c4c..9b3656c73a 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -4320,6 +4320,7 @@ static void _set_arm_thumb_bits(struct Elf_(obj_t) *eo, RBinSymbol **symp) { RBinSymbol *sym = *symp; const char *name = r_bin_name_tostring2 (sym->name, 'o'); int len = strlen (name); + sym->bits = bin_bits; if (name[0] == '$' && (len >= 2 && !name[2])) { switch (name[1]) { case 'a' : // arm @@ -4334,14 +4335,16 @@ static void _set_arm_thumb_bits(struct Elf_(obj_t) *eo, RBinSymbol **symp) { sym->paddr--; } return; +#if 0 case 'd': // data + sym->bits = 32; return; +#endif default: break; } } - sym->bits = bin_bits; - if (bin_bits != 64) { + if (sym->bits != 64) { sym->bits = 32; if (sym->paddr != UT64_MAX) { if (sym->vaddr & 1) { diff --git a/libr/core/cbin.c b/libr/core/cbin.c index e10e087678..3dadd30801 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -709,7 +709,7 @@ static void load_types_from(RCore *core, const char *fmt, ...) { R_API void r_core_anal_type_init(RCore *core) { R_RETURN_IF_FAIL (core && core->anal); - int bits = core->rasm->config->bits; + const int bits = core->rasm->config->bits; Sdb *types = core->anal->sdb_types; // make sure they are empty this is initializing sdb_reset (types); @@ -2418,30 +2418,36 @@ static void handle_arm_special_symbol(RCore *core, RBinSymbol *symbol, int va) { } } -static void handle_arm_hint(RCore *core, RBinInfo *info, ut64 paddr, ut64 vaddr, int bits, int va) { - if (info->bits > 32) { // we look at 16 or 32 bit only +static void handle_arm_hint(RCore *core, RBinInfo *bi, ut64 paddr, ut64 vaddr, int sym_bits, int va) { + if (bi->bits > 32) { // we look at 16 or 32 bit only return; } int force_bits = 0; ut64 addr = compute_addr (core->bin, paddr, vaddr, va); - if (paddr & 1 || bits == 16) { + if (paddr & 1 || sym_bits == 16) { force_bits = 16; - } else if (info->bits == 16 && bits == 32) { + } else if (bi->bits == 16 && sym_bits == 32) { #if 1 // ignore this case, which causes false positives on half-arm-thumb binaries if (vaddr & 1) { force_bits = 16; } else { - RAnalHint *hint = r_anal_hint_get (core->anal, vaddr); + // XXX ruseli fails + force_bits = 32; +#if 0 + RAnalHint *hint = r_anal_hint_get (core->anal, addr); if (hint && hint->bits == 32) { force_bits = 32; } else { - return; + force_bits = 32; + //return; + // force_bits = 0; } +#endif } #endif - } else if (!(paddr & 1) && bits == 32) { + } else if (!(paddr & 1) && sym_bits == 32) { force_bits = 32; } if (force_bits) { @@ -2753,8 +2759,8 @@ next: // handle thumb and arm for entry point since they are not present in symbols if (is_arm) { - r_list_foreach (entries, iter, entry) { - if (IS_MODE_SET (mode)) { + if (IS_MODE_SET (mode)) { + r_list_foreach (entries, iter, entry) { handle_arm_entry (r, entry, info, va); } } diff --git a/test/db/anal/thumb b/test/db/anal/thumb index 85777d6f58..d791444eda 100755 --- a/test/db/anal/thumb +++ b/test/db/anal/thumb @@ -71,3 +71,45 @@ svc 0x42 svc 0xb6 EOF RUN + +NAME=arm/thumb imports +FILE=bins/elf/libmagic.so +CMDS=<