我试图获取在调用sys_open
系统调用时打开的文件名,但是我遇到了分段错误。系统调用sys_open
仅打开使用的第一个文件,然后点击分段错误。我该如何解决这个问题?
代码如下所示:
while(1) {
wait(&status);
if(WIFEXITED(status))
break;
orig_eax = ptrace(PTRACE_PEEKUSER,
sb->child, 8 * ORIG_RAX,
NULL);
printf("%l\n", orig_eax);
if(orig_eax == SYS_open) {
if(toggle == 0) {
toggle = 1;
rdi = ptrace(PTRACE_PEEKUSER,
sb->child, 8 * RDI,
NULL);
rsi = ptrace(PTRACE_PEEKUSER,
sb->child, 8 * RSI,
NULL);
rdx = ptrace(PTRACE_PEEKUSER,
sb->child, 8 * RDX,
NULL);
str = (char *)calloc((rdx+1)
, sizeof(char));
getdata(sb->child, rdi, str, 100);
}
else {
toggle = 0;
}
}
ptrace(PTRACE_SYSCALL, sb->child, NULL, NULL);
}