Skip to content

Instantly share code, notes, and snippets.

@asilturk
Created October 5, 2020 07:13
Show Gist options
  • Save asilturk/ed887e174c4e12a6be10314e5e5dfe46 to your computer and use it in GitHub Desktop.
Save asilturk/ed887e174c4e12a6be10314e5e5dfe46 to your computer and use it in GitHub Desktop.
jailBroken.swift
static var isDeviceJailbroken: Bool {
guard TARGET_IPHONE_SIMULATOR != 1 else { return false }
// Check 1 : existence of files that are common for jailbroken devices
if FileManager.default.fileExists(atPath: "/Applications/Cydia.app")
|| FileManager.default.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib")
|| FileManager.default.fileExists(atPath: "/bin/bash")
|| FileManager.default.fileExists(atPath: "/usr/sbin/sshd")
|| FileManager.default.fileExists(atPath: "/etc/apt")
|| FileManager.default.fileExists(atPath: "/private/var/lib/apt/")
|| UIApplication.shared.canOpenURL(URL(string:"cydia://package/com.example.package")!) {
return true
}
// Check 2 : Reading and writing in system directories (sandbox violation)
let stringToWrite = "Jailbreak Test"
do {
try stringToWrite.write(toFile:"/private/JailbreakTest.txt", atomically:true, encoding:String.Encoding.utf8)
// Device is jailbroken
return true
} catch {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment