How to print the name of the symbols of ELF files like the nm?

家住魔仙堡 提交于 2019-11-29 16:28:27

Should I cast my shstrab into a Elf64_Sym so that I can use the st_name?

No.

Here is the loop you want:

Elf64_Sym *sym = (Elf64_Sym*) (data + symtab->sh_offset);
str = (char*) (data + strtab->sh_offset);

for (size_t i = 0; i < symtab->sh_size / sizeof(Elf64_Sym); i++) {
  printf("%s\n", str + sym[i].st_name);
}

You have to write symtab->sh_size / symtab->sh_entsize not like symtab->sh_size / sizeof(Elf64_Sym *) as the post above says

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!