Advertisement
Guest User

Untitled

a guest
Mar 6th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/ptrace.h>
  5. #include <sys/user.h>
  6. #include <sys/wait.h>
  7. #include <sys/syscall.h>
  8.  
  9. int main(){
  10.     pid_t child;
  11.     long orig_rax, rax;
  12.     int status;
  13.     struct user_regs_struct regs;
  14.  
  15.     child = fork();
  16.     if (child == 0) {
  17.         // Child process
  18.         ptrace(PTRACE_TRACEME, 0, NULL, NULL);
  19.         execl("/bin/ls", "ls", NULL);
  20.         // write(1, "Hi1\n", 4);
  21.         // write(1, "Hi2\n", 4);
  22.     }
  23.     else {
  24.         // Parent process
  25.         wait(&status);
  26.        
  27.         while (WIFSTOPPED(status)) {
  28.             // Get the system call number
  29.             ptrace(PTRACE_GETREGS, child, NULL, &regs);
  30.             orig_rax = regs.orig_rax;
  31.             printf("System call %ld made by child\n", orig_rax);
  32.            
  33.             // Continue the child process
  34.             ptrace(PTRACE_SYSCALL, child, NULL, NULL);
  35.             wait(&status);
  36.         }
  37.     }
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement