kingcos / Perspective

📝 Write something with perspectives.
https://kingcos.me
185 stars 15 forks source link

判断 iOS 设备是否越狱 #53

Open kingcos opened 6 years ago

kingcos commented 6 years ago
Platform Device Status
iOS 9.0.1 iPhone 5s Jailbroken
iOS 12 beta iPhone 7 Not Jailbroken

Solution

func isJailed() -> Bool {
    // Check env vars
    return (getenv("DYLD_INSERT_LIBRARIES") != nil)
}
func isJailed() -> Bool {
    // Check files
    let paths = [
        "/Applications/Cydia.app",
        "/Library/MobileSubstrate/MobileSubstrate.dylib",
        "/var/lib/cydia",
        "/var/lib/apt",
        "/var/cache/apt",
        "/etc/apt",
        "/bin/bash",
        "/bin/sh",
        "/usr/sbin/sshd",
        "/usr/libexec/ssh-keysig", // iOS 9.0.1 Jailbroken device may not have this, either
        "/etc/ssh/sshd_config",
        "/private/var/lib/apt/",
    ]

    for path in paths {
        return FileManager.default.fileExists(atPath: path)
    }

    return false
}
func isJailed() -> Bool {
    // Check Cydia URL
    return UIApplication.shared.canOpenURL(URL(string: "cydia://package/com.example.package")!)
}