How to prevent dynamic debugging of iOS
Editor to share with you how to prevent dynamic debugging iOS, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Prevent GDB and lldb from condescending. Keyword ptrace
# import # import 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, charchar * argv []) {# ifndef DEBUG disable_gdb (); # endif @ autoreleasepool {return UIApplicationMain (argc, argv, nil, NSStringFromClass ([WQMainPageAppDelegate class]));}}
Sysctl checks whether it is debugged or not
Int isDebuggerPerforming () {struct kinfo_proc infos_process; size_t size_info_proc = sizeof (infos_process); pid_t pid_process = getpid (); / / pid of the current process / / int mib [] = {CTL_KERN, / / Kernel infos KERN_PROC, / / Search in process table KERN_PROC_PID, / / the process with pid = pid_process} / / pid_process / Retrieve infos for current process in infos_process int ret = sysctl (mib, 4, & infos_process, & size_info_proc, NULL, 0); if (ret) return 0; / / sysctl failed / / struct extern_proc process = infos_process.kp_proc; int flags_process = process.p_flag; return (flags_process & P_TRACED)! = 0 / / value of the debug flag}
Compile with xcode and add this field to Other Linker Flags.
-Wl,-sectcreate,__RESTRICT,__restrict,/dev/null above is all the contents of the article "how to prevent dynamic debugging in iOS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!