• Swift 判断是否是调试模式以及是否越狱


    以下两段代码是从安全公司里面代码

    判断是否是调试模式

    extension UIApplication {
    
        var isBeingDebugged: Bool {
            // Initialize all the fields so that,
            // if sysctl fails for some bizarre reason, we get a predictable result.
            var info = kinfo_proc()
            // Initialize mib, which tells sysctl the info we want,
            // in this case we're looking for info about a specific process ID.
            var mib = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
            // Call sysctl.
            var size = MemoryLayout.stride(ofValue: info)
            let junk = sysctl(&mib, u_int(mib.count), &info, &size, nil, 0)
            assert(junk == 0, "sysctl failed")
            // We're being debugged if the P_TRACED flag is set.
            return (info.kp_proc.p_flag & P_TRACED) != 0
        }
    
    }
    
    

    判断是否越狱

    import Foundation
    
    var isJailbroken: Bool {
        return jailbreakFileExists
            || sandboxBreached
            || evidenceOfSymbolLinking
    }
    
    private var evidenceOfSymbolLinking: Bool {
        var s = stat()
        guard lstat("/Applications", &s) == 0 else { return false }
        return (s.st_mode & S_IFLNK == S_IFLNK)
    }
    
    private var sandboxBreached: Bool {
        guard (try? " ".write(
            toFile: "/private/jailbreak.txt",
            atomically: true, encoding: .utf8)) == nil else {
                return true
        }
        return false
    }
    
    private var jailbreakFileExists: Bool {
        let jailbreakFilePaths = [
            "/Applications/Cydia.app",
            "/Library/MobileSubstrate/MobileSubstrate.dylib",
            "/bin/bash",
            "/usr/sbin/sshd",
            "/etc/apt",
            "/private/var/lib/apt/"
        ]
        let fileManager = FileManager.default
        return jailbreakFilePaths.contains { path in
            if fileManager.fileExists(atPath: path) {
                return true
            }
            if let file = fopen(path, "r") {
                fclose(file)
                return true
            }
            return false
        }
    }
    
    
    
    
  • 相关阅读:
    [DNN模块] DNNPortalDownload_1_0_9a_PA(C#)汉化版
    我的第一个DNN皮肤
    调试DNN的方法
    DotNetNuke系列文章 Skin 與 Container 設計介紹
    DotNetNuke 語言包的上傳步驟
    pstools使用说明
    Android Prefence 总结
    android 来电自动接听和自动挂断
    Android 颜色选择器(ColorPicker)
    修改文件权限与归属
  • 原文地址:https://www.cnblogs.com/gaox97329498/p/13871134.html
Copyright © 2020-2023  润新知