//
|
// JLJailBreak.m
|
// JLJailBreak
|
//
|
// Created by 陈嘉乐 on 2020/10/26.
|
// Copyright © 2020 陈嘉乐. All rights reserved.
|
//
|
|
#import "JLJailBreak.h"
|
#import "stdlib.h"
|
|
@implementation JLJailBreak
|
|
|
/**
|
* 判断设备是否越狱
|
*/
|
+ (BOOL)isJailBreak
|
{
|
return [JLJailBreak isHasReadAppFileAuthority] || [JLJailBreak isHasJailBreakAppOrFile] || [JLJailBreak isHasDyldInsertLibraries];
|
}
|
|
/**
|
* 第一种:判断是否有获取其它App权限
|
*/
|
+ (BOOL) isHasReadAppFileAuthority
|
{
|
if ([[NSFileManager defaultManager] fileExistsAtPath:@"User/Applications/"]) {
|
return YES;
|
}else{
|
return NO;
|
}
|
}
|
|
/**
|
* 第二种:判断是否存在apt和Cydia.app或者越狱文件
|
*/
|
+(BOOL) isHasJailBreakAppOrFile{
|
BOOL isJailBreak = NO;
|
NSString *cydiaPath = @"/Applications/Cydia.app";
|
NSString *aptPath = @"/private/var/lib/apt/";
|
if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath]||[[NSFileManager defaultManager] fileExistsAtPath:aptPath]) {
|
isJailBreak = YES;
|
}else{
|
NSFileManager *fileManager=[NSFileManager defaultManager];
|
NSArray *pathArray = @[@"/etc/ssh/sshd_config",
|
@"/usr/libexec/ssh-keysign",
|
@"/usr/sbin/sshd",
|
@"/usr/sbin/sshd",
|
@"/bin/sh",
|
@"/bin/bash",
|
@"/etc/apt",
|
@"/Application/Cydia.app/",
|
@"/Library/MobileSubstrate/MobileSubstrate.dylib"
|
];
|
for (NSString *path in pathArray) {
|
isJailBreak = [fileManager fileExistsAtPath:path];
|
// 如果存在这些目录,就是已经越狱
|
if (isJailBreak) {
|
break;
|
}
|
}
|
}
|
return isJailBreak;
|
}
|
|
|
|
/**
|
* 第三种:判断环境变量DYLD_INSERT_LIBRARIES
|
*/
|
+ (BOOL) isHasDyldInsertLibraries
|
{
|
char *env = getenv("DYLD_INSERT_LIBRARIES");
|
|
if (env != NULL) {
|
return YES;
|
}else{
|
return NO;
|
}
|
}
|
|
|
//+ (void)exitApplicationWhenJailBreak{
|
//
|
// if ([JLJailBreak isJailBreak]) {
|
//
|
// AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
//
|
// UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:@"本应用暂不支持在越狱设备上运行,请使用未越狱设备进行重新安装" preferredStyle:UIAlertControllerStyleAlert];
|
// UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
// [JLJailBreak exitWithAnimation];
|
// }];
|
// [alertVc addAction:sureAction];
|
//
|
// [app.window.rootViewController presentViewController:alertVc animated:YES completion:nil];
|
//
|
// }
|
//
|
//}
|
//
|
//
|
//+ (void)exitWithAnimation{
|
//
|
// AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
// UIWindow *window = app.window;
|
//
|
// [UIView animateWithDuration:.35 animations:^{
|
// window.alpha = 0;
|
// window.frame = CGRectMake(window.frame.size.width/2, window.frame.size.height/2, 0, 0);
|
// } completion:^(BOOL finished) {
|
// exit(0);
|
// }];
|
//}
|
|
@end
|