Skip to content

Instantly share code, notes, and snippets.

@kharmabum
Created January 5, 2015 05:34
Show Gist options
  • Save kharmabum/dd6ba37ad53c46f98a4c to your computer and use it in GitHub Desktop.
Save kharmabum/dd6ba37ad53c46f98a4c to your computer and use it in GitHub Desktop.
AmIBeingDebugged
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>
static Bool AmIBeingDebugged(void) {
int mib[4];
struct kinfo_proc info;
size_t size = sizeof(info);
info.kp_proc.p_flag = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
return (info.kp_proc.p_flag & P_TRACED) != 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment