iOS 判断手机是否越狱

释放双眼,带上耳机,听听看~!

1.通过越狱后增加的越狱文件判断

通常情况下,手机越狱后会增加以下文件
/Applications/Cydia.app
/Library/MobileSubstrate/MobileSubstrate.dylib
/bin/bash
/usr/sbin/sshd
/etc/apt

判断这些文件是否存在,让文件添加到数组中,遍历数组,如果存在任何一个文件,就认为是越狱了

NSArray *jailbreak_tool_paths = @[
@"/Applications/Cydia.app",
@"/Library/MobileSubstrate/MobileSubstrate.dylib",
@"/bin/bash",
@"/usr/sbin/sshd",
@"/etc/apt"
];
- (BOOL)isJailBreak {
for (int i=0; i<jailbreak_tool_paths.count; i++) {
if ([[NSFileManager defaultManager] fileExistsAtPath:jailbreak_tool_paths[i]]) {
NSLog(@"The device is jail broken!");
return YES;
}
}
NSLog(@"The device is NOT jail broken!");
return NO;
}

2.是否能打开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;
}

3.越狱后的手机是可以获取到手机内安装的所有应用程序的,如果可以获取到就说明越狱了

- (BOOL)isJailBreak {
if ([[NSFileManager defaultManager] fileExistsAtPath:@"User/Applications/"]) {
NSLog(@"The device is jail broken!");
NSArray *appList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"User/Applications/" error:nil];
NSLog(@"appList = %@", appList);
return YES;
}
NSLog(@"The device is NOT jail broken!");
return NO;
}

4.使用C语言的函数来判断,使用star方法判断cydia是否存在

int checkInject() {
int ret;
Dl_info dylib_info;
int (*func_stat)(const char*, struct stat*) = stat;
char *dylib_name = "/usr/lib/system/libsystem_kernel.dylib";
if ((ret = dladdr(func_stat, &dylib_info)) && strncmp(dylib_info.dli_fname, dylib_name, strlen(dylib_name))) {
return 0;
}
return 1;
}
int checkCydia() {
struct stat stat_info;
if (!checkInject()) {
if (0 == stat("/Applications/Cydia.app", &stat_info)) {
return 1;
}
} else {
return 1;
}
return 0;
}

5.根据读取的环境变量是否有值判断
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;
}

真正使用的时候,为了保证判断的准确性,可以5中方法结合起来判断,只要有一个方法返回yes,就认为是越狱。

人已赞赏
iOS文章

iOS PCH文件的使用方法

2020-3-29 19:04:36

iOS文章

swift for 循环遍历数组与字典

2020-3-29 20:18:01

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索