Last active
September 25, 2018 08:47
-
-
Save camillobruni/6602939 to your computer and use it in GitHub Desktop.
A little example showing how ptrace works under OSX
This file contains 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/types.h> | |
#include <sys/ptrace.h> | |
#include <unistd.h> | |
int main(int argc, char *argv[]) | |
{ | |
int target_pid; | |
long ret; | |
target_pid = atoi(argv[1]); | |
printf("attach to %i \n", target_pid); | |
ret = ptrace (PT_ATTACH, target_pid, NULL, 0); | |
printf("attach %lu \n", ret); | |
sleep(5); | |
ret = ptrace (PT_CONTINUE, target_pid, NULL, 0); | |
printf("continue %lu \n", ret); | |
sleep(5); | |
ret = ptrace (PT_DETACH, target_pid, NULL, 0); | |
printf("detach %lu \n", ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment