-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_example.c
36 lines (34 loc) · 838 Bytes
/
1_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
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reg.h>
#include <sys/user.h>
#include <stdio.h>
#include <string.h>
/*
* long ptrace(enum __ptrace_request request, pid_t pid,
* void *addr, void *data);
*/
int main()
{
pid_t child;
child = fork();
if(child == 0)
{
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("/bin/ls", "ls", "-la", NULL);
}
else
{
wait(NULL);
long rax_reg_value = ptrace(PTRACE_PEEKUSER,
child,
8 * ORIG_RAX,
NULL);
printf("The child made a "
"system call %ld\n", rax_reg_value);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return 0;
}