We have a school project where we need to re-code "strace".
We have to only intercept syscall like write and read, but we cannot use PTRACE_SYSCALL
. I'm looking for a way to do that using PTRACE_SINGLESTEP
, I've already coded a way to print the syscall and when I'm using PTRACE_SYSCALL
it works fine, but when I use PTRACE_SINGLESTEP
I can't find a way to only print the syscalls.
Here is the code I use, maybe someone can help me figure out what's wrong with it:
pid_t child;
long orig_eax;
user_regs_struct regs;
child = fork();
if (child == 0) {
ptrace(PTRACE_TRACEME, 0, 0, 0);
execve("/home/architek/a.out", {"/home/architek/a.out", NULL}, envp);
} else {
waitpid(child, &status, 0);
while (WIFSTOPPED(status)) {
orig_eax = ptrace(PTRACE_PEEKUSER, child, 8 * ORIG_RAX, NULL);
ptrace(PTRACE_GETREGS, child, NULL, ®s);
call_printer(®s, child);
ptrace(PTRACE_SINGLESTEP, child, 0, 0);
waitpid(child, &status, 0);
}
}