Created
January 11, 2017 09:29
-
-
Save torinnguyen/15ec444bae755cc1eaccc8233492761a to your computer and use it in GitHub Desktop.
iOS jailbreak detection
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
/* return true if phone is jail broken */ | |
+ (BOOL) checkJailbreak | |
{ | |
#if (TARGET_OS_SIMULATOR) | |
return NO; | |
#endif | |
/* checking fork */ | |
pid_t child = fork(); | |
if (child > 0) { | |
return YES; | |
} | |
/* checking for existence of files */ | |
NSArray *fileNames = | |
@[ | |
@"/Applications/Cydia.app", | |
@"/Library/MobileSubstrate/MobileSubstrate.dylib", | |
@"/var/cache/apt", | |
@"/var/lib/apt", | |
@"/var/lib/cydia", | |
@"/var/log/syslog", | |
@"/var/tmp/cydia.log", | |
@"/bin/bash", | |
@"/bin/sh", | |
@"/usr/sbin/sshd", | |
@"/usr/libexec/ssh-keysign", | |
@"/etc/ssh/sshd_config", | |
@"/etc/apt" | |
]; | |
for (NSString *fileName in fileNames) { | |
if ([[NSFileManager defaultManager] fileExistsAtPath:fileName]) | |
{ | |
NSLog(@"File exists: %@", fileName); | |
return YES; | |
} | |
} | |
/* checking for ability to write into /private */ | |
NSError *error; | |
NSString *testWriteText = @"Jailbreak test"; | |
NSString *testWritePath = @"/private/jailbreaktest.txt"; | |
[testWriteText writeToFile:testWritePath atomically:YES encoding:NSUTF8StringEncoding error:&error]; | |
if (error == nil) | |
{ | |
[[NSFileManager defaultManager] removeItemAtPath:testWritePath error:nil]; | |
return YES; | |
} | |
else | |
{ | |
[[NSFileManager defaultManager] removeItemAtPath:testWritePath error:nil]; | |
} | |
/* checking for ability to open cydia:// link */ | |
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://package/com.example.package"]]) | |
{ | |
return YES; | |
} | |
return NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment