-
Notifications
You must be signed in to change notification settings - Fork 84
/
ViewController.m
226 lines (173 loc) · 6.63 KB
/
ViewController.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//
// ViewController.m
// iRE
//
// Created by veracode on 11/8/13.
// Copyright (c) 2013 veracode. All rights reserved.
//
#import "ViewController.h"
#include <ifaddrs.h>
#include <arpa/inet.h>
@interface ViewController ()
@end
@implementation ViewController
UIButton*btnStart;
int intButtonState;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
float rd = 3.0/255.0;
float gr = 119.0/255.0;
float bl = 204.0/255.0;
self.view.backgroundColor = [UIColor colorWithRed:rd green:gr blue:bl alpha:1.0];
//ADD THE HEADER LABEL
lblHeader = [[UILabel alloc]
initWithFrame:CGRectMake(0,10,320,100)];
lblHeader.text = @"Welcome to iRET";
lblHeader.backgroundColor = [UIColor clearColor];
lblHeader.textColor = [UIColor whiteColor];
lblHeader.font = [UIFont fontWithName:@"Arial-BoldMT" size:25.0];
lblHeader.textAlignment = NSTextAlignmentCenter;
//ADD THE HEADER LABEL
lbliRET = [[UILabel alloc]
initWithFrame:CGRectMake(0,60,320,100)];
lbliRET.text = @"The iOS Reverse Engineering Toolkit";
lbliRET.backgroundColor = [UIColor clearColor];
lbliRET.textColor = [UIColor whiteColor];
lbliRET.font = [UIFont fontWithName:@"Arial-BoldMT" size:15.0];
lbliRET.textAlignment = NSTextAlignmentCenter;
//ADD THE MESSAGE LABEL
lblMessage = [[UILabel alloc]
initWithFrame:CGRectMake(0,100,320,100)];
lblMessage.numberOfLines = 0;
lblMessage.lineBreakMode = true;
lblMessage.text = @"For on device analysis and reversing.";
lblMessage.backgroundColor = [UIColor clearColor];
lblMessage.textColor = [UIColor whiteColor];
lblMessage.font = [UIFont fontWithName:@"Arial-BoldMT" size:10.0];
lblMessage.textAlignment = NSTextAlignmentCenter;
//ADD THE BUTTON
UIButton*btnStart = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnStart.frame = CGRectMake(105,175,100,35);
btnStart.backgroundColor = [UIColor whiteColor];
[btnStart.titleLabel setTextColor:[UIColor blackColor]];
[btnStart.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[btnStart setTitle:@"Start" forState:UIControlStateNormal];
[btnStart addTarget:self action:@selector(btnStartPressed:) forControlEvents:UIControlEventTouchUpInside];
//ADD THE IP Text LABEL
lblIPText = [[UILabel alloc]
initWithFrame:CGRectMake(0,225,320,100)];
lblIPText.backgroundColor = [UIColor clearColor];
lblIPText.textColor = [UIColor whiteColor];
lblIPText.font = [UIFont fontWithName:@"Arial-BoldMT" size:20.0];
lblIPText.textAlignment = NSTextAlignmentCenter;
//ADD THE IP Address LABEL
lblIPAddress = [[UILabel alloc]
initWithFrame:CGRectMake(0,275,320,200)];
lblIPAddress.backgroundColor = [UIColor clearColor];
lblIPAddress.textColor = [UIColor blackColor];
lblIPAddress.font = [UIFont fontWithName:@"Arial-BoldMT" size:15.0];
lblIPAddress.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:lblHeader];
[self.view addSubview:lblMessage];
[self.view addSubview:btnStart];
[self.view addSubview:lblIPText];
[self.view addSubview:lblIPAddress];
[self.view addSubview: lbliRET];
}
-(void) btnStartPressed:(UIButton *) sender
{
//START THE LISTENER
NSString *strIP;
if (intButtonState == 0)
{
intButtonState = 1;
@try
{
//change the button text to show 'Stop'
[sender setTitle: @"Stop" forState: UIControlStateNormal];
int loadResult = system("launchctl load /System/Library/LaunchDaemons/com.jensen.iRE.Startup.plist");
NSLog(@" Load Startup Result: %i", loadResult);
if(loadResult == 0)
strIP = [self getIPAddress];
strIP = [strIP stringByAppendingString:@":5555"];
lblIPText.text = @"Navigate your browser to:";
lblIPAddress.text = strIP;
}
@catch (NSException *exception)
{
NSLog( @"NSException caught ");
NSLog( @"Name: %@", exception.name);
NSLog( @"Reason: %@", exception.reason);
}
@finally
{
NSLog( @"In finally block.");
}
}
else if (intButtonState == 1)
{
//STOP THE LISTENER
intButtonState = 0;
@try {
//change the button text to show 'Start'
[sender setTitle: @"Start" forState: UIControlStateNormal];
int unloadStart = system("launchctl unload /System/Library/LaunchDaemons/com.jensen.iRE.Startup.plist");
NSLog(@"Unload Start Result: %i", unloadStart);
lblIPText.text = @"";
lblIPAddress.text = @"";
}
@catch (NSException *exception) {
NSLog( @"NSException caught ");
NSLog( @"Name: %@", exception.name);
NSLog( @"Reason: %@", exception.reason);
}
@finally {
NSLog( @"In finally block.");
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSString *)getIPAddress {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL) {
if(temp_addr->ifa_addr->sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}
temp_addr = temp_addr->ifa_next;
}
}
// Free memory
freeifaddrs(interfaces);
return address;
}
@end