【发布时间】:2021-02-15 20:25:19
【问题描述】:
我正在尝试重现 Jon Erickson 在“剥削的艺术”一书中给出的示例。该过程实际上非常简单:我想为我的程序提供命令行参数并使用 lldb 检查它们的内存地址。 C 类看起来像这样:
#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调试器,效果很好。
【问题讨论】: