Skip to content

Instantly share code, notes, and snippets.

@astrokin
Last active October 1, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrokin/3d51a571cabc9db90afc08f96bb3f7bd to your computer and use it in GitHub Desktop.
Save astrokin/3d51a571cabc9db90afc08f96bb3f7bd to your computer and use it in GitHub Desktop.
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