-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_example.c
66 lines (64 loc) · 1.69 KB
/
3_example.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/reg.h>
#include <sys/syscall.h>
#include <stdio.h>
int main()
{
pid_t child;
long orig_rax, rax;
long params[3];
int status;
int insyscall = 0;
struct user_regs_struct regs;
child = fork();
if(child == 0)
{
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("/bin/ls", "ls", "-l" ,NULL);
}
else
{
while(1)
{
wait(&status);
if(WIFEXITED(status))
break;
orig_rax = ptrace(PTRACE_PEEKUSER,
child,
8 * ORIG_RAX,
NULL);
if(orig_rax == SYS_write)
{
if(insyscall == 0)
{
/* Syscall entry */
insyscall = 1;
ptrace(PTRACE_GETREGS,
child,
NULL,
®s);
printf("Write called with %lld, %lld, %lld\n",
regs.rdi, regs.rsi, regs.rdx);
}
else /* Syscall exit */
{
rax = ptrace(PTRACE_PEEKUSER,
child,
8 * RAX,
NULL);
printf("Write returned with %ld\n", rax);
insyscall = 0;
}
}
ptrace(PTRACE_SYSCALL,
child,
NULL,
NULL);
}
}
return 0;
}