【发布时间】:2012-06-21 04:40:36
【问题描述】:
我正在阅读一篇文章 here 并尝试我在下面复制的代码 sn-p :-
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h> /* For constants
ORIG_EAX etc */
int main()
{ pid_t child;
long orig_eax;
child = fork();
if(child == 0) {
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("/bin/ls", "ls", NULL);
}
else {
wait(NULL);
orig_eax = ptrace(PTRACE_PEEKUSER,
child, 4 * ORIG_EAX,
NULL);
printf("The child made a "
"system call %ld\n", orig_eax);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return 0;
}
我对 ORIG_EAX 到底是什么以及为什么将 4*ORIG_EAX 传递给 ptrace 调用有疑问。我最初假设ORIG_EAX、EBX、ECX 等将是存储寄存器值的特定结构的偏移量。
所以我决定在等待之后使用printf("origeax = %ld\n", ORIG_EAX); 打印 ORIG_EAX 的值。值为11。所以,我之前关于偏移量的假设是错误的。
我了解wait 调用在子级发生状态更改时终止(在这种情况下,发出系统调用)并且 ORIG_EAX 将包含系统调用号。
但是,为什么将 ORIG_EAX * 4 传递给 ptrace 调用?
【问题讨论】:
标签: c linux ptrace systems-programming