gpt4 book ai didi

c - (ORIG_EAX*4) 在 ptrace 调用中

转载 作者:IT王子 更新时间:2023-10-29 00:25:54 25 4
gpt4 key购买 nike

我正在浏览一篇文章 here并正在尝试我在下面复制的代码片段:-

#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_EAXEBXECX 等将是存储寄存器值的特定结构的偏移量。

所以我决定在等待之后使用 printf("origeax = %ld\n", ORIG_EAX); 打印 ORIG_EAX 的值。值为 11。因此,我之前关于抵消的假设是错误的。

据我了解,wait 调用会在子级发生状态更改(在本例中为发出系统调用)时终止,并且 ORIG_EAX 将包含系统调用号。

但是,为什么 ORIG_EAX * 4 会传递给 ptrace 调用?

最佳答案

参数是 user_regs_struct 的偏移量.请注意,其中每一个都是 unsigned long,因此要获得第 11 个条目 (orig_eax),以字节为单位的偏移量为 44,(前提是您在 x86 机器上当然)。

关于c - (ORIG_EAX*4) 在 ptrace 调用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11095927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com