iOS如何防止动态调试

小编给大家分享一下iOS如何防止动态调试,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

碧江网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

防止GDB、lldb依俯。关键字 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 检查是否被调试

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}

xcode 编译,在Other Linker Flags那里添加一条这个字段

-Wl,-sectcreate,__RESTRICT,__restrict,/dev/null

以上是“iOS如何防止动态调试”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


网站标题:iOS如何防止动态调试
网页网址:http://scyanting.com/article/pphsos.html