Created
November 3, 2025 22:36
-
-
Save deanrock/27084d2bda88a22051b07f49620f0efb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <sys/ptrace.h> | |
| #include <sys/types.h> | |
| #include <sys/wait.h> | |
| #include <unistd.h> | |
| #include <sys/user.h> | |
| #include <sys/syscall.h> | |
| int main() | |
| { pid_t child; | |
| long orig_eax, eax; | |
| 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", NULL); | |
| } | |
| else { | |
| while(1) { | |
| wait(&status); | |
| if(WIFEXITED(status)) | |
| break; | |
| orig_eax = ptrace(PTRACE_PEEKUSER, | |
| child, 8 * 15, | |
| NULL); | |
| printf("after wai %ld\n", orig_eax); | |
| if(orig_eax == SYS_write) { | |
| if(insyscall == 0) { | |
| /* Syscall entry */ | |
| insyscall = 1; | |
| ptrace(PTRACE_GETREGSET, child, | |
| NULL, ®s); | |
| printf("Write called with \n"); | |
| } | |
| else { /* Syscall exit */ | |
| eax = ptrace(PTRACE_PEEKUSER, | |
| child, 8 * 15, | |
| NULL); | |
| printf("Write returned " | |
| "with %ld\n", eax); | |
| insyscall = 0; | |
| } | |
| } | |
| ptrace(PTRACE_SYSCALL, child, | |
| NULL, NULL); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment