美文网首页iOS
iOS越狱判断

iOS越狱判断

作者: A訫飛Flyme | 来源:发表于2019-01-10 15:03 被阅读68次
    HS

    以下5种方法均可以判断设置是否越狱,但为了保证判断的准确性,通常会多种方法联合使用。判断越狱的基本思想是根据越狱前和越狱后的一些权限改变或者增加的文件来判断的。

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

    根据使用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;
    }
    

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

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

    END

    相关文章

      网友评论

        本文标题:iOS越狱判断

        本文链接:https://www.haomeiwen.com/subject/psdarqtx.html