How to check app running on jailbreak iOS device

Issue #385

From https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalJailbreakDetection.m

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
+ (BOOL)isJailbroken {

#if !(TARGET_IPHONE_SIMULATOR)

FILE *file = fopen("/Applications/Cydia.app", "r");
if (file) {
fclose(file);
return YES;
}
file = fopen("/Library/MobileSubstrate/MobileSubstrate.dylib", "r");
if (file) {
fclose(file);
return YES;
}

file = fopen("/bin/bash", "r");
if (file) {
fclose(file);
return YES;
}
file = fopen("/usr/sbin/sshd", "r");
if (file) {
fclose(file);
return YES;
}
file = fopen("/etc/apt", "r");
if (file) {
fclose(file);
return YES;
}
file = fopen("/usr/bin/ssh", "r");
if (file) {
fclose(file);
return YES;
}

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:@"/Applications/Cydia.app"])
return YES;
else if ([fileManager fileExistsAtPath:@"/Library/MobileSubstrate/MobileSubstrate.dylib"])
return YES;
else if ([fileManager fileExistsAtPath:@"/bin/bash"])
return YES;
else if ([fileManager fileExistsAtPath:@"/usr/sbin/sshd"])
return YES;
else if ([fileManager fileExistsAtPath:@"/etc/apt"])
return YES;
else if ([fileManager fileExistsAtPath:@"/usr/bin/ssh"])
return YES;

// Omit logic below since they show warnings in the device log on iOS 9 devices.
if (NSFoundationVersionNumber > 1144.17) // NSFoundationVersionNumber_iOS_8_4
return NO;

// Check if the app can access outside of its sandbox
NSError *error = nil;
NSString *string = @".";
[string writeToFile:@"/private/jailbreak.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!error)
return YES;
else
[fileManager removeItemAtPath:@"/private/jailbreak.txt" error:nil];

// Check if the app can open a Cydia's URL scheme
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://package/com.example.package"]])
return YES;

#endif

return NO;
}

Comments