1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <sys/types.h>
#include <sys/reg.h>
#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
#include "helper.h"
/*This is a small snippet of code im trying*/
if (child == 0) {
  // In the child process
  ptrace (PTRACE_TRACEME,0,NULL,NULL);
  execl("/home/cdac/Documents/ptrace/file_write","file_write","a.txt", "b.txt", NULL);
}
else {
  while (1){
    int syscall;
                struct user_regs_struct u_in;  //Loop to catch each of e system calls
    wait (&status);      //wait for the child process to finish
    if (WIFEXITED(status))    //The child process exited
      break;
    syscall = ptrace (PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL);  
              if (syscall == SYS_execve) {
      long reg_val_temp[3];
      if (insyscall_5 == 0) {
        counter++;
        insyscall_5 = 1;
        ptrace (PTRACE_GETREGS, child, 0, &u_in);
      }
      else {
        insyscall_5 = 0;
      
      }
    }  


  ptrace (PTRACE_SYSCALL, child, NULL, NULL);
  }
}
return 0;
}