Skip to content

Instantly share code, notes, and snippets.

@abhisek
Created January 15, 2022 15:24
Show Gist options
  • Save abhisek/add729bf9177324d0440ae3e8f67ef20 to your computer and use it in GitHub Desktop.
Save abhisek/add729bf9177324d0440ae3e8f67ef20 to your computer and use it in GitHub Desktop.
#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