Skip to content

Commit

Permalink
Blind ELF fixes ##bin
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae committed Mar 21, 2023
1 parent 66d6734 commit ef8ec63
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions libr/bin/format/elf/elf.c
Expand Up @@ -3615,24 +3615,32 @@ RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin,

static ut32 hashRBinElfSymbol(const void *obj) {
const RBinElfSymbol *symbol = (const RBinElfSymbol *)obj;
if (!symbol || !*symbol->name) {
if (!symbol || R_STR_ISEMPTY (symbol->name)) {
return 0;
}
int hash = sdb_hash (symbol->name);
hash ^= sdb_hash (symbol->type);
if (R_STR_ISNOTEMPTY (symbol->type)) {
hash ^= sdb_hash (symbol->type);
}
hash ^= (symbol->offset >> 32);
hash ^= (symbol->offset & 0xffffffff);
hash ^= (symbol->offset & UT32_MAX);
return hash;
}

static int cmp_RBinElfSymbol(const RBinElfSymbol *a, const RBinElfSymbol *b) {
if (a->offset != b->offset) {
return 1;
}
if (!a->name || !b->name) {
return 1;
}
int result = strcmp (a->name, b->name);
if (result != 0) {
return result;
}
if (!a->type || !b->type) {
return 1;
}
return strcmp (a->type, b->type);
}

Expand Down Expand Up @@ -3943,15 +3951,14 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type
goto beach;
}
import_ret_ctr = 0;
i = -1;
while (!ret[++i].last) {
for (i = 0; !ret[i].last; i++) {
if (!(import_sym_ptr = Elf_(_r_bin_elf_convert_symbol) (bin, &ret[i], "%s"))) {
continue;
}
setsymord (bin, import_sym_ptr->ordinal, import_sym_ptr);
if (ret[i].is_imported) {
memcpy (&import_ret[import_ret_ctr], &ret[i], sizeof (RBinElfSymbol));
++import_ret_ctr;
import_ret_ctr++;
}
}
import_ret[import_ret_ctr].last = 1;
Expand Down

0 comments on commit ef8ec63

Please sign in to comment.