iOS判断手机是否越狱

iOS判断手机是否越狱_第1张图片
jailbroken.jpg

直接上正题!!!判断手机越狱的几种方式:

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

static const char* jailbreak_apps[] =
{
    "/Applications/Cydia.app",
    "/Applications/limera1n.app",
    "/Applications/greenpois0n.app",
    "/Applications/blackra1n.app",
    "/Applications/blacksn0w.app",
    "/Applications/redsn0w.app",
    "/Applications/Absinthe.app",
    "/Library/MobileSubstrate/MobileSubstrate.dylib",
    "/bin/bash",
    "/usr/sbin/sshd",
    "/etc/apt",
    "/private/var/lib/apt/",
    NULL,
};
- (BOOL)isJailBreak {
    for (int i = 0; i < jailbreak_tool_paths.count; i++) {
    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:jailbreak_apps[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.根据使用stat方法来判断cydia是否存在来判断
这个方法的思路还是通过判定cydia应用,但方法是使用stat函数,同时会判断是否有注入动态库。

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;
}

以上就是判断手机越狱的方法,但是为了保证判断的准确性,通常会多种方法联合使用。

越狱有风险,越狱需谨慎!!!

参考文章 iOS 判断手机是否越狱

欢迎关注公众号交流!


iOS判断手机是否越狱_第2张图片
十二公子

你可能感兴趣的:(iOS判断手机是否越狱)