Ptrace on iOS 8

I am trying to call a function on ptrace like this ptrace(PT_DENY_ATTACH, 0, 0, 0); But when I try to import it using #include <sys/ptrace.h> , Xcode gives me the error 'sys/ptrace.h' file not found . Am I missing something, do I need to import the library or is it just not available in iOS?

+7
ios8 ptrace file-not-found
source share
2 answers

The problem is that Xcode adds the base SDK path to all system header paths (e.g. / Applications / Xcode.app / Contents / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS9.0.sdk / USR / include /). Unfortunately, ptrace.h does not exist, but is found in / usr / include / sys /. So, to solve this problem, you need to modify the include statement:

 #include </usr/include/sys/ptrace.h> 

I have no idea why ptrace.h is not included in the SDK, but the functionality you are looking for works when it works on the phone.

Update:. Although this allows you to use the ptrace function, downloading to Apple will lead to application rejection due to:

 Non-public API usage: The app references non-public symbols in <app name>: _ptrace 
+3
source share

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 
+1
source share

All Articles