我正在尝试访问“会合结构”(struct r_debug *) 为了找到进程的链接映射。 但我一直遇到无效地址,我真的想不通 发生了什么事。
下面是我如何继续尝试找到它:
1. Get the AT_PHDR value from the auxiliary vector
2. Go through the program headers until I find the PT_DYNAMIC segment
3. Try to access the vaddr of that segment (PT_DYNAMIC) to get the dynamic tags
4. Iterate through the dynamic tags until I find DT_DEBUG. If I get here I should be done
问题是我无法通过第 3 步,因为 PT_DYNAMIC 的 vaddr 段总是指向无效地址。
我做错了什么?我需要找到 vaddr 的搬迁吗? 我查看了 LLDB 源代码,但我无法弄清楚他们是如何获得地址的。
更新:@EmployedRussian 是对的,我在看一个与位置无关的可执行文件。 他计算搬迁的解决方案非常有效。
最佳答案
What am I doing wrong ?
您很可能正在查看与位置无关的可执行文件。如果您的 readelf -Wl a.out
如下所示:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0001f8 0x0001f8 R 0x8
INTERP 0x000238 0x0000000000000238 0x0000000000000238 0x00001c 0x00001c R 0x1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x016d28 0x016d28 R E 0x200000
LOAD 0x017250 0x0000000000217250 0x0000000000217250 0x0010d0 0x001290 RW 0x200000
DYNAMIC 0x017df8 0x0000000000217df8 0x0000000000217df8 0x0001e0 0x0001e0 RW 0x8
然后需要通过可执行重定位地址调整Phdr_pt_dynamic.p_vaddr
(关键是第一个Phdr_pt_load.p_vaddr == 0
)。
您可以找到此重定位地址作为辅助 vector 中的 AT_PHDR
值与 Phdr_pt_phdr.p_vaddr
之间的增量。
(以上我使用 Phdr_xxx
作为 Phdr[j]
和 .p_type == xxx
的简写)。
您还以比必须的方式复杂得多的方式进行操作:动态数组的地址可以作为 _DYNAMIC[]
轻松获得。参见 this answer .
关于c - 查找进程的集合点(struct r_debug)结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55643058/