c - 带有 PTRACE_O_EXITKILL 的 PTRACE_SETOPTIONS 不起作用:参数无效
问题描述
我正在学习如何使用ptrace
并编写一些代码来测试它。但是,当我尝试使用PTRACE_SETOPTIONS
请求设置PTRACE_O_EXITKILL
选项以在跟踪进程终止时终止跟踪进程时,我遇到了问题。
作为参考,我正在使用适用于 Linux 的 Kali Linux 的 Windows 子系统,运行内核版本 4.4.0。
void child_code();
void parent_code(pid_t pid);
int main(const int argc, char *argv[])
{
pid_t pid;
switch (pid = fork())
{
case -1:
perror("fork");
break;
case 0:
child_code();
break;
default: //parent code
parent_code(pid);
}
return 0;
}
void parent_code(pid_t pid)
{
printf("Parent code\n");
int status;
if (wait(&status) == -1)
{
perror("parent wait one");
}
printf("Finished waiting\n");
printf("PTRACE_O_EXITKILL is %x\n", PTRACE_O_EXITKILL); //0x100000
printf("PTRACE_O_TRACEEXEC is %x\n", PTRACE_O_TRACEEXEC); //0x10
printf("PTRACE_O_TRACEFORK is %x\n", PTRACE_O_TRACEFORK); //0x2
printf("My PID is %d\n", getpid());
err_wrap(
ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_EXITKILL),
0, "ptrace-set-options");
//This is returning EINVAL error and prints "Invalid argument" and I don't know why.
}
void child_code() {
printf("Child code\n");
printf("Parent is: %d\n", getppid());
err_wrap(ptrace(PTRACE_TRACEME, 0,0,0), 0, "ptrace-traceme");
err_wrap(raise(SIGSTOP), 0, "raise");
unsigned int pleb = 0xffbbcde8;
int x = 0;
printf("Hello WoRld\n");
printf("Pleb is: %llx\n", pleb);
printf("x is: %d\n", x);
}
err_wrap 在这里定义
void err_wrap(const int ret, const int success, const char *msg)
{
if (ret != success)
{
perror(msg);
}
}
当我打电话PTRACE_SETOPTIONS
时PTRACE_O_EXITKILL
,它说无效的论点,但我不知道为什么。当我尝试其他选项时PTRACE_O_TRACEEXEC
,它工作正常。不过,我还没有尝试过所有其他选项。
我不明白为什么它不起作用。正如PTRACE_O_EXITKILL
定义的那样,它不是我制作的宏/变量,我认为它ptrace
会识别它,但由于某种原因它不会。我将它打印出来,它与我在ptrace
源代码 ( 0x100000
) 中看到的值相匹配。
任何帮助将不胜感激,谢谢。
解决方案
推荐阅读
- jquery - 按两次 esc 关闭弹出窗口
- scikit-learn - sklearn model_selection 错误:ImportError: cannot import name '_approximate_mode'
- laravel - 如何在 laravel 中使用播种机保存特定文件 .docx
- php - 在 PHP 中计算数组的内存使用情况
- python - Python 解码来自 utf16 的列表元素
- java - 不使用 simpleMailMessage 发送电子邮件
- javascript - 当我想通过 google 或 facebook 登录时,如何使场景自动化?
- android - 在 Kotlin 中覆盖多个版本的构造函数
- mysql - 为什么更新查询在此函数中不起作用?
- python - Tkinter 复选框背景切换