越狱后会自动安装cydia,所以我们 可以从这方面入手;也可以借助权限问题,去读取应用的列表;还可以去读环境变量,不越狱的机器应该是读取不到任何内容的。
下面我们一个一个方法来讲:
- 判定常见的越狱文件
/Applications/Cydia.app
/Library/MobileSubstrate/MobileSubstrate.dylib
/bin/bash
/usr/sbin/sshd
/etc/apt
这个表可以尽可能的列出来,然后判定是否存在,只要有存在的就可以认为机器是越狱了。
#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
const char* jailbreak_tool_pathes[] = {
"/Applications/Cydia.app",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/bin/bash",
"/usr/sbin/sshd",
"/etc/apt"
};
- (BOOL)isJailBreak
{
for (int i=0; i<ARRAY_SIZE(jailbreak_tool_pathes); i++) {
if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:jailbreak_tool_pathes[i]]]) {
NSLog(@"The device is jail broken!");
return YES;
}
}
NSLog(@"The device is NOT jail broken!");
return NO;
}
- 判断cydia的URL scheme,URL scheme是可以用来在应用中呼出另一个应用,是一个资源的路径,这个方法也就是在判定是否存在cydia这个应用。
- (BOOL)isJailBreak
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]]) {
NSLog(@"The device is jail broken!");
return YES;
}
NSLog(@"The device is NOT jail broken!");
return NO;
}
- 读取系统所有应用的名称,这个是利用不越狱的机器没有这个权限来判定的。
#define USER_APP_PATH @"/User/Applications/"
- (BOOL)isJailBreak
{
if ([[NSFileManager defaultManager] fileExistsAtPath:USER_APP_PATH]) {
NSLog(@"The device is jail broken!");
NSArray *applist = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:USER_APP_PATH error:nil];
NSLog(@"applist = %@", applist);
return YES;
}
NSLog(@"The device is NOT jail broken!");
return NO;
}
- 使用stat方法来判定cydia是否存在
这个方法本身思路还是通过判定cydia应用,但方法是用的stat函数,同时会判定是否有注入动态库。
#define CYDIA_APP_PATH "/Applications/Cydia.app"
int checkInject()
{
int ret;
Dl_info dylib_info;
int (*func_stat)(const char*, struct stat*) = stat;
if ((ret = dladdr(func_stat, &dylib_info)) && strncmp(dylib_info.dli_fname, dylib_name, strlen(dylib_name))) {
return 0;
}
return 1;
}
int checkCydia()
{
// first ,check whether library is inject
struct stat stat_info;
if (!checkInject()) {
if (0 == stat(CYDIA_APP_PATH, &stat_info)) {
return 1;
}
} else {
return 1;
}
return 0;
}
- (BOOL)isJailBreak
{
if (checkCydia()) {
NSLog(@"The device is jail broken!");
return YES;
}
NSLog(@"The device is NOT jail broken!");
return NO;
}
- 读取环境变量
这个DYLD_INSERT_LIBRARIES环境变量,在非越狱的机器上应该是空,越狱的机器上基本都会有Library/MobileSubstrate/MobileSubstrate.dylib
char* printEnv(void)
{
charchar *env = getenv("DYLD_INSERT_LIBRARIES");
NSLog(@"%s", env);
return env;
}
- (BOOL)isJailBreak
{
if (printEnv()) {
NSLog(@"The device is jail broken!");
return YES;
}
NSLog(@"The device is NOT jail broken!");
return NO;
}
网友评论