Advertisement
lilezek

Untitled

Apr 16th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/ptrace.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <sys/user.h>
  6. #include <sys/reg.h>
  7. #include <sys/syscall.h>
  8. #include <unistd.h>
  9.  
  10. int main()
  11. {
  12.  
  13.     struct user data;
  14.  
  15.     pid_t child;
  16.     child = fork();
  17.     if(child == 0) {
  18.         ptrace(PTRACE_TRACEME, 0, NULL, NULL);
  19.         execl("/bin/ls", "ls", NULL);
  20.     }
  21.     else {
  22.         // Get syscall:
  23.         ptrace(PTRACE_SYSCALL,child, NULL ,NULL);
  24.         // Check syscall:
  25.         long sys = ptrace(PTRACE_PEEKUSER,child, NULL, ((long long)&data.regs.orig_rax - (long long)&data));
  26.         printf("Syscall called: %d",(int)sys);
  27.     }
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement