Skip to content

Instantly share code, notes, and snippets.

@camillobruni
Last active September 25, 2018 08:47
Show Gist options
  • Save camillobruni/6602939 to your computer and use it in GitHub Desktop.
Save camillobruni/6602939 to your computer and use it in GitHub Desktop.
A little example showing how ptrace works under OSX
#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