iOS开发经验与技巧iOS Developer计算机技术一锅炖

备用:判断iOS设备是否越狱代码

2016-06-07  本文已影响433人  1b3bd36d9d21

越狱后会自动安装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;    
}
- (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;    
} 
#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;    
} 
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;    
}
上一篇下一篇

猜你喜欢

热点阅读