-
Notifications
You must be signed in to change notification settings - Fork 2
/
UIDevice+JailbrokenDevice.swift
124 lines (110 loc) · 4.41 KB
/
UIDevice+JailbrokenDevice.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/// This extension helps in adding certain ways to detect jailbroken devices
extension UIDevice {
static let isSimulator: Bool = {
var isSim = false
#if targetEnvironment(simulator)
isSim = true
#endif
return isSim
}()
/// Checks if device is jailbroken or not
var isJailBroken: Bool {
get {
if UIDevice.isSimulator { return false }
if UIDevice.isAppContainUnAuthorizedApps() { return true }
if UIDevice.isAppContainUnAuthorizedFiles() { return true }
if UIDevice.isAppCanOpenUnAuthorizedURL() { return true }
return UIDevice.isAppCanEditSystemFiles()
}
}
/// List of unauthorized apps path
static var unAuthorizedApps: [String] {
let appsList = ["/Applications/Cydia.app",
"/Applications/FakeCarrier.app",
"/Applications/Icy.app",
"/Applications/MxTube.app",
"/Applications/IntelliScreen.app",
"/Applications/RockApp.app",
"/Applications/WinterBoard.app",
"/Applications/SBSettings.app",
"/Applications/blackra1n.app"
]
return appsList
}
/// List of unauthorized file paths
static var unAuthorizedFiles: [String] {
let filesList = ["/Library/MobileSubstrate/DynamicLibraries/LiveClock.plist",
"/Library/MobileSubstrate/DynamicLibraries/Veency.plist",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/System/Library/LaunchDaemons/com.ikey.bbot.plist",
"/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist",
"/bin/bash",
"/bin/sh",
"/etc/apt",
"/etc/ssh/sshd_config",
"/private/var/lib/apt",
"/private/var/lib/apt/",
"/private/var/lib/cydia",
"/private/var/mobile/Library/SBSettings/Themes",
"/private/var/stash",
"/private/var/tmp/cydia.log",
"/usr/bin/sshd",
"/usr/libexec/sftp-server",
"/usr/libexec/ssh-keysign",
"/usr/sbin/sshd",
"/var/cache/apt",
"/var/lib/apt",
"/var/lib/cydia"]
return filesList
}
/// Check if the app can open a Cydia's URL scheme
static func isAppCanOpenUnAuthorizedURL() -> Bool {
if let url = URL(string: "cydia://"),
UIApplication.shared.canOpenURL(url) {
return true
}
return false
}
/// Check if the app have permission to write outside of its sandbox
static func isAppCanEditSystemFiles() -> Bool {
let stringToWrite = "Jail break text"
let filePath = "/private/jailbreak.txt"
do {
try stringToWrite.write(toFile: filePath, atomically: true, encoding: .utf8)
return true
} catch {
return false
}
}
/// Check if device able to access system API's
static func isSystemAPIAccessable() -> Bool {
var pid: pid_t = -1
var status: Int32
status = posix_spawn(&pid, "", nil, nil, [], nil)
waitpid(pid, &status, WEXITED)
return pid >= 0
}
/// Function to check if device contains unauthorized apps
static func isAppContainUnAuthorizedApps()-> Bool {
for filePath in unAuthorizedApps {
if FileManager.default.fileExists(atPath: filePath) {
return true
}
}
return false
}
/// Function to check if device contains unauthorized files
static func isAppContainUnAuthorizedFiles() -> Bool {
for filePath in unAuthorizedFiles {
if FileManager.default.fileExists(atPath: filePath) {
return true
}
}
return false
}
}
///Also try adding "Cydia" in LSApplicationQueriesSchemes key of info.plist. Otherwise canOpenURL will always return false.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>cydia</string>
</array>