Last active
April 4, 2016 13:27
-
-
Save xslim/5c48b6adcc4da9290427 to your computer and use it in GitHub Desktop.
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
+ (BOOL)checkJailbreak { | |
//#if DEBUG | |
// return NO; | |
//#endif | |
BOOL debug = YES; | |
if (debug) NSLog(@"setup started"); | |
int is_jailbroken = 0; | |
int result = fork(); | |
if (!result) { | |
if (debug) NSLog(@"forking"); | |
exit(0); | |
/* Perform the fork */ | |
/* The child should exit, if it spawned */ | |
} | |
if (result >= 0) //sandbox_is_compromised | |
is_jailbroken ++; | |
if (debug) NSLog(@"after fork test, current value of is_jailbroken = %d", is_jailbroken); | |
//TODO execve() | |
#if __has_include(<UIKit/UIKit.h>) | |
// Throws on iOS 9.0+ | |
//NSURL* url = [NSURL URLWithString:@"cydia://package/com.example.package"]; | |
//if ([[UIApplication sharedApplication] canOpenURL:url]) is_jailbroken++; | |
#endif | |
//perhaps try with fopen() as well. | |
struct stat filestats; | |
is_jailbroken += stat("/Applications/Cydia.app", &filestats) == 0; | |
is_jailbroken += stat("/Library/MobileSubstrate/MobileSubstrate.dylib", &filestats) == 0; | |
//is_jailbroken += stat("/var/cache/apt", &filestats) == 0; // Is 1 if was Jailbroken before | |
//is_jailbroken += stat("/var/lib/apt", &filestats) == 0; // Is 1 if was Jailbroken before | |
//is_jailbroken += stat("/var/lib/cydia", &filestats) == 0; // Is 1 if was Jailbroken before | |
is_jailbroken += stat("/var/log/syslog", &filestats) == 0; | |
is_jailbroken += stat("/var/tmp/cydia.log", &filestats) == 0; | |
is_jailbroken += stat("/bin/bash", &filestats) == 0; | |
is_jailbroken += stat("/bin/sh", &filestats) == 0; | |
is_jailbroken += stat("/usr/sbin/sshd", &filestats) == 0; | |
is_jailbroken += stat("/usr/libexec/ssh-keysign", &filestats) == 0; | |
is_jailbroken += stat("/etc/ssh/sshd_config", &filestats) == 0; | |
is_jailbroken += stat("/etc/apt", &filestats) == 0; | |
if (debug) NSLog(@"after file path test, current value of is_jailbroken = %d", is_jailbroken); | |
/* Skip this test, it fails on iOS7 beta | |
stat("/etc/fstab", &filestats); | |
if ( debug ) NSLog(@"size of fstab file is %lld", filestats.st_size); //SIM 403216, IOS5 80, JB_IOS5.1.1 174, IOS6.0.1 80 | |
if( filestats.st_size > 80 ) is_jailbroken ++; | |
if (debug) NSLog(@"after fstab test, current value of is_jailbroken = %d", is_jailbroken); | |
*/ | |
is_jailbroken += symLinkTest("/Applications"); | |
is_jailbroken += symLinkTest("/Library/Ringtones"); | |
is_jailbroken += symLinkTest("/Library/Wallpaper"); | |
is_jailbroken += symLinkTest("/usr/arm-apple-darwin9"); | |
is_jailbroken += symLinkTest("/usr/include"); | |
is_jailbroken += symLinkTest("/usr/libexec"); | |
is_jailbroken += symLinkTest("/usr/share"); | |
if (debug) NSLog(@"after symlink test, current value of is_jailbroken = %d", is_jailbroken); | |
is_jailbroken += dynLibTest(); | |
if (debug) NSLog(@"after dynlib exec test, current value of is_jailbroken = %d", is_jailbroken); | |
return (is_jailbroken > 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment