iOS 判断是否越狱

OC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    BOOL status1 = [self isJailBreak1];
    BOOL status2 = [self isJailBreak2];
    BOOL status3 = [self isJailBreak3];
    
    if (status1 || status2 || status3) {
        NSLog(@"越狱了");
    }else{
        NSLog(@"未越狱了");
    }
    
    
}

///判断条件1
-(BOOL)isJailBreak1{
    //通常情况下,手机越狱后会增加以下文件
    //模拟器也会有如下文件
    NSArray *jailbreak_tool_paths = @[
        @"/Applications/Cydia.app",
        @"/Library/MobileSubstrate/MobileSubstrate.dylib",
        @"/bin/bash",
        @"/usr/sbin/sshd",
        @"/etc/apt"
    ];
    for (int i=0; i

Swift

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        let status1 = isJailBreak1()
        let status2 = isJailBreak2()
        let status3 = isJailBreak3()
        
        if (status1 || status2 || status3) {
            print("越狱了");
        }else{
            print("未越狱了");
        }
    }
    
    func isJailBreak1() -> Bool {
        //通常情况下,手机越狱后会增加以下文件
        //模拟器也会有如下文件
        let jailbreak_tool_paths = [
            "/Applications/Cydia.app",
            "/Library/MobileSubstrate/MobileSubstrate.dylib",
            "/bin/bash",
            "/usr/sbin/sshd",
            "/etc/apt"
        ]
        for item in jailbreak_tool_paths {
            if FileManager.default.fileExists(atPath: item) {
                print("The device is jail broken!1")
                return true
            }
        }
        print("The device is NOT jail broken!1")
        return false
    }
    

    func isJailBreak2() -> Bool {
        //是否能打开cydia这个协议头
        if UIApplication.shared.canOpenURL(URL.init(string: "cydia://")!) {
            print("The device is jail broken!2")
            return true
        }
        
        print("The device is NOT jail broken!2")
        return false
    }
    
    func isJailBreak3() -> Bool {
        //越狱后的手机是可以获取到手机内安装的所有应用程序的,如果可以获取到就说明越狱了
        if FileManager.default.fileExists(atPath: "User/Applications/") {
            print("The device is jail broken!3")
            let appList = try! FileManager.default.contentsOfDirectory(atPath: "User/Applications/")
            print("appList = \(appList)")
            return true
        }
        print("The device is NOT jail broken!3")
        return false
        
    }

你可能感兴趣的:(iOS 判断是否越狱)