Created
January 15, 2022 15:24
-
-
Save abhisek/add729bf9177324d0440ae3e8f67ef20 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 <stdlib.h> | |
#include <sys/ptrace.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <assert.h> | |
#include <signal.h> | |
void hello() { | |
printf("Hello debugger\n"); | |
} | |
main() { | |
int ret; | |
pid_t child; | |
child = fork(); | |
if (!child) { | |
sleep(2); | |
printf("Running child\n"); | |
hello(); | |
exit(0); | |
} | |
ret = ptrace(PTRACE_ATTACH, child, 0L, 0L); | |
assert(ret == 0); | |
waitpid(child, &ret, 0); | |
unsigned char bp[8]; | |
memset(&bp, 0xcc, 8); | |
ret = ptrace(PTRACE_POKEDATA, child, &hello, (void*) &bp); | |
assert(ret == 0); | |
ret = ptrace(PTRACE_CONT, child, 0L, 0L); | |
assert(ret == 0); | |
exit(1); | |
//waitpid(child, &ret, 0); | |
//printf("Parent done\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment