-
Notifications
You must be signed in to change notification settings - Fork 4
/
TNRootViewController.m
162 lines (131 loc) · 6.2 KB
/
TNRootViewController.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
#import "TNRootViewController.h"
#import "TSUtil.h"
NSString* getHelperPath(void)
{
return [NSBundle.mainBundle.bundleURL.path stringByAppendingPathComponent:@"noncehelper"];
}
@implementation TNRootViewController
- (void)loadView
{
[super loadView];
}
- (void)startActivity:(NSString*)activity
{
if(_activityController) return;
_activityController = [UIAlertController alertControllerWithTitle:activity message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(5,5,50,50)];
activityIndicator.hidesWhenStopped = YES;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
[activityIndicator startAnimating];
[_activityController.view addSubview:activityIndicator];
[self presentViewController:_activityController animated:YES completion:nil];
}
- (void)stopActivityWithCompletion:(void (^)(void))completion
{
if(!_activityController) return;
[_activityController dismissViewControllerAnimated:YES completion:^
{
_activityController = nil;
if(completion)
{
completion();
}
}];
}
- (NSMutableArray*)specifiers
{
if(!_specifiers)
{
_specifiers = [NSMutableArray new];
PSSpecifier* groupSpecifier = [PSSpecifier emptyGroupSpecifier];
[groupSpecifier setProperty:[NSString stringWithFormat:@"TrollNonce %@\n\n© 2022 Lars Fröder (opa334)\n\nCredits:\n@jaakerblom: multicast_bytecopy exploit\n@_simo36: weightBufs exploit\n@0x7ff: dimentio", [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]] forKey:@"footerText"];
[_specifiers addObject:groupSpecifier];
PSSpecifier* readNonceSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Nonce"
target:self
set:nil
get:@selector(getNonceInfoString)
detail:nil
cell:PSTitleValueCell
edit:nil];
readNonceSpecifier.identifier = @"readnonce";
[readNonceSpecifier setProperty:@YES forKey:@"enabled"];
[_specifiers addObject:readNonceSpecifier];
PSSpecifier* setNonceSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Set Nonce"
target:self
set:nil
get:nil
detail:nil
cell:PSButtonCell
edit:nil];
setNonceSpecifier.identifier = @"setnonce";
[setNonceSpecifier setProperty:@YES forKey:@"enabled"];
setNonceSpecifier.buttonAction = @selector(setNoncePressed);
[_specifiers addObject:setNonceSpecifier];
}
[(UINavigationItem *)self.navigationItem setTitle:@"TrollNonce"];
return _specifiers;
}
- (NSString*)getNonceInfoString
{
NSString* output;
spawnRoot(getHelperPath(), @[@"get-nonce"], &output, nil);
NSLog(@"output: %@", output);
NSCharacterSet *separator = [NSCharacterSet newlineCharacterSet];
NSArray* lines = [output componentsSeparatedByCharactersInSet:separator];
return lines.firstObject;
}
- (void)setNoncePressed
{
UIAlertController* setNonceAlert = [UIAlertController alertControllerWithTitle:@"Set Nonce" message:@"Select a nonce to set, supports 15.0 - 15.1.1 on A10-A15 (multicast_bytecopy) and 15.0 - 15.5b4 on A12+ (weightBufs, NOTE: limited compatibility, some device / version combinations aren't working currently).\nNote: Setting a nonce using multicast_bytecopy is only possible once per boot." preferredStyle:UIAlertControllerStyleAlert];
[setNonceAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"0x1111111111111111";
}];
UIAlertAction* setAction = [UIAlertAction actionWithTitle:@"Set" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action)
{
UITextField* nonceField = setNonceAlert.textFields[0];
NSString* nonceStr = nonceField.text;
if(!nonceStr || nonceStr.length == 0)
{
nonceStr = @"0x1111111111111111";
}
if(nonceStr.length > 2 && [nonceStr hasPrefix:@"0x"])
{
[self startActivity:@"Setting Nonce..."];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
int setRet = spawnRoot(getHelperPath(), @[@"set-nonce", nonceStr], nil, nil);
dispatch_async(dispatch_get_main_queue(), ^(void){
[self stopActivityWithCompletion:^
{
[self reloadSpecifiers];
if(setRet == 0)
{
UIAlertController* successAlert = [UIAlertController alertControllerWithTitle:@"Success" message:@"Setting the nonce should have succeeded, the TrollHelper app may display \"Error\" or an invalid value in the nonce field until a reboot, this is a quirk of dimentio and normal. If you want to be sure that setting the nonce has succeeded, reboot your device and check the 'Nonce' field afterwards." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[successAlert addAction:closeAction];
[self presentViewController:successAlert animated:YES completion:nil];
}
else if(setRet == 5)
{
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:@"TrollNonce does not support this device / version combination" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[errorAlert addAction:closeAction];
[self presentViewController:errorAlert animated:YES completion:nil];
}
else
{
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error %d occured while setting nonce, kernel exploit probably failed, maybe (reboot and) try again? Check syslog for more info", setRet] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[errorAlert addAction:closeAction];
[self presentViewController:errorAlert animated:YES completion:nil];
}
}];
});
});
}
}];
[setNonceAlert addAction:setAction];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[setNonceAlert addAction:cancelAction];
[self presentViewController:setNonceAlert animated:YES completion:nil];
}
@end