-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathpwnHelperClass.m
817 lines (613 loc) · 24.6 KB
/
pwnHelperClass.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
//
// pwnHelperClass.m
// Seas0nPass
//
// Created by Kevin Bradley on 4/16/09.
// Copyright 2009 nito, LLC. All rights reserved.
//
#import "pwnHelperClass.h"
#import "nitoUtility.h"
#import "include/libpois0n.h"
@implementation pwnHelperClass
@synthesize currentBundle;
- (NSString *)convertImage:(NSString *)irString toMode:(int)theMode
{
NSString *outputName = nil;
NSString *modeString = nil;
switch (theMode)
{
case 0: //UDRW
outputName = [[self theDownloadPath] stringByAppendingPathComponent:@"converted.dmg"];
modeString = @"UDRW";
break;
case 1: //
outputName = [[self theDownloadPath] stringByAppendingPathComponent:@"final.dmg"];
modeString = @"UDZO";
break;
}
NSTask *irTask = [[NSTask alloc] init];
NSMutableArray *irArgs = [[NSMutableArray alloc] init];
[irArgs addObject:@"convert"];
[irArgs addObject:irString];
[irArgs addObject:@"-format"];
[irArgs addObject:modeString];
[irArgs addObject:@"-o"];
[irArgs addObject:outputName];
[irTask setLaunchPath:@"/usr/bin/hdiutil"];
[irTask setArguments:irArgs];
[irArgs release];
//NSLog(@"hdiutil %@", [[irTask arguments] componentsJoinedByString:@" "]);
[irTask launch];
//[self setCurrentTask:irTask];
[irTask waitUntilExit];
return outputName;
}
- (NSString *)theDownloadPath {
NSString *thePath = [processDict valueForKey:@"download"];
return thePath;
}
- (NSDictionary *)processDict {
return [[processDict retain] autorelease];
}
- (void)setProcessDict:(NSDictionary *)value {
if (processDict != value) {
[processDict release];
processDict = [value copy];
}
}
- (void)changeOwner:(NSString *)theOwner onFile:(NSString *)theFile isRecursive:(BOOL)isR
{
NSTask *ownTask = [[NSTask alloc] init];
NSMutableArray *ownArgs = [[NSMutableArray alloc] init];
[ownTask setLaunchPath:@"/usr/sbin/chown"];
if (isR)
[ownArgs addObject:@"-R"];
[ownArgs addObject:theOwner];
[ownArgs addObject:theFile];
[ownTask setArguments:ownArgs];
//NSLog(@"chown %@", [ownArgs componentsJoinedByString:@" "]);
[ownArgs release];
[ownTask launch];
[ownTask waitUntilExit];
[ownTask release];
ownTask = nil;
}
- (void)changePermissions:(NSString *)perms onFile:(NSString *)theFile isRecursive:(BOOL)isR
{
NSTask *permTask = [[NSTask alloc] init];
NSMutableArray *permArgs = [[NSMutableArray alloc] init];
if (isR)
[permArgs addObject:@"-R"];
[permArgs addObject:perms];
[permArgs addObject:theFile];
[permTask setLaunchPath:@"/bin/chmod"];
[permTask setArguments:permArgs];
//NSLog(@"chmod %@", [[permTask arguments] componentsJoinedByString:@" "]);
[permTask launch];
[permTask waitUntilExit];
[permTask release];
permTask = nil;
}
- (int)patchFstab:(NSDictionary *)patchDict withRoot:(NSString *)mountedPath
{
NSString *inputFile = [mountedPath stringByAppendingPathComponent:[patchDict valueForKey:@"inputFile"]];
NSString *thePatch = [patchDict valueForKey:@"patchFile"];
NSString *md5 = [patchDict valueForKey:@"md5"];
return [nitoUtility patchFile:inputFile withPatch:thePatch endMD5:md5];
}
- (int)installCydia:(NSString *)cydiaPackage withRoot:(NSString *)mountedPath
{
return [nitoUtility extractGZip:cydiaPackage toRoot:mountedPath];
}
- (void)installWifi:(NSString *)wifiFile withRoot:(NSString *)mountedPath
{
[FM copyItemAtPath:wifiFile toPath:[mountedPath stringByAppendingPathComponent:@"/Library/Preferences/SystemConfiguration/com.apple.wifi.plist"] error:nil];
}
- (void)installSSHKey:(NSString *)sshKey withRoot:(NSString *)mountedPath
{
NSString *sshFolder = [mountedPath stringByAppendingPathComponent:@"var/root/.ssh"];
[FM createDirectoryAtPath:sshFolder withIntermediateDirectories:YES attributes:nil error:nil];
if([FM copyItemAtPath:sshKey toPath:[sshFolder stringByAppendingPathComponent:@"authorized_keys"] error:nil])
{
[self changeOwner:@"root:wheel" onFile:sshFolder isRecursive:YES];
NSLog(@"authorized key installed successfully!");
}
}
- (int)runBundleCommands:(NSArray *)commands onFiles:(NSString *)thePath
{
id theAction = nil;
int status = 0;
NSEnumerator *dictEnum = [commands objectEnumerator];
while (theAction = [dictEnum nextObject]) {
status = [self performAction:theAction onVolume:thePath];
}
return status;
}
- (int)stash:(NSString *)scriptFile withRoot:(NSString *)mountedPath
{
return [nitoUtility runScript:scriptFile withInput:mountedPath];
}
- (int)fileSystemPatches:(NSString *)theVolume
{
int status = 0;
if ([currentBundle coreFilesInstallation] != nil)
{
NSDictionary *cfi = [currentBundle coreFilesInstallation];
id coreFile = nil;
NSEnumerator *dictEnum = [cfi objectEnumerator];
while (coreFile = [dictEnum nextObject]) {
status = [self performAction:coreFile onVolume:theVolume];
if (status != 0)
{
NSLog(@"coreFileInstallation failed!! bail!");
return -1;
}
}
}
if ([currentBundle filesystemJailbreak] != nil)
{
NSArray *cfi = [currentBundle filesystemJailbreak];
id coreFile = nil;
NSEnumerator *dictEnum = [cfi objectEnumerator];
while (coreFile = [dictEnum nextObject]) {
status = [self performAction:coreFile onVolume:theVolume];
if (status != 0)
{
NSLog(@"filesystemJailbreak failed!! bail!");
return -1;
}
}
}
return status;
}
- (int)performAction:(NSDictionary *)actionDict onVolume:(NSString *)theVolume
{
NSString *actionType = [actionDict valueForKey:@"Action"];
if ([actionType isEqualToString:@"Add"])
{
return [self addAction:actionDict toVolume:theVolume];
} else if ([actionType isEqualToString:@"Patch"])
{
return [self patchAction:actionDict toVolume:theVolume];
} else if ([actionType isEqualToString:@"SetPermission"])
{
return [self permissionAction:actionDict toVolume:theVolume];
} else if ([actionType isEqualToString:@"SetOwner"])
{
return [self ownerAction:actionDict toVolume:theVolume];
} else if ([actionType isEqualToString:@"Extract"]) {
return [self extractAction:actionDict toVolume:theVolume];
} else {
NSLog(@"unrecognized action: %@", actionType);
return -1;
}
}
- (int)ownerAction:(NSDictionary *)actionDict toVolume:(NSString *)theVolume
{
NSString *inputFile = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"File"]];
NSString *owner = [actionDict valueForKey:@"Owner"];
NSLog(@"set %@ to %@", inputFile, owner);
[nitoUtility changeOwner:owner onFile:inputFile isRecursive:FALSE];
return 0;
}
- (int)permissionAction:(NSDictionary *)actionDict toVolume:(NSString *)theVolume
{
NSLog(@"action: %@", actionDict);
NSString *inputFile = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"File"]];
NSString *permission = [actionDict valueForKey:@"Permission"];
NSLog(@"set %@ to %@", inputFile, permission);
[nitoUtility changePermissions:permission onFile:inputFile isRecursive:FALSE];
return 0;
}
- (int)patchAction:(NSDictionary *)actionDict toVolume:(NSString *)theVolume
{
//NSLog(@"patchAction: %@ toVolume: %@", actionDict, theVolume);
NSString *inputFile = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"File"]];
NSString *patch = [self.currentBundle.bundlePath stringByAppendingPathComponent:[actionDict valueForKey:@"Patch"]];
return [nitoUtility patchFile:inputFile withPatch:patch endMD5:nil];
}
- (void)sendCommand:(id)theKbag
{
//NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Logs/SP_Keys.log"];
//NSString *duplicate = [[logPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"txt"];
//[FM removeFileAtPath:logPath handler:nil];
//FILE* file = freopen([logPath fileSystemRepresentation], "w+", stdout);
NSString *command = [NSString stringWithFormat:@"go aes dec %@", theKbag];
//NSLog(@"command: %@", command);
int quit = 0;
irecv_error_t error = 0;
irecv_init();
irecv_client_t client = NULL;
if (irecv_open(&client) != IRECV_E_SUCCESS)
{
NSLog(@"fail!");
return;
}
//irecv_set_debug_level(20);
//irecv_set_interface(client, 0, 0);
irecv_set_configuration(client, 1);
//irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL);
//irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL);
while (!quit) {
irecv_set_interface(client, 0, 0);
irecv_set_interface(client, 1, 1);
error = irecv_receive(client);
//irecv_set_interface(client, 1, 0);
error = irecv_send_command(client, [command UTF8String]);
error = irecv_receive(client);
//debug("%s\n", irecv_strerror(error));
quit = 1;
}
irecv_close(client);
irecv_exit();
/*
fclose(file);
[FM copyItemAtPath:logPath toPath:duplicate error:nil];
NSString *me = [NSString stringWithContentsOfFile:duplicate];
NSLog(@"ME: %@", me);
*/
}
- (int)extractAction:(NSDictionary *)actionDict toVolume:(NSString *)theVolume
{
NSString *theFile = [actionDict valueForKey:@"File"];
NSString *path = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"Path"]];
NSString *inputFile = [self.currentBundle.bundlePath stringByAppendingPathComponent:theFile];
NSLog(@"extracting %@ to %@",theFile, path);
int returnStatus = [nitoUtility extractGZip:inputFile toRoot:path];
NSLog(@"returnStatus: %i", returnStatus);
if ([theFile isEqualToString:@"saffron.tgz"])
{
[nitoUtility linkFile:@"/boot/untether" toPath:@"usr/libexec/dirhelper" inWorkingDirectory:theVolume];
}
if ([theFile isEqualToString:@"corona.tgz"])
{
NSString *patchFile = [self.currentBundle.bundlePath stringByAppendingPathComponent:@"racoon.patch"];
[nitoUtility patchFile:@"usr/sbin/racoon" withPatch:patchFile toLocation:@"usr/sbin/corona" inWorkingDirectory:theVolume];
}
if ([theFile isEqualToString:@"rocky.tgz"])
{
NSString *patchFile = [self.currentBundle.bundlePath stringByAppendingPathComponent:@"racoon.patch"];
[nitoUtility patchFile:@"usr/sbin/racoon" withPatch:patchFile toLocation:@"private/var/audit/rocky-racoon/racoon" inWorkingDirectory:theVolume];
}
return returnStatus;
}
- (int)addAction:(NSDictionary *)actionDict toVolume:(NSString *)theVolume
{
//var/db/.launchd_use_gmalloc
NSString *theFile = [actionDict valueForKey:@"File"];
NSString *pathCompare = [[actionDict valueForKey:@"Path"] lastPathComponent];
if ([theFile isEqualToString:@"libgmalloc.dylib"])
{
NSString *gmallocUse = [theVolume stringByAppendingPathComponent:@"var/db/.launchd_use_gmalloc"];
[FM createFileAtPath:gmallocUse contents:nil attributes:nil];
NSLog(@"%@ added successfully!", gmallocUse);
}
NSString *path = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"Path"]];
NSString *inputFile = [self.currentBundle.bundlePath stringByAppendingPathComponent:theFile];
if ([FM fileExistsAtPath:path])
{
//may need to switcheroo?? //punchd
NSLog(@"comparing File: %@ to Path: %@", theFile, pathCompare);
if (![theFile isEqualToString:pathCompare])
{
NSString *path2 = [theVolume stringByAppendingPathComponent:[actionDict valueForKey:@"Path"]];
path2 = [[path2 stringByDeletingLastPathComponent] stringByAppendingPathComponent:theFile];
[FM moveItemAtPath:path toPath:path2 error:nil];
} else { //just remove the file
[FM removeItemAtPath:path error:nil];
}
}
if (![FM fileExistsAtPath:[path stringByDeletingLastPathComponent]])
{
NSLog(@"creating directory");
[FM createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
}
NSLog(@"copying: %@ to %@", inputFile, path);
if([FM copyItemAtPath:inputFile toPath:path error:nil])
{
NSLog(@"installed %@ successfully!",[actionDict valueForKey:@"File"] );
[nitoUtility changeOwner:@"root:wheel" onFile:path isRecursive:YES];
[nitoUtility changePermissions:@"777" onFile:path isRecursive:YES];
return 0;
} else{
NSLog(@"%@ installation failed!", [actionDict valueForKey:@"File"]);
return -1;
}
return -1;
}
- (NSArray *)debWhitelist
{
return [NSArray arrayWithObjects:@"com.nito.deb", @"awkwardtv.deb", @"org.xbmc.repo_0.1-1_iphoneos-arm.deb",@"syslogd.deb", nil];
}
- (void)installWhitelistDebFilesFromPath:(NSString *)debPath toRoot:(NSString *)rootPath
{
id theDeb = nil;
NSString *outputPath = [rootPath stringByAppendingPathComponent:@"var/root/Media/Cydia/AutoInstall"];
NSDirectoryEnumerator *files = [[NSFileManager defaultManager] enumeratorAtPath:debPath];
while (theDeb = [files nextObject])
{
NSString *extension = [theDeb pathExtension];
if ([[extension lowercaseString] isEqualToString:@"deb"])
{
NSString *fullpath = [debPath stringByAppendingPathComponent:theDeb];
NSString *finalPath = [outputPath stringByAppendingPathComponent:theDeb];
if ([[self debWhitelist] containsObject:theDeb])
{
NSLog(@"%@ is on the list!!", theDeb);
if([FM copyItemAtPath:fullpath toPath:finalPath error:nil])
{
NSLog(@"installed: %@ to %@ successfully!", fullpath, finalPath);
} else {
NSLog(@"install: %@ to %@ failed!", fullpath, finalPath);
}
} else {
NSLog(@"%@ is out!", theDeb);
}
}
}
}
- (void)installDebFilesFromPath:(NSString *)debPath toRoot:(NSString *)rootPath
{
id theDeb = nil;
if ([[self processDict] valueForKey:@"debWhitelist"] != nil)
{
NSLog(@"deb white list is enabled, but is ignored for now");
//[self installWhitelistDebFilesFromPath:debPath toRoot:rootPath];
//return;
}
NSString *outputPath = [rootPath stringByAppendingPathComponent:@"var/root/Media/Cydia/AutoInstall"];
if (![[NSFileManager defaultManager] fileExistsAtPath:outputPath])
[[NSFileManager defaultManager] createDirectoryAtPath:outputPath withIntermediateDirectories:TRUE attributes:nil error:nil];
NSDirectoryEnumerator *files = [[NSFileManager defaultManager] enumeratorAtPath:debPath];
while (theDeb = [files nextObject])
{
NSString *extension = [theDeb pathExtension];
if ([[extension lowercaseString] isEqualToString:@"deb"])
{
NSString *fullpath = [debPath stringByAppendingPathComponent:theDeb];
NSString *finalPath = [outputPath stringByAppendingPathComponent:theDeb];
if([FM copyItemAtPath:fullpath toPath:finalPath error:nil])
{
NSLog(@"installed: %@ to %@ successfully!", fullpath, finalPath);
} else {
NSLog(@"install: %@ to %@ failed!", fullpath, finalPath);
}
}
}
}
- (int)disableBetaExpiry:(NSString *)theVolume
{
NSString *systemVersionPath = [theVolume stringByAppendingPathComponent:@"System/Library/CoreServices/SystemVersion.plist"];
NSMutableDictionary *systemVersion = [[NSMutableDictionary alloc] initWithContentsOfFile:systemVersionPath];
if ([[systemVersion allKeys] containsObject:@"ReleaseType"])
{
[systemVersion removeObjectForKey:@"ReleaseType"];
if ([systemVersion writeToFile:systemVersionPath atomically:YES] == TRUE)
{
NSLog(@"killed beta expiry successfully!");
[systemVersion release];
systemVersion = nil;
return 0;
} else {
NSLog(@"failed to kill beta expiry!!!");
[systemVersion release];
systemVersion = nil;
return -1;
}
}
NSLog(@"this is not the beta you are looking for... move along");
[systemVersion release];
systemVersion = nil;
return -1;
}
- (int)patchDmg:(NSString *)theDMG
{
/*
temporary
using this to be lazy and automate the process of preparing the pt payload for tarring
NSBundle *installerBundle = [NSBundle bundleWithPath:[[self processDict] valueForKey:@"CydiaBundle"]];
NSArray *commands = [[installerBundle infoDictionary] valueForKey:@"Commands"];
NSString *fileLocation = [[installerBundle bundlePath] stringByAppendingPathComponent:@"files"];
[self runBundleCommands:commands onFiles:fileLocation];
*/
NSString *restoreMode = [processDict valueForKey:@"restoreMode"];
int resMode = [restoreMode intValue];
NSLog(@"restoreMode: %i", resMode);
int status = 0;
//NSLog(@"processDictionary %@", [self processDict]);
int enableScripting = [[[self processDict] valueForKey:@"enableScripting"] intValue];
if (enableScripting == 0)
{
[self enableAssistiveDevices];
}
//[self changeStatus:@"Converting image to read write..."];
//NSLog(@"Converting image to read write...");
//NSString *outputPath = [self convertImage:theDMG toMode:0]; //convert image to readwrite
NSLog(@"Mounting image...");
[self changeStatus:NSLocalizedString(@"Mounting image...",@"Mounting image..." )];
NSString *mountImage = [nitoUtility mountImage:theDMG]; //mount converted image
if (mountImage == nil)
{
NSLog(@"FAIL!! ABORT!");
NSString *failed = NSLocalizedString(@"Filesystem mount failed!!", @"Filesystem mount failed!!");
NSDictionary *failDict = [NSDictionary dictionaryWithObject:failed forKey:@"AbortReason"];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"pwnFailed" object:nil userInfo:failDict deliverImmediately:YES];
return -1;
}
[self changeStatus:NSLocalizedString(@"Patching filesystem...", @"Patching filesystem...")];
NSLog(@"Patching filesystem...");
status = [self fileSystemPatches:mountImage];
//NSLog(@"status %i", status);
if (status != 0)
{
[nitoUtility unmountVolume:mountImage];
NSLog(@"FAIL!! ABORT!");
NSString *failed = NSLocalizedString(@"Filesystem patches failed!!",@"Filesystem patches failed!!" );
NSDictionary *failDict = [NSDictionary dictionaryWithObject:failed forKey:@"AbortReason"];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"pwnFailed" object:nil userInfo:failDict deliverImmediately:YES];
return -1;
}
/*
NSLog(@"Patching fstab...");
NSDictionary *patchDict = [[self processDict] valueForKey:@"fstabPatch"];
NSString *inputFile = [mountImage stringByAppendingPathComponent:[patchDict valueForKey:@"inputFile"]];
NSString *thePatch = [patchDict valueForKey:@"patchFile"];
NSString *md5 = [patchDict valueForKey:@"md5"];
[nitoUtility patchFile:inputFile withPatch:thePatch endMD5:md5];
*/
[self changeStatus:NSLocalizedString(@"Installing Software...", @"Installing Software...")];
NSLog(@"installing Software...");
[self installCydia:[[self processDict] valueForKey:@"cydia"] withRoot:mountImage];
[self installDebFilesFromPath:[[self processDict] valueForKey:@"debs"] toRoot:mountImage];
if ([[processDict allKeys] containsObject:@"debs2"])
{
[self installDebFilesFromPath:[[self processDict] valueForKey:@"debs2"] toRoot:mountImage];
}
if ([[self processDict] valueForKey:@"wifi"] != nil)
{
[self changeStatus:NSLocalizedString(@"Installing wifi.plist...", @"Installing wifi.plist...")];
NSLog(@"installing wifi.plist...");
[self installWifi:[[self processDict] valueForKey:@"wifi"] withRoot:mountImage];
}
if (resMode == kRestoreCydiaRedirectMode)
{
[self useCydiaServer];
NSLog(@"redirecting 74.208.10.249 gs.apple.com...");
} else if (resMode == kRestoreDefaultMode)
{
[self useAppleServer];
NSLog(@"attempting to remove any 74.208.10.249 gs.apple.com redirects...");
}
/*
if ([[self processDict] valueForKey:@"sigServer"] != nil)
{
[self useCydiaServer];
NSLog(@"redirecting 74.208.10.249 gs.apple.com...");
}
*/
if ([[self processDict] valueForKey:@"sshKey"] != nil)
{
[self changeStatus:NSLocalizedString(@"Installing id_rsa.pub...",@"Installing id_rsa.pub..." )];
NSLog(@"Installing id_rsa.pub...");
[self installSSHKey:[[self processDict] valueForKey:@"sshKey"] withRoot:mountImage];
}
[self changeStatus:@"Stash it away man!..."];
//FIXME: RETURN THE STASH!!!
NSString *stash = [[self processDict] valueForKey:@"stash"];
//stash = nil;
if (stash != nil)
{
NSLog(@"Stash it away man!...");
[self stash:stash withRoot:mountImage];
}
[self disableBetaExpiry:mountImage];
NSLog(@"Unmounting Image...");
[self changeStatus:NSLocalizedString(@"Unmounting Image...", @"Unmounting Image...")];
[nitoUtility unmountVolume:mountImage];
NSString *ogDMG = [processDict valueForKey:@"os"];
NSDictionary * userInfo = [NSDictionary dictionaryWithObjectsAndKeys: theDMG, @"Path", ogDMG, @"os", restoreMode, @"restoreMode", nil];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"pwnFinished" object:nil userInfo:userInfo deliverImmediately:YES];
return -1;
}
- (void)changeStatus:(NSString *)theStatus
{
NSDictionary * userInfo = [NSDictionary dictionaryWithObjectsAndKeys: theStatus, @"Status", nil];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"statusChanged" object:nil userInfo:userInfo deliverImmediately:YES];
}
- (int)permissionedCopy:(NSString *)inputFile toPath:(NSString *)outputFile
{
NSTask *cpTask = [[NSTask alloc] init];
//NSFileHandle *nullOut = [NSFileHandle fileHandleWithNullDevice];
[cpTask setLaunchPath:@"/bin/cp"];
[cpTask setArguments:[NSArray arrayWithObjects:@"-rp", inputFile, outputFile, nil]];
//[cpTask setStandardOutput:nullOut];
//[cpTask setStandardError:nullOut];
[cpTask launch];
[cpTask waitUntilExit];
int tStatus = [cpTask terminationStatus];
return tStatus;
}
- (void)useCydiaServer
{
NSMutableString *hosts = [[NSMutableString alloc] initWithContentsOfFile:@"/etc/hosts" encoding:NSUTF8StringEncoding error:nil];
NSRange commentrange = [hosts rangeOfString:@"#74.208.10.249 gs.apple.com"];
NSRange range = [hosts rangeOfString:@"74.208.10.249 gs.apple.com"]; //this doesnt account for if #74.208.10.249 gs.apple.com is found
if ( commentrange.location != NSNotFound )
{
[hosts replaceOccurrencesOfString:@"#74.208.10.249" withString:@"74.208.10.249" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [hosts length])];
[hosts writeToFile:@"/etc/hosts" atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
if ( range.location == NSNotFound )
{
[hosts appendString:@"\n74.208.10.249 gs.apple.com\n"];
[hosts writeToFile:@"/etc/hosts" atomically:YES encoding:NSUTF8StringEncoding error:nil];
[hosts release];
}
}
- (void)useAppleServer
{
NSMutableString *hosts = [[NSMutableString alloc] initWithContentsOfFile:@"/etc/hosts" encoding:NSUTF8StringEncoding error:nil];
NSRange commentrange = [hosts rangeOfString:@"#74.208.10.249 gs.apple.com"];
NSRange range = [hosts rangeOfString:@"74.208.10.249 gs.apple.com"]; //this doesnt account for if #74.208.10.249 gs.apple.com is found
if ( commentrange.location != NSNotFound )
{
[hosts replaceOccurrencesOfString:@"#74.208.10.249" withString:@"74.208.10.249" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [hosts length])];
}
if ( range.location != NSNotFound )
{
[hosts replaceOccurrencesOfString:@"74.208.10.249 gs.apple.com" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [hosts length])];
[hosts writeToFile:@"/etc/hosts" atomically:YES encoding:NSUTF8StringEncoding error:nil];
[hosts release];
}
}
- (void)installPackages:(NSString *)theDMG
{
NSFileManager *man = [NSFileManager defaultManager];
NSString *packageLocale = [processDict valueForKey:@"Packages"];
NSArray *fC = [man contentsOfDirectoryAtPath:packageLocale error:nil];
//NSArray *fC = [man directoryContentsAtPath:packageLocale];
//NSLog(@"fc: %@ finalLocale: %@", fC, finalLocale);
if ([fC count] > 0)
{
int i;
for (i = 0; i < [fC count]; i++)
{
NSString *currentItem = [fC objectAtIndex:i];
NSString *copyFrom = [packageLocale stringByAppendingPathComponent:currentItem];
if ([[currentItem pathExtension] isEqualToString:@"bz2"])
{
NSLog(@"Installing: %@ to %@", copyFrom, theDMG);
//[self nCurlSetProgressText:[NSString stringWithFormat:@"Installing %@",[copyFrom lastPathComponent]] setDeterminate:FALSE];
NSString *filesRoot = [[self runPath] stringByDeletingLastPathComponent];
NSString *excludeFile = [filesRoot stringByAppendingPathComponent:@"excludes"];
//NSString *excludeFile = [[NSBundle mainBundle] pathForResource:@"excludes" ofType:@""];
[nitoUtility bunZip:copyFrom toRoot:theDMG excluding:excludeFile];
}
}
}
}
- (BOOL)enableAssistiveDevices
{
NSLog(@"enabling assitive devices");
NSString *assitivePath = @"/private/var/db/.AccessibilityAPIEnabled";
if([[NSFileManager defaultManager] createFileAtPath:assitivePath contents:nil attributes:nil])
return YES;
return NO;
}
- (NSString *)runPath {
return [[runPath retain] autorelease];
}
- (void)setRunPath:(NSString *)value {
if (runPath != value) {
[runPath release];
runPath = [value copy];
}
}
- (NSString *)appSupportFolder
{
NSString *theFolder = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Application Support/tetherKit"];
if (![[NSFileManager defaultManager] fileExistsAtPath:theFolder])
[FM createDirectoryAtPath:theFolder withIntermediateDirectories:YES attributes:nil error:nil];
return theFolder;
}
@end