forked from hetelek/TimePasscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.xm
More file actions
176 lines (148 loc) · 5.33 KB
/
Tweak.xm
File metadata and controls
176 lines (148 loc) · 5.33 KB
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
#import <UIKit/UIKit.h>
#import "include/AES.m"
static BOOL truePasscodeFailed;
@interface SBDeviceLockController : UIViewController
- (NSString *)getCurrentPasscode;
@end
%hook SBDeviceLockController
static char dateFormatterHolder;
- (BOOL)attemptDeviceUnlockWithPassword:(NSString *)passcode appRequested:(BOOL)requested
{
if (![passcode isKindOfClass:[NSString class]])
return %orig;
NSString *key = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.expetelek.timepasscodepreferences.plist";
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
if (!prefs)
prefs = [[NSMutableDictionary alloc] init];
if (truePasscodeFailed)
{
BOOL result = %orig;
if (result)
{
[prefs setObject:[[passcode dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key] forKey:@"truePasscode"];
if ([prefs writeToFile:settingsPath atomically:YES])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Passcode Updated"
message:@"Your passcode has been updated."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
truePasscodeFailed = NO;
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Passcode Changed"
message:@"It seems like you've changed your passcode. Please unlock your device using the true passcode to reconfigure your device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
return result;
}
if (![[prefs allKeys] containsObject:@"truePasscode"])
{
BOOL result = %orig;
if (result)
{
[prefs setObject:[[passcode dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key] forKey:@"truePasscode"];
if ([prefs writeToFile:settingsPath atomically:YES])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Device Configured"
message:@"You have now configured TimePasscode to work with your device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Not Configured"
message:@"TimePasscode has not yet been configured to work with your device. Please unlock your device using the true passcode to configure it."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
return result;
}
else if ([prefs[@"truePasscode"] isKindOfClass:[NSString class]])
{
prefs[@"truePasscode"] = [[prefs[@"truePasscode"] dataUsingEncoding:NSUTF8StringEncoding] AES256EncryptWithKey:key];
[prefs writeToFile:settingsPath atomically:YES];
}
BOOL isEnabled = ![[prefs allKeys] containsObject:@"isEnabled"] || [prefs[@"isEnabled"] boolValue];
BOOL didAnswerCorrectly = NO;
if (isEnabled)
{
NSString *timePasscode = [self getCurrentPasscode];
if ([prefs[@"reverseTimePasscode"] boolValue])
{
NSMutableString *reversedString = [NSMutableString string];
NSInteger charIndex = [timePasscode length];
while (charIndex-- > 0)
[reversedString appendString:[timePasscode substringWithRange:NSMakeRange(charIndex, 1)]];
timePasscode = reversedString;
}
if ([timePasscode isEqualToString:passcode])
{
didAnswerCorrectly = YES;
NSData *passcodeDecrypt = [prefs[@"truePasscode"] AES256DecryptWithKey:key];
passcode = [NSString stringWithUTF8String:[[[NSString alloc] initWithData:passcodeDecrypt encoding:NSUTF8StringEncoding] UTF8String]];
}
else if (![prefs[@"allowTruePasscodeUnlock"] boolValue])
passcode = [NSString string];
}
BOOL alteredResult = %orig(passcode, requested);
if (didAnswerCorrectly && !alteredResult)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Passcode Changed"
message:@"It seems like you've changed your passcode. Please unlock your device using the true passcode to reconfigure your device."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
truePasscodeFailed = YES;
}
return alteredResult;
}
%new
- (NSString *)getCurrentPasscode
{
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = objc_getAssociatedObject(self, &dateFormatterHolder);
if (!dateFormatter)
{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
objc_setAssociatedObject(self, &dateFormatterHolder, dateFormatter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
NSString *dateString = [[dateFormatter stringFromDate:date] stringByReplacingOccurrencesOfString:@":" withString:[NSString string]];
NSMutableString *strippedString = [NSMutableString stringWithCapacity:dateString.length];
NSScanner *scanner = [NSScanner scannerWithString:dateString];
NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
while (![scanner isAtEnd])
{
NSString *buffer;
if ([scanner scanCharactersFromSet:numbers intoString:&buffer])
[strippedString appendString:buffer];
else
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
dateString = strippedString;
if (strippedString.length != 4)
dateString = [@"0" stringByAppendingString:dateString];
return dateString;
}
%end