查找进程的rendezvous(struct r_debug)结构?

问题描述 投票:2回答:1

我正在尝试访问“rendezvous结构”(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是对的,我正在查看与位置无关的可执行文件。他计算搬迁的解决方案非常有效。

c linux debugging elf debug-symbols
1个回答
1
投票

我究竟做错了什么 ?

您很可能正在查看与位置无关的可执行文件。如果你的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)。

您可以在辅助向量中的AT_PHDR值和Phdr_pt_phdr.p_vaddr之间找到此重定位地址。

(上面我使用Phdr_xxx作为Phdr[j].p_type == xxx的简写)。

你也是以比你更复杂的方式做到这一点:动态数组的地址可以简单地用作_DYNAMIC[]。见this answer

© www.soinside.com 2019 - 2024. All rights reserved.