Skip to content

Instantly share code, notes, and snippets.

@imranansari
Created January 26, 2015 19:11
Show Gist options
  • Select an option

  • Save imranansari/70c7ed23efa418f2e8ea to your computer and use it in GitHub Desktop.

Select an option

Save imranansari/70c7ed23efa418f2e8ea to your computer and use it in GitHub Desktop.
+(BOOL)isJailbroken{
#if !(TARGET_IPHONE_SIMULATOR)
if ([[NSFileManager defaultManager] fileExistsAtPath:@"/Applications/Cydia.app"]){
return YES;
}else if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/MobileSubstrate/MobileSubstrate.dylib"]){
return YES;
}else if([[NSFileManager defaultManager] fileExistsAtPath:@"/bin/bash"]){
return YES;
}else if([[NSFileManager defaultManager] fileExistsAtPath:@"/usr/sbin/sshd"]){
return YES;
}else if([[NSFileManager defaultManager] fileExistsAtPath:@"/etc/apt"]){
return YES;
}else if([[NSFileManager defaultManager] fileExistsAtPath:@"/private/var/lib/apt/"]){
return YES;
}
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://package/com.example.package"]]){
return YES;
}
FILE *f = fopen("/bin/bash", "r");
if (f != NULL) {
fclose(f);
return YES;
}
fclose(f);
f = fopen("/Applications/Cydia.app", "r");
if (f != NULL) {
fclose(f);
return YES;
}
fclose(f);
f = fopen("/Library/MobileSubstrate/MobileSubstrate.dylib", "r");
if (f != NULL) {
fclose(f);
return YES;
}
fclose(f);
f = fopen("/usr/sbin/sshd", "r");
if (f != NULL) {
fclose(f);
return YES;
}
fclose(f);
f = fopen("/etc/apt", "r");
if (f != NULL) {
fclose(f);
return YES;
}
fclose(f);
NSError *error;
NSString *stringToBeWritten = @"This is a test.";
[stringToBeWritten writeToFile:@"/private/jailbreak.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
[[NSFileManager defaultManager] removeItemAtPath:@"/private/jailbreak.txt" error:nil];
if(error==nil){
return YES;
}
#endif
//All checks have failed. Most probably, the device is not jailbroken
return NO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment