├── JailBreak.swift └── README.md /JailBreak.swift: -------------------------------------------------------------------------------- 1 | static func isJailbroken() -> Bool { 2 | 3 | guard let cydiaUrlScheme = NSURL(string: "cydia://package/com.example.package") else { return false } 4 | if UIApplication.shared.canOpenURL(cydiaUrlScheme as URL) { 5 | return true 6 | } 7 | 8 | #if arch(i386) || arch(x86_64) 9 | // This is a Simulator not an idevice 10 | return false 11 | #endif 12 | 13 | let fileManager = FileManager.default 14 | if fileManager.fileExists(atPath: "/Applications/Cydia.app") || 15 | fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") || 16 | fileManager.fileExists(atPath: "/bin/bash") || 17 | fileManager.fileExists(atPath: "/usr/sbin/sshd") || 18 | fileManager.fileExists(atPath: "/etc/apt") || 19 | fileManager.fileExists(atPath: "/usr/bin/ssh") || 20 | fileManager.fileExists(atPath: "/private/var/lib/apt") { 21 | return true 22 | } 23 | 24 | if canOpen(path: "/Applications/Cydia.app") || 25 | canOpen(path: "/Library/MobileSubstrate/MobileSubstrate.dylib") || 26 | canOpen(path: "/bin/bash") || 27 | canOpen(path: "/usr/sbin/sshd") || 28 | canOpen(path: "/etc/apt") || 29 | canOpen(path: "/usr/bin/ssh") { 30 | return true 31 | } 32 | 33 | let path = "/private/" + NSUUID().uuidString 34 | do { 35 | try "anyString".write(toFile: path, atomically: true, encoding: String.Encoding.utf8) 36 | try fileManager.removeItem(atPath: path) 37 | return true 38 | } catch { 39 | return false 40 | } 41 | } 42 | 43 | static func canOpen(path: String) -> Bool { 44 | let file = fopen(path, "r") 45 | guard file != nil else { return false } 46 | fclose(file) 47 | return true 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JailBreak-Detection 2 | Swift 4: Function to handle jailbreak detection on iOS 3 | --------------------------------------------------------------------------------