JLChen
2021-01-08 20f4a21e2a8e489b5e859a11ad76f77582f6650b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
//  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