-
Notifications
You must be signed in to change notification settings - Fork 11
/
RootViewController.mm
388 lines (351 loc) · 15.2 KB
/
RootViewController.mm
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#import "RootViewController.h"
#import "SignedCert.h"
#import "CertUtils.h"
@implementation RootViewController {
UIWindow *window;
UILabel *label1; // Title
UILabel *label2; // by blabla
UILabel *label3; // State (remaining)
UILabel *label4; // AppID
UILabel *label5; // Expiration date
UILabel *label6; // Installation date
UILabel *label7; // TTL
UILabel *footer;
UIView *topSpace;
UIView *bottomSpace;
}
- (instancetype)initWithWindow:(UIWindow *)parent {
self = [super init];
window = parent;
return self;
}
- (NSString *)humanLocalizedDate:(NSDate *)date displayFormat:(NSString *)format {
NSString *toReturn;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:format];
toReturn = [dateFormat stringFromDate:date];
return toReturn;
}
- (void)loadView {
int errCode = 1;
NSFileManager *filemgr;
SignedCert *usingCert;
NSDate *now = [NSDate date];
NSString *defFormat = @"yyyy-MM-dd 'at' HH:mm";
filemgr = [[NSFileManager alloc] init];
[filemgr changeCurrentDirectoryPath:@"/var/MobileDevice/ProvisioningProfiles/"];
NSArray *dirContents = [filemgr contentsOfDirectoryAtPath:[filemgr currentDirectoryPath] error:nil];
NSLog(@"[CertRemainTime] Now browsing %@", [filemgr currentDirectoryPath]);
for (NSString *fullFileName in dirContents) {
if (errCode == 1) errCode = 2;
SignedCert *cert = [[SignedCert alloc] init:[CertUtils provisioningProfileAtPath:fullFileName]];
if ([cert.appId rangeOfString:@"jailbreak"].location != NSNotFound ||
[cert.appId rangeOfString:@"yalu"].location != NSNotFound ||
[cert.appId rangeOfString:@"pangu"].location != NSNotFound ||
([cert.appId rangeOfString:@"mach"].location != NSNotFound && [cert.appId rangeOfString:@"portal"].location != NSNotFound) ||
([cert.appId rangeOfString:@"extra"].location != NSNotFound && [cert.appId rangeOfString:@"recipe"].location != NSNotFound) ||
([cert.appId rangeOfString:@"ph"].location != NSNotFound && [cert.appId rangeOfString:@"nix"].location != NSNotFound) ||
([cert.appId rangeOfString:@"home"].location != NSNotFound && [cert.appId rangeOfString:@"depot"].location != NSNotFound) ||
[cert.appId rangeOfString:@"saigon"].location != NSNotFound ||
[cert.appId rangeOfString:@"g0blin"].location != NSNotFound ||
[cert.appId rangeOfString:@"h3lix"].location != NSNotFound ||
[cert.appId rangeOfString:@"electra"].location != NSNotFound ||
[cert.appId rangeOfString:@"liberios"].location != NSNotFound ||
[cert.appId rangeOfString:@"meridian"].location != NSNotFound ||
[cert.appId rangeOfString:@"unc0ver"].location != NSNotFound ||
[cert.appId rangeOfString:@"tweakbox"].location != NSNotFound ||
[cert.appId rangeOfString:@"ignition"].location != NSNotFound)
{
if (!usingCert || [cert.expireDate compare:usingCert.expireDate] == NSOrderedDescending) {
usingCert = cert;
}
}
}
if (usingCert != NULL) {
errCode = 0;
}
if (errCode < 0 && usingCert.expireDate != NULL) {
errCode = 3;
}
NSLog(@"[CertRemainTime] errCode = %@", [NSString stringWithFormat:@"%i", errCode]);
NSLog(@"[CertRemainTime] defFormat = %@", defFormat);
NSLog(@"[CertRemainTime] appId = %@", usingCert.appId);
NSLog(@"[CertRemainTime] now = %@", now);
NSLog(@"[CertRemainTime] ttlDays = %@", usingCert.ttlDays);
NSLog(@"[CertRemainTime] expireDate = %@", usingCert.expireDate);
NSLog(@"[CertRemainTime] createDate = %@", usingCert.createDate);
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[self view] setBackgroundColor:[UIColor whiteColor]];
/* Label */
NSLog(@"[CertRemainTime] Drawing label 1");
label1 = [[UILabel alloc] init];
label1.font = [UIFont boldSystemFontOfSize: 45.0f];
label1.textColor = [UIColor blackColor];
label1.backgroundColor = [UIColor clearColor];
label1.textAlignment = NSTextAlignmentCenter;
[label1 setText:@"Cert Time"];
[label1 sizeToFit];
label1.translatesAutoresizingMaskIntoConstraints = NO;
[label1 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label1];
NSLog(@"[CertRemainTime] Drawing label 2");
label2 = [[UILabel alloc] init];
label2.font = [UIFont boldSystemFontOfSize: 15.0f];
label2.textColor = [UIColor blackColor];
label2.backgroundColor = [UIColor clearColor];
label2.textAlignment = NSTextAlignmentCenter;
[label2 setText:@"by @lululombard"];
[label2 sizeToFit];
label2.translatesAutoresizingMaskIntoConstraints = NO;
[label2 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label2];
NSLog(@"[CertRemainTime] Drawing label 3");
label3 = [[UILabel alloc] init];
label3.font = [UIFont boldSystemFontOfSize: 20.0f];
label3.textColor = [UIColor blackColor];
label3.backgroundColor = [UIColor clearColor];
label3.textAlignment = NSTextAlignmentCenter;
if (errCode == 1) [label3 setText:@"State : No certificate found"];
else if (errCode == 2) [label3 setText:@"State : No certificate compatible"];
else if (errCode == 3) [label3 setText:@"State : Location error"];
else {
NSTimeInterval secondsBetween;
NSString *state;
NSString *remaining = @"";
if ([usingCert.expireDate compare:now] == NSOrderedDescending) {
secondsBetween = [usingCert.expireDate timeIntervalSinceDate:now];
state = @"Valid for";
}
else {
secondsBetween = [now timeIntervalSinceDate:usingCert.expireDate];
state = @"Expired since";
}
NSLog(@"[CertRemainTime] State = %@", state);
int minutesBetween = secondsBetween / 60;
int days = 0;
int hours = 0;
while (minutesBetween >= 1440) {
minutesBetween -= 1440;
days++;
}
while (minutesBetween >= 60) {
minutesBetween -= 60;
hours++;
}
NSString *daysString = [NSString stringWithFormat:@"%i", days];
NSString *hoursString = [NSString stringWithFormat:@"%i", hours];
NSString *minutesString = [NSString stringWithFormat:@"%i", minutesBetween];
NSLog(@"[CertRemainTime] days = %@", daysString);
NSLog(@"[CertRemainTime] hours = %@", hoursString);
NSLog(@"[CertRemainTime] minutes = %@", minutesString);
if (days == 0 && hours == 0 && minutesBetween == 0) remaining = @"NOW !";
else {
if (days > 0) {
NSLog(@"[CertRemainTime] days > 0 = YES");
remaining = [remaining stringByAppendingString:[daysString stringByAppendingString:(days == 1 ? @" day" : @" days")]];
}
if (days < 10 && hours > 0) {
NSLog(@"[CertRemainTime] days < 10 && hours > 0 = YES");
if (![remaining isEqual:@""]) remaining = [remaining stringByAppendingString:(days == 0 && minutesBetween > 0) ? @", " : @" and "];
remaining = [remaining stringByAppendingString:[hoursString stringByAppendingString:(hours == 1 ? @" hour" : @" hours")]];
}
if (days == 0 && minutesBetween > 0) {
NSLog(@"[CertRemainTime] days == 0 && minutesBetween > 0 = YES");
if (![remaining isEqual:@""]) remaining = [remaining stringByAppendingString:@" and "];
remaining = [remaining stringByAppendingString:[minutesString stringByAppendingString:(minutesBetween == 1 ? @" minute" : @" minutes")]];
}
}
// Fix for TweakBox
if ([usingCert.appId isEqual:@"tweakbox"]) {
NSLog(@"[CertRemainTime] Remaining = %@ - TweakBox detected!", remaining);
[label3 setText:[[[state stringByAppendingString:@" "] stringByAppendingString:remaining] stringByAppendingString:@"\n\nTweakBox profile found!"
"\nDue to the way TweakBox signs"
"\ntheir apps, the name of the tool"
"\ncannot be determined."]];
}
// Fix for Ignition
if ([usingCert.appId isEqual:@"ignition"]) {
NSLog(@"[CertRemainTime] Remaining = %@ - Ignition detected!", remaining);
[label3 setText:[[[state stringByAppendingString:@" "] stringByAppendingString:remaining] stringByAppendingString:@"\n\nIgnition profile found!"
"\nDue to the way Ignition signs"
"\ntheir apps, the name of the tool"
"\ncannot be determined."]];
}
else {
NSLog(@"[CertRemainTime] Remaining = %@", remaining);
[label3 setText:[[state stringByAppendingString:@" "] stringByAppendingString:remaining]];
}
}
[label3 sizeToFit];
label3.translatesAutoresizingMaskIntoConstraints = NO;
label3.numberOfLines = 0;
[label3 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label3];
NSLog(@"[CertRemainTime] Drawing label 4");
label4 = [[UILabel alloc] init];
label4.font = [UIFont boldSystemFontOfSize: 15.0f];
label4.textColor = [UIColor blackColor];
label4.backgroundColor = [UIColor clearColor];
label4.textAlignment = NSTextAlignmentCenter;
if (errCode == 1 || errCode == 2) [label4 setText:@"Possible issues :"];
else if (errCode == 3) [label4 setText:@"Please send a mail with these info :"];
else [label4 setText:[@"Tool detected : " stringByAppendingString:usingCert.appId]];
[label4 sizeToFit];
label4.translatesAutoresizingMaskIntoConstraints = NO;
[label4 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label4];
NSLog(@"[CertRemainTime] Drawing label 5");
label5 = [[UILabel alloc] init];
label5.font = [UIFont boldSystemFontOfSize: 15.0f];
label5.textColor = [UIColor blackColor];
label5.backgroundColor = [UIColor clearColor];
label5.textAlignment = NSTextAlignmentCenter;
NSString *expireDateString = [self humanLocalizedDate:usingCert.expireDate displayFormat:defFormat];
if (errCode == 1 || errCode == 2) [label5 setText:@"- Your cert is expired and was removed"];
else if (errCode == 3) [label5 setText:@"- Language and region set"];
else [label5 setText:[@"Expiration : " stringByAppendingString:expireDateString]];
[label5 sizeToFit];
label5.translatesAutoresizingMaskIntoConstraints = NO;
[label5 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label5];
NSLog(@"[CertRemainTime] Drawing label 6");
label6 = [[UILabel alloc] init];
label6.font = [UIFont boldSystemFontOfSize: 15.0f];
label6.textColor = [UIColor blackColor];
label6.backgroundColor = [UIColor clearColor];
label6.textAlignment = NSTextAlignmentCenter;
NSString *createDateString = [self humanLocalizedDate:usingCert.createDate displayFormat:defFormat];
if (errCode == 1 || errCode == 2) [label6 setText:@"- You didn't use Cydia Impactor"];
else if (errCode == 3) [label6 setText:@"- Hour display setting (12h/24h)"];
else [label6 setText:[@"Creation : " stringByAppendingString:createDateString]];
[label6 sizeToFit];
label6.translatesAutoresizingMaskIntoConstraints = NO;
[label6 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label6];
NSLog(@"[CertRemainTime] Drawing label 7");
label7 = [[UILabel alloc] init];
label7.font = [UIFont boldSystemFontOfSize: 15.0f];
label7.textColor = [UIColor blackColor];
label7.backgroundColor = [UIColor clearColor];
label7.textAlignment = NSTextAlignmentCenter;
if (errCode == 1 || errCode == 2) [label7 setText:@"- Other? [email protected]"];
else if (errCode == 3) [label7 setText:@"- Calendar used (Gregorian or other)"];
else [label7 setText:[@"Certificate duration : " stringByAppendingString:[usingCert.ttlDays stringByAppendingString:@" days"]]];
[label7 sizeToFit];
label7.translatesAutoresizingMaskIntoConstraints = NO;
[label7 setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:label7];
NSLog(@"[CertRemainTime] Drawing label 8");
footer = [[UILabel alloc] init];
footer.font = [UIFont boldSystemFontOfSize: 10.0f];
footer.textColor = [UIColor blackColor];
footer.backgroundColor = [UIColor clearColor];
footer.textAlignment = NSTextAlignmentCenter;
if (errCode == 1 || errCode == 2) [footer setText:@"Send /var/MobileDevice/ProvisioningProfiles via mail"];
else if (errCode == 3) [footer setText:@"[email protected]"];
else [footer setText:@"Any issues? [email protected]"];
[footer sizeToFit];
footer.translatesAutoresizingMaskIntoConstraints = NO;
[footer setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[[self view] addSubview:footer];
/* Spaces */
NSLog(@"[CertRemainTime] Defining spaces");
topSpace = [[UIView alloc] init];
bottomSpace = [[UIView alloc] init];
topSpace.translatesAutoresizingMaskIntoConstraints = NO;
bottomSpace.translatesAutoresizingMaskIntoConstraints = NO;
[[self view] addSubview:topSpace];
[[self view] addSubview:bottomSpace];
/* Constraints */
NSLog(@"[CertRemainTime] Defining Constraints");
NSDictionary *viewDict = NSDictionaryOfVariableBindings(label1, label2, label3, label4, label5, label6, label7, footer, topSpace, bottomSpace);
NSLog(@"[CertRemainTime] Defining constraint for label 1");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label1
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 2");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label2
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 3");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label3
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 4");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label4
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 5'");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label5
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 6");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label6
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 7");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:label7
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining constraint for label 8");
[self.view addConstraint: [NSLayoutConstraint
constraintWithItem:footer
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0
]];
NSLog(@"[CertRemainTime] Defining general look");
[self.view addConstraints: [NSLayoutConstraint
constraintsWithVisualFormat:@"V:|-50-[label1]-10-[label2][topSpace(==bottomSpace)]-[label3]-100-[label4]-[label5]-[label6]-[label7][bottomSpace][footer]-10-|"
options:0
metrics:nil
views:viewDict
]];
NSLog(@"[CertRemainTime] Done !");
}
@end