Skip to content

Commit

Permalink
Improve the compatibility of symbol search.
Browse files Browse the repository at this point in the history
PLT that is only used internally may not be included in the .hash or .gnu.hash.

Thanks: shuliwu@bytedance.com.
  • Loading branch information
caikelun committed Oct 18, 2021
1 parent 937566c commit 4fc5554
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bytehook/src/main/cpp/bh_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ static ElfW(Sym) *bh_elf_find_import_func_symbol_by_symbol_name(bh_elf_t *self,
if(NULL != sym && BH_ELF_IS_EXPORT_SYM(sym->st_shndx)) return sym;
}

// PLT that is only used internally may not be included in the .hash or .gnu.hash.
//
// from .rel.plt and .rel.dyn, O(n)
for(size_t i = 0; i < self->rel_plt_cnt; i++)
{
size_t sym_idx = BH_ELF_R_SYM(self->rel_plt[i].r_info);
if(0 == strcmp(self->dynstr + self->dynsym[sym_idx].st_name, sym_name)) return &self->dynsym[sym_idx];
}
for(size_t i = 0; i < self->rel_dyn_cnt; i++)
{
size_t sym_idx = BH_ELF_R_SYM(self->rel_dyn[i].r_info);
if(0 == strcmp(self->dynstr + self->dynsym[sym_idx].st_name, sym_name)) return &self->dynsym[sym_idx];
}
return NULL;
}

Expand Down

0 comments on commit 4fc5554

Please sign in to comment.