LLDB 无法读取 argv 指针数组中的内存地址,在 C 的 main 方法中作为参数给出

LLDB fails to read the memory adresses in the argv pointer-array, given as an argument in the main method in C

我正在尝试重现 Jon Erickson 在“The Art of Exploitation”一书中给出的示例。该过程实际上非常简单:我想为我的程序提供命令行参数并使用 lldb 检查它们的内存地址。 C class 看起来像这样:

#include <stdio.h>

int main(int arg_count, char *arg_list[]) {
   // something
}

为了使用 lldb 检查程序,我执行以下操作:

lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/Users/<path>/a.out' (x86_64).
(lldb) b main
Breakpoint 1: where = a.out`main + 22 at commandline.c:7:50, address = 0x0000000100003f06
(lldb) run first second

Process 4161 launched: '/Users/<path>/a.out' (x86_64)
Process 4161 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f06 a.out`main(arg_count=3, arg_list=0x00007ffeefbffa40) at commandline.c:7:50
Target 0: (a.out) stopped.

所以现在我希望在 arg_list 中存储的地址之后接下来的三个内存字指向通过命令行给出的字符串的地址。我知道第一个参数始终是一个字符串,其中包含我的 ./a.out 文件的路径。

(lldb) x/3xw arg_list
0x7ffeefbffa40: 0xefbffbb8 0x00007ffe 0xefbffbe9
(lldb) x/s 0xefbffbb8
error: failed to read memory from 0xefbffbb8.
(lldb) x/s 0x00007ffe
error: failed to read memory from 0x7ffe.

所以当我尝试检查内存时,它总是失败。有谁知道为什么?书中的例子使用了gdb调试器,运行良好

这本书看起来是为 32 位代码编写的,但您的系统是 64 位的。所以每个指针都是 64 位。尝试 x/3xg arg_list,其中 g 代表“giant”,gdb 的 8 字节对象大小字母。这应该为您提供三个以 0x00007ffeefbffbb8 开头的 64 位值,然后您可以 x/s 0x00007ffeefbffbb8.

(你可能想找一本更适合你系统的书,或者设置一个 32 位 Linux VM 来跟随它。)