我正在编写一个用户态 elf 加载器作为一个业余项目,以了解有关 ELF 文件及其工作原理的更多信息。我想知道从哪里获取从动态库(libc.so.6
)加载符号的地址。
当我反汇编程序时,我得到:
$objdump -d test | grep puts
400420: ff 25 f2 0b 20 00 jmpq *0x200bf2(%rip) # 601018 <puts@GLIBC_2.2.5>
0x200bf2
是函数所在的地址,但是我从哪里获取它呢?
编辑:我询问它的加载位置而不是定义位置,因此 st_value
无关
最佳答案
您必须手动解析 Sprite 。
此类信息可以在符号表部分中找到:
This contains a list of all of the symbols (program entry points, addresses of variables, etc.) that are defined or referenced within the file, the address associated with the symbol, and some kind of tag indicating the type of the symbol.
(From The Linux Journal)
要查找符号表,请迭代各个部分,直到找到 sh_type = SHT_SYMTAB
的部分,然后对其进行适当的解析。
符号表是 Elf32_Sym
和/或 Elf64_Sym
结构的数组。该方法的地址将分配给结构体的 st_value
成员,该成员相对于索引 st_shndx
处的节头。
更多信息,您可以引用:
关于c - 动态符号的地址从何而来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46879401/