Perspective icon indicating copy to clipboard operation
Perspective copied to clipboard

判断 iOS 设备是否越狱

Open kingcos opened this issue 6 years ago • 0 comments

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
}
  • 检查 Cydia URL
func isJailed() -> Bool {
    // Check Cydia URL
    return UIApplication.shared.canOpenURL(URL(string: "cydia://package/com.example.package")!)
}

kingcos avatar Sep 04 '18 14:09 kingcos