温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS如何防止动态调试

发布时间:2021-11-24 17:51:40 来源:亿速云 阅读:310 作者:小新 栏目:大数据

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

防止GDB、lldb依俯。关键字 ptrace

#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, 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如何防止动态调试”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios
AI