Skip to content

Commit

Permalink
Fix #17523 - Resolve internal symbols referenced from the PLT ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 26, 2023
1 parent 7db7177 commit d736136
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions libr/bin/format/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) {
/* non-thumb entry points */
if (!memcmp (buf, "\x00\xb0\xa0\xe3\x00\xe0\xa0\xe3", 8)) {
if (buf[0x40 + 2] == 0xff && buf[0x40 + 3] == 0xeb) {
// nothing may happen
// nothing to do
} else if (!memcmp (buf + 0x28 + 2, "\xff\xeb", 2)) {
return Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[0x34]) & ~1);
}
Expand Down Expand Up @@ -4175,6 +4175,7 @@ RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin, s
ptr->bind = symbol->bind;
ptr->type = symbol->type;
ptr->is_imported = symbol->is_imported;
// ptr->is_internal = symbol->is_internal;
ptr->paddr = paddr;
ptr->vaddr = vaddr;
ptr->size = symbol->size;
Expand Down Expand Up @@ -4489,14 +4490,12 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
bool is_sht_null = false;
bool is_vaddr = false;
bool is_imported = false;
bool is_internal = false;
if (type == R_BIN_ELF_IMPORT_SYMBOLS) {
if (memory.sym[k].st_value) {
toffset = memory.sym[k].st_value;
} else if ((toffset = get_import_addr (bin, k)) == -1) {
toffset = 0;
}
toffset = get_import_addr (bin, k);
tsize = 16;
is_imported = memory.sym[k].st_shndx == STN_UNDEF;
is_imported = true;
is_internal = memory.sym[k].st_shndx != STN_UNDEF;
} else {
tsize = memory.sym[k].st_size;
toffset = (ut64)memory.sym[k].st_value;
Expand Down Expand Up @@ -4539,6 +4538,7 @@ static RVector /* <RBinElfSymbol> */ *Elf_(_r_bin_elf_load_symbols_and_imports)(
es->is_sht_null = is_sht_null;
es->is_vaddr = is_vaddr;
es->is_imported = is_imported;
es->is_internal = is_internal;
if (type == R_BIN_ELF_IMPORT_SYMBOLS && is_imported) {
import_ret_ctr++;
}
Expand Down
1 change: 1 addition & 0 deletions libr/bin/format/elf/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct r_bin_elf_symbol_t {
bool is_sht_null;
bool is_vaddr; /* when true, offset is virtual address, otherwise it's physical */
bool is_imported;
bool is_internal;
} RBinElfSymbol;

typedef struct r_bin_elf_reloc_t {
Expand Down
4 changes: 3 additions & 1 deletion libr/bin/p/bin_elf.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,13 @@ static RList* imports(RBinFile *bf) {

RBinElfSymbol *import_symbol;
r_vector_foreach (import_symbols, import_symbol) {
if (import_symbol->is_internal) {
continue;
}
RBinImport *ptr = R_NEW0 (RBinImport);
if (!ptr) {
break;
}

ptr->name = strdup (import_symbol->name);
ptr->bind = import_symbol->bind;
ptr->type = import_symbol->type;
Expand Down

0 comments on commit d736136

Please sign in to comment.