From f6c24f2a473cdbd66aa6fa03ce2158a52866aaef Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 9 Jan 2025 18:02:11 +0100 Subject: [PATCH] Fix #23865 - imports vaddr on some ELFs reporting below baddr locations ##bin --- libr/bin/format/elf/elf.c | 13 ++++++++++++- test/db/formats/elf/symbols | 31 +++++++++++++++++++++++++++++++ test/db/formats/mangling/mangling | 6 +++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 44e7dcfcb595e..193f80ef9f197 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -4360,12 +4360,23 @@ static void _set_arm_thumb_bits(struct Elf_(obj_t) *eo, RBinSymbol **symp) { // XXX this is slow because we can directly use RBinSymbol instead of RBinElfSymbol imho RBinSymbol *Elf_(convert_symbol)(ELFOBJ *eo, RBinElfSymbol *symbol) { ut64 paddr, vaddr; + const ut64 baddr = Elf_(get_baddr) (eo); + if (baddr && baddr != UT64_MAX && symbol->offset && symbol->offset != UT64_MAX) { + if (symbol->is_vaddr && symbol->offset < baddr) { + symbol->is_vaddr = false; + } + } if (symbol->is_vaddr) { paddr = UT64_MAX; vaddr = symbol->offset; } else { paddr = symbol->offset; - vaddr = Elf_(p2v_new) (eo, paddr); + ut64 va = Elf_(p2v_new) (eo, paddr); + if (va != UT64_MAX) { + vaddr = va; + } else { + vaddr = paddr; + } } RBinSymbol *ptr = R_NEW0 (RBinSymbol); diff --git a/test/db/formats/elf/symbols b/test/db/formats/elf/symbols index e8790f50d2ce0..856a90af55162 100644 --- a/test/db/formats/elf/symbols +++ b/test/db/formats/elf/symbols @@ -186,3 +186,34 @@ EXPECT=<