Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to detect jailbroken device programmatically? http://swiftiostutorials.com/detect-jailbroken-device-programmatically/
#import <sys/stat.h>
void checkJailbreakSymlinks()
{
NSArray *linksChecks = @[LOO_CRYPT_STR_N("/Applications", 13),
LOO_CRYPT_STR_N("/usr/libexec", 12),
LOO_CRYPT_STR_N("/usr/share", 10),
LOO_CRYPT_STR_N("/Library/Wallpaper", 18),
LOO_CRYPT_STR_N("/usr/include", 12)];
for (NSString *checkPath in linksChecks)
{
checkJailbreakSymLink(checkPath);
}
}
/*
The lstat() function shall be equivalent to stat(),
except when path refers to a symbolic link.
In that case lstat() shall return information about the link,
while stat() shall return information about the file the link references.
*/
void checkJailbreakSymLink(NSString *checkPath)
{
struct stat s;
if (lstat([checkPath UTF8String], &s) == 0)
{
if (S_ISLNK(s.st_mode) == 1)
{
foundJailbrokenDevice();
}
}
}
void checkJailbreakFiles()
{
NSArray *fileChecks = @[LOO_CRYPT_STR_N("/bin/bash", 9),
LOO_CRYPT_STR_N("/etc/apt", 8),
LOO_CRYPT_STR_N("/usr/sbin/sshd", 14),
LOO_CRYPT_STR_N("/Library/MobileSubstrate/MobileSubstrate.dylib", 46),
LOO_CRYPT_STR_N("/Applications/Cydia.app", 23),
LOO_CRYPT_STR_N("/bin/sh", 7),
LOO_CRYPT_STR_N("/var/cache/apt", 14),
LOO_CRYPT_STR_N("/var/tmp/cydia.log", 18)];
for (NSString *checkPath in fileChecks)
{
checkJailbreakFile(checkPath);
}
}
void checkJailbreakFile(NSString *checkPath)
{
struct stat s;
if (stat([checkPath UTF8String], &s) == 0)
{
foundJailbrokenDevice();
}
}
void checkReadWritePermissions()
{
if([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:LOO_CRYPT_STR_N("cydia://package/com.com.com", 27)]])
{
foundJailbrokenDevice();
}
NSError *error;
NSString *stringToBeWritten = @"0";
[stringToBeWritten writeToFile:LOO_CRYPT_STR_N("/private/jailbreak.test", 23)
atomically:YES
encoding:NSUTF8StringEncoding error:&error];
if (error == nil)
{
foundJailbrokenDevice();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment