This seems to work for me and prevent the debugger from attaching. I have not tested #ifdef OPTIMIZE if it works in the distribution, so let me know if you find any problems.
//#include <sys/ptrace.h> #import <dlfcn.h> #import <sys/types.h> typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data); #if !defined(PT_DENY_ATTACH) #define PT_DENY_ATTACH 31 #endif // !defined(PT_DENY_ATTACH) void disable_gdb() { void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW); ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace"); ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0); dlclose(handle); } int main(int argc, char *argv[]) { //#ifndef DEBUG => use the following instead. #ifdef __OPTIMIZE__ //ptrace(PT_DENY_ATTACH, 0, 0, 0); disable_gdb(); #endif
Nikolay DS
source share