#include <errno.h> #include "sys/ptrace.h" #include "sys/wait.h" #include "unistd.h" #include "sys/reg.h" #include "stdlib.h" #include "errno.h" #include "string.h" #include "sys/types.h" #include "stdio.h" 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, 8*ORIG_RAX, NULL); if (orig_eax == -1) { printf("%s\n", strerror(errno)); } printf("The child made a system call %ld\n", orig_eax); ptrace(PTRACE_CONT, child, NULL, NULL); } return 0;}
注意:此程序比网上流传的一般程序做了如下修改:
1.头文件部分重新引用,尤其是引用了
#include "sys/reg.h"
2.修改部分语句,如:
orig_eax= ptrace(PTRACE_PEEKUSER,child, 8*ORIG_RAX, NULL);此处再64位上应为8,与ORIG_RAX