Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <errno.h>
- #include <stdio.h>
- #include <sys/ptrace.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/user.h>
- #include <sys/reg.h>
- #include <sys/syscall.h>
- #include <unistd.h>
- int main()
- {
- struct user data;
- pid_t child;
- child = fork();
- long sys = -2;
- if(child == 0) {
- ptrace(PTRACE_TRACEME, 0, NULL, NULL);
- execl("/bin/ls", "ls", NULL);
- }
- else while (sys != 60 and sys != -1)
- {
- if (sys == -2)
- wait(NULL);
- // Get syscall:
- if (ptrace(PTRACE_SYSCALL,child, NULL ,NULL) == -1)
- fprintf(stderr,"Syscall failed: %s\n", strerror(errno));
- wait(NULL);
- // Check syscall:
- sys = ptrace(PTRACE_PEEKUSER,child, ((long long)&data.regs.orig_rax - (long long)&data), NULL);
- if (sys == -1)
- fprintf(stderr,"Syscall failed: %s\n", strerror(errno));
- else
- fprintf(stderr,"Syscall called: %d\n",(int)sys);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement