-
Notifications
You must be signed in to change notification settings - Fork 5
/
Tweak.xm
148 lines (128 loc) · 3.71 KB
/
Tweak.xm
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
#import <substrate.h>
#import <UIKit/UIKit.h>
#define PREFERENCE_IDENTIFIER CFSTR("com.tuttarealstep.iunlockpreferences")
#define REAL_PASSCODE_KEY CFSTR("realPasscode")
static NSData *realPasscode;
static bool realPasscodeFailed;
static bool isEnabled = YES;
static bool showAlert = NO;
%hook SBFUserAuthenticationController
- (bool)_authenticateWithPasscodeData:(id)arg1 outError:(id*)arg2
{
NSLog(@"_authenticateWithPasscodeData -----> %@", arg1);
if(realPasscodeFailed)
{
bool result = %orig;
if (result)
{
//Crypt passcode
realPasscode = arg1;
CFPreferencesSetAppValue(REAL_PASSCODE_KEY, (CFDataRef)realPasscode, PREFERENCE_IDENTIFIER);
if (CFPreferencesAppSynchronize(PREFERENCE_IDENTIFIER))
{
if(showAlert)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iUnlock"
message:@"Updated with the new passcode!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
realPasscodeFailed = NO;
}
} else {
if(showAlert)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iUnlock"
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 (realPasscode == NULL)
{
bool result = %orig;
if (result)
{
//Crypt passcode
realPasscode = arg1;
CFPreferencesSetAppValue(REAL_PASSCODE_KEY, (CFDataRef)realPasscode, PREFERENCE_IDENTIFIER);
if (CFPreferencesAppSynchronize(PREFERENCE_IDENTIFIER))
{
if(showAlert)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iUnlock"
message:@"Device configured, you can now use iUnlock!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
} else {
if(showAlert)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iUnlock"
message:@"Device not configured, unlock your device for use iUnlock!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
return result;
}
bool didAnswerCorrectly = NO;
if (isEnabled)
{
didAnswerCorrectly = YES;
arg1 = realPasscode;
}
bool result = %orig(arg1, arg2);
if (didAnswerCorrectly && !result)
{
if(showAlert)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"iUnlock"
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];
}
realPasscodeFailed = YES;
}
return result;
}
/*- (long long) _evaluatePasscodeAttempt:(id)arg1 outError:(id*)arg2
{
NSLog(@"_evaluatePasscodeAttempt -----> %@", arg1);
long long prova = %orig;
NSLog(@"risultato -----> %lld", prova);
return prova;
}*/
%end
static void loadSettings()
{
CFPreferencesAppSynchronize(PREFERENCE_IDENTIFIER);
realPasscode = (NSData *)CFBridgingRelease(CFPreferencesCopyAppValue(REAL_PASSCODE_KEY, PREFERENCE_IDENTIFIER));
}
static void settingsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
loadSettings();
}
%ctor
{
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, settingsChanged, CFSTR("com.tuttarealstep.iunlockpreferences/settingsChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
loadSettings();
}