+(BOOL)isJailbreak{
if (TARGET_IPHONE_SIMULATOR) {
return NO;
}else{
//越狱检查
//能否访问沙盒外面的路径
if ([[NSFileManager defaultManager]fileExistsAtPath:@"User/Applications/"]) {
return YES;
}
if ([[[UIDevice currentDevice] systemVersion] floatValue]<9.0) {
//CanOpenURL检查
@try {
#if !(defined(__has_feature) && __has_feature(attribute_availability_app_extension))
NSURL *FakeURL = [NSURL URLWithString:@"cydia://package/com.fake.package"];
if ([[UIApplication sharedApplication] canOpenURL:FakeURL])
return YES;
#endif
}
@catch (NSException *exception) {
}
}
//Cydia应用检查
@try {
NSString *appPath =@"/Applications/Cydia.app";
FILE *vf = fopen([appPath cStringUsingEncoding:NSASCIIStringEncoding],"r");
if (vf != NULL)
return YES;
}
@catch (NSException *exception) {
}
//fork函数检查
if (fork()>=0) {
return YES;
}
NSInteger motzart =0;
//无法访问文件检查
@try {
NSArray *files =@[
@"/Applications/RockApp.app",
@"/Applications/Icy.app",
@"/usr/sbin/sshd",
@"/usr/bin/sshd",
@"/usr/libexec/sftp-server",
@"/Applications/WinterBoard.app",
@"/Applications/SBSettings.app",
@"/Applications/MxTube.app",
@"/Applications/IntelliScreen.app",
@"/Library/MobileSubstrate/DynamicLibraries/Veency.plist",
@"/Library/MobileSubstrate/DynamicLibraries/LiveClock.plist",
@"/Library/MobileSubstrate/DynamicLibraries/xCon.plist",
@"/private/var/lib/apt",@"/private/var/stash",
@"/System/Library/LaunchDaemons/com.ikey.bbot.plist",
@"/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist",
@"/private/var/tmp/cydia.log",@"/private/var/lib/cydia",
@"/etc/clutch.conf", @"/var/cache/clutch.plist",
@"/etc/clutch_cracked.plist",
@"/var/cache/clutch_cracked.plist",
@"/var/lib/clutch/overdrive.dylib",
@"/var/root/Documents/Cracked/"];
for (NSString *fileName in files) {
FILE *vf = fopen([fileName cStringUsingEncoding:NSASCIIStringEncoding],"r");
if (vf != NULL){
motzart +=2;
break;
}
}
}
@catch (NSException *exception) {
}
//plist文件检查
@try {
NSString *exePath = [[NSBundle mainBundle] executablePath];
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
FILE *vf = fopen([exePath cStringUsingEncoding:NSASCIIStringEncoding],"r");
if (vf == NULL || infoDict == nil || infoDict.count <= 0) {
motzart +=2;
}
}
@catch (NSException *exception) {
}
if ([[[UIDevice currentDevice] systemVersion] floatValue]<9.0) {
//进程检查
@try {
NSArray *processes = [self runningProcesses];
for (NSDictionary * dict in processes) {
NSString *process = [dict objectForKey:@"ProcessName"];
if ([process isEqualToString:@"MobileCydia"]||[process isEqualToString:@"Cydia"]||[process isEqualToString:@"afpd"]) {
motzart +=2;
break;
}
}
}
@catch (NSException *exception) {
}
//符号链接检查
@try {
struct stat s;
if (lstat("/Applications", &s) != 0 && (s.st_mode & S_IFLNK)) {
motzart += 2;
}
}
@catch (NSException *exception) {
}
}
return motzart >= 3;
}
}
+ (NSArray *)runningProcesses {
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
size_t miblen = 4;
size_t size = 0;
int st;
struct kinfo_proc * process = NULL;
struct kinfo_proc * newprocess = NULL;
do {
size += (size / 10);
newprocess = realloc(process, size);
if (!newprocess){
if (process){
free(process);
}
return nil;
}
process = newprocess;
st = sysctl(mib, (int)miblen, process, &size, NULL, 0);
} while (st == -1 && errno == ENOMEM);
if (st == 0){
if (size % sizeof(struct kinfo_proc) == 0){
int nprocess = (int)(size / sizeof(struct kinfo_proc));
if (nprocess){
NSMutableArray * array = [[NSMutableArray alloc] init];
for (int i = nprocess - 1; i >= 0; i--){
NSString * processID =[[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];
NSString * processName =[[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];
NSString *processPriority =[[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_priority];
NSDate *processStartDate =[NSDate dateWithTimeIntervalSince1970:process[i].kp_proc.p_un.__p_starttime.tv_sec];
NSDictionary *dict =@{
@"ProcessID":processID,
@"ProcessPriority":processPriority,
@"ProcessName":processName,
@"ProcessStartDate":processStartDate};
[array addObject:dict];
}
free(process);
return array;
}
}
}
free(process);
return nil;
}
判断iPhone手机是否越狱
最新推荐文章于 2024-09-10 13:46:13 发布