-
Notifications
You must be signed in to change notification settings - Fork 5
/
LibPass.m
188 lines (155 loc) · 5.65 KB
/
LibPass.m
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
#import "libPass.h"
#import "headers.h"
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>
#import "NSData+AES.m"
#define SETTINGS_FILE @"/var/mobile/Library/Preferences/com.bd452.libpass.plist"
NSString *getTimePasscode()
{
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.expetelek.timepasscodepreferences.plist"];
if ([dict[@"isEnabled"] boolValue] == NO)
return nil;
SBDeviceLockController *lockController = [objc_getClass("SBDeviceLockController") sharedController];
if ([lockController respondsToSelector:@selector(getCurrentPasscode)])
return [lockController getCurrentPasscode];
else if ([lockController respondsToSelector:@selector(getCurrentPasscode:)])
return [lockController getCurrentPasscode:dict];
return nil;
}
@implementation LibPass
+ (id) sharedInstance
{
// This (helps) prevent multiple instances from being created which would cause issues
static LibPass *instance;
if (!instance)
instance = [[LibPass alloc] init];
return instance;
}
- (id) init
{
delegates = [[NSMutableArray alloc] init];
self.isPasscodeOn = YES;
self.devicePasscode = nil;
return [super init];
}
-(BOOL) isDelegateRegistered:(id)delegate
{
return [delegates indexOfObject:delegate] != NSNotFound;
}
-(void) registerDelegate:(id)delegate
{
if ([self isDelegateRegistered:delegate] || delegate == nil)
return;
[delegates addObject:delegate];
}
-(void) deregisterDelegate:(id)delegate
{
if (![self isDelegateRegistered:delegate] || delegate == nil)
return;
NSUInteger num = [delegates indexOfObject:delegate];
if (NSNotFound == num)
return;
[delegates removeObjectAtIndex:num];
}
- (void)unlockWithCodeEnabled:(BOOL)enabled
{
if (enabled) {
[(SBLockScreenManager *)[objc_getClass("SBLockScreenManager") sharedInstance] unlockUIFromSource:1 withOptions:nil];
}
else
{
[self setPasscodeToggle:NO];
id awayController_ = objc_getClass("CSAwayController") ?: objc_getClass("SBAwayController");
if (awayController_ && [awayController_ respondsToSelector:@selector(sharedAwayController)])
{
SBAwayController *awayController = [awayController_ sharedAwayController];
if ([awayController respondsToSelector:@selector(attemptDeviceUnlockWithPassword:lockViewOwner:)])
{
if ([[LibPass sharedInstance] respondsToSelector:@selector(getEffectiveDevicePasscode)])
{
[awayController attemptDeviceUnlockWithPassword:[[LibPass sharedInstance] getEffectiveDevicePasscode] lockViewOwner:nil];
return;
}
}
}
[(SBLockScreenViewController*)[[objc_getClass("SBLockScreenManager") sharedInstance] lockScreenViewController] passcodeLockViewPasscodeEntered:nil];
//[(SBLockScreenManager *)[objc_getClass("SBLockScreenManager") sharedInstance] attemptUnlockWithPasscode:[NSString stringWithFormat:@"%@", self.devicePasscode]];
}
}
- (void)lockWithCodeEnabled:(BOOL)enabled
{
[(SBUserAgent *)[objc_getClass("SBUserAgent") sharedUserAgent] lockAndDimDevice];
[self setPasscodeToggle:enabled];
}
- (void)togglePasscode {
self.isPasscodeOn = !self.isPasscodeOn;
// This shows a banner notification to the user
// letting them know what status the passcode is in right now.
Class bulletinBannerController = objc_getClass("SBBulletinBannerController");
Class bulletinRequest = objc_getClass("BBBulletinRequest");
if (bulletinBannerController && bulletinRequest) {
BBBulletinRequest *request = [[bulletinRequest alloc] init];
request.title = @"Password";
NSString *passcodeEnabledString;
if ([LibPass sharedInstance].isPasscodeOn)
passcodeEnabledString = @"enabled";
else
passcodeEnabledString = @"disabled";
request.message = [NSString stringWithFormat:@"Password now %@", passcodeEnabledString];
request.sectionID = @"com.bd452.libpass";
[(SBBulletinBannerController *)[bulletinBannerController sharedInstance] observer:nil addBulletin:request forFeed:2];
return;
}
}
-(void)setPasscodeToggle:(BOOL)enabled
{
self.isPasscodeOn = enabled;
}
-(void)passwordWasEnteredHandler:(NSString *)password {
for (id delegate in delegates)
{
if (delegate && [delegate respondsToSelector:@selector(passwordWasEntered:)])
{
[delegate passwordWasEntered:password];
}
}
}
// This is used when unlocking the device and isPasscodeOn == YES to allow for
// multiple passcode to be used and the like.
// This opens the door to a large variety of possibilities.
- (BOOL) shouldAllowPasscode:(NSString*)passcode
{
BOOL result = [passcode isEqualToString:self.devicePasscode];
for (id delegate in delegates)
{
if (delegate && [delegate respondsToSelector:@selector(shouldAllowPasscode:)])
{
result = result || [delegate shouldAllowPasscode:passcode];
}
}
return result;
}
-(BOOL) toggleValue
{
return !self.isPasscodeOn;
}
-(BOOL) isPasscodeAvailable
{
return [self getEffectiveDevicePasscode] != nil;
}
-(NSString*)getEffectiveDevicePasscode
{
// Add more usages and stuff here pl0x
// Currently supports: TimePasscode and TimePasscode Pro
// As well as the standard device passcode, obviously ;)
NSString *returnValue = getTimePasscode();
if (returnValue)
return returnValue;
return self.devicePasscode;
}
-(void) deviceWasUnlockedHandler
{
[[LibPass sharedInstance] setPasscodeToggle:YES];
}
@end