-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.xm
136 lines (84 loc) · 3.32 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
%hook CredentialPromptsViewController
BOOL isPasswordViewController;
static NSString *preferencesFilePath = @"/private/var/mobile/Library/Preferences/com.ahmad.passConnect.plist";
-(void)viewWillAppear:(BOOL)animated {
NSMutableDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:preferencesFilePath].mutableCopy;
if (!preferences) preferences = [[NSMutableDictionary alloc] init];
NSDictionary *userPromptDict = MSHookIvar<NSDictionary *>(self, "userPromptDict");
NSString *type = userPromptDict[@"PromptEntryArray"][0][@"Name"];
if ([type isEqualToString:@"password"]) {
isPasswordViewController = YES;
if (preferences[@"Password"]) {
userPromptDict[@"PromptEntryArray"][0][@"Value"] = preferences[@"Password"];
MSHookIvar<NSDictionary *>(self, "userPromptDict") = userPromptDict;
}
}
%orig;
}
- (void)textFieldDidEndEditing:(UITextField *)arg1 {
if (isPasswordViewController) {
isPasswordViewController = NO;
NSMutableDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:preferencesFilePath].mutableCopy;
if (!preferences) preferences = [[NSMutableDictionary alloc] init];
NSString *passwordString = arg1.text;
[preferences setObject:passwordString forKey:@"Password"];
[preferences writeToFile:preferencesFilePath atomically:NO];
}
%orig;
}
-(void)viewDidAppear:(BOOL)animated {
NSMutableDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:preferencesFilePath].mutableCopy;
if (!preferences) {
preferences = [[NSMutableDictionary alloc] init];
}
NSDictionary *userPromptDict = MSHookIvar<NSDictionary *>(self, "userPromptDict");
NSString *value = userPromptDict[@"PromptEntryArray"][0][@"Value"];
if (![value isEqualToString:@""] && [preferences[@"AutoConnect"] isEqualToString:@"YES"]) {
[self performSelector:@selector(connect)];
}
%orig;
}
%end
%hook HomeViewController
UISwitch *connectSwitch;
-(void)viewDidLoad {
%orig;
connectSwitch = [[UISwitch alloc] init];
[connectSwitch addTarget:self action:@selector(connectSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
NSMutableDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:preferencesFilePath].mutableCopy;
if (!preferences) {
preferences = [[NSMutableDictionary alloc] init];
}
if ([preferences[@"AutoConnect"] isEqualToString:@"YES"]) {
[connectSwitch setOn:YES];
}
}
%new(v@:)
-(void)connectSwitchValueChanged:(UISwitch *)sender {
NSMutableDictionary *preferences = [NSDictionary dictionaryWithContentsOfFile:preferencesFilePath].mutableCopy;
if (!preferences) {
preferences = [[NSMutableDictionary alloc] init];
}
NSString *switchStatus;
if (sender.isOn) {
switchStatus = @"YES";
} else {
switchStatus = @"NO";
}
[preferences setObject:switchStatus forKey:@"AutoConnect"];
[preferences writeToFile:preferencesFilePath atomically:NO];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 3) {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.textLabel.text = @"Auto Connect";
cell.accessoryView = connectSwitch;
return cell;
} else {
return %orig;
}
}
%end