Last active
October 1, 2019 16:07
-
-
Save astrokin/3d51a571cabc9db90afc08f96bb3f7bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Security { | |
static func isJailbroken() -> Bool { | |
guard let cydiaUrlScheme = NSURL(string: "cydia://package/com.example.package") else { return false } | |
if UIApplication.shared.canOpenURL(cydiaUrlScheme as URL) { | |
return true | |
} | |
#if arch(i386) || arch(x86_64) | |
// This is a Simulator not an idevice | |
return false | |
#endif | |
for path in ["/Applications/Cydia.app", | |
"/Library/MobileSubstrate/MobileSubstrate.dylib", | |
"/bin/bash", | |
"/usr/sbin/sshd", | |
"/etc/apt", | |
"/usr/bin/ssh", | |
"/private/var/lib/apt"] { | |
if FileManager.default.fileExists(atPath: path) { | |
return true | |
} | |
if canOpen(path: path) { | |
return true | |
} | |
} | |
let path = "/private/" + NSUUID().uuidString | |
do { | |
try "anyString".write(toFile: path, atomically: true, encoding: String.Encoding.utf8) | |
try fileManager.removeItem(atPath: path) | |
return true | |
} catch { | |
return false | |
} | |
} | |
private static func canOpen(path: String) -> Bool { | |
let file = fopen(path, "r") | |
guard file != nil else { return false } | |
fclose(file) | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment