-
Notifications
You must be signed in to change notification settings - Fork 79
/
main.mm
1853 lines (1627 loc) · 94.4 KB
/
main.mm
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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <dlfcn.h>
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
#import "ZipArchive/ZipArchive.h"
#import "UIDevice-Capabilities/UIDevice-Capabilities.h"
#define EXECUTABLE_VERSION @"3.4.1"
#define KEY_INSTALL_TYPE @"User"
#define KEY_SDKPATH "/System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation"
#define IPA_FAILED -1
typedef int (*MobileInstallationInstall)(NSString *path, NSDictionary *dict, void *na, NSString *backpath);
typedef int (*MobileInstallationUninstall)(NSString *bundleID, NSDictionary *dict, void *na);
@interface LSApplicationWorkspace : NSObject
+ (LSApplicationWorkspace *)defaultWorkspace;
- (BOOL)installApplication:(NSURL *)path withOptions:(NSDictionary *)options;
- (BOOL)uninstallApplication:(NSString *)identifier withOptions:(NSDictionary *)options;
- (BOOL)applicationIsInstalled:(NSString *)appIdentifier;
- (NSArray *)allInstalledApplications;
- (NSArray *)allApplications;
- (NSArray *)applicationsOfType:(unsigned int)appType; // 0 for user, 1 for system
@end
@interface LSApplicationProxy : NSObject
+ (LSApplicationProxy *)applicationProxyForIdentifier:(id)appIdentifier;
@property(readonly) NSString * applicationIdentifier;
@property(readonly) NSString * bundleVersion;
@property(readonly) NSString * bundleExecutable;
@property(readonly) NSArray * deviceFamily;
@property(readonly) NSURL * bundleContainerURL;
@property(readonly) NSString * bundleIdentifier;
@property(readonly) NSURL * bundleURL;
@property(readonly) NSURL * containerURL;
@property(readonly) NSURL * dataContainerURL;
@property(readonly) NSString * localizedShortName;
@property(readonly) NSString * localizedName;
@property(readonly) NSString * shortVersionString;
@end
static NSString *SystemVersion = nil;
static int DeviceModel = 0;
static BOOL isUninstall = NO;
static BOOL isGetInfo = NO;
static BOOL isListing = NO;
static BOOL isBackup = NO;
static BOOL isBackupFull = NO;
static BOOL cleanInstall = NO;
static int quietInstall = 0; //0 is show all outputs, 1 is to show only errors, 2 is to show nothing
static BOOL forceInstall = NO;
static BOOL removeMetadata = NO;
static BOOL deleteFile = NO;
static BOOL notRestore = NO;
static NSString * randomStringInLength(int len) {
NSString *ret = @"";
NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (int i=0; i<len; i++)
ret = [NSString stringWithFormat:@"%@%C", ret, [letters characterAtIndex:arc4random() % [letters length]]];
return ret;
}
static BOOL removeAllContentsUnderPath(NSString *path) {
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isDirectory;
if ([fileMgr fileExistsAtPath:path isDirectory:&isDirectory]) {
if (isDirectory) {
NSArray *dirContents = [fileMgr contentsOfDirectoryAtPath:path error:nil];
BOOL allRemoved = YES;
for (int unsigned j=0; j<[dirContents count]; j++) {
if (![fileMgr removeItemAtPath:[path stringByAppendingPathComponent:[dirContents objectAtIndex:j]] error:nil])
allRemoved = NO;
}
if (!allRemoved)
return NO;
if (![fileMgr removeItemAtPath:path error:nil])
return NO;
}
}
return YES;
}
static void setPermissionsForPath(NSString *path) {
NSFileManager *fileMgr = [NSFileManager defaultManager];
//Set root folder's attributes
NSDictionary *directoryAttributes = [fileMgr attributesOfItemAtPath:path error:nil];
NSMutableDictionary *defaultDirectoryAttributes = [NSMutableDictionary dictionaryWithCapacity:[directoryAttributes count]];
[defaultDirectoryAttributes setDictionary:directoryAttributes];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileGroupOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileGroupOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithShort:0755] forKey:NSFilePosixPermissions];
[fileMgr setAttributes:defaultDirectoryAttributes ofItemAtPath:path error:nil];
for (NSString *subPath in [fileMgr contentsOfDirectoryAtPath:path error:nil]) {
NSDictionary *attributes = [fileMgr attributesOfItemAtPath:[path stringByAppendingPathComponent:subPath] error:nil];
if ([[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeRegular]) {
NSMutableDictionary *defaultAttributes = [NSMutableDictionary dictionaryWithDictionary:directoryAttributes];
[defaultAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileOwnerAccountID];
[defaultAttributes setObject:@"mobile" forKey:NSFileOwnerAccountName];
[defaultAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileGroupOwnerAccountID];
[defaultAttributes setObject:@"mobile" forKey:NSFileGroupOwnerAccountName];
[defaultAttributes setObject:[NSNumber numberWithShort:0644] forKey:NSFilePosixPermissions];
[fileMgr setAttributes:defaultAttributes ofItemAtPath:[path stringByAppendingPathComponent:subPath] error:nil];
} else if ([[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory])
setPermissionsForPath([path stringByAppendingPathComponent:subPath]);
else {
//Ignore symblic links
}
}
}
static void setExecutables(NSString *dirPath) {
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isDir;
if (![fileMgr fileExistsAtPath:dirPath isDirectory:&isDir])
return;
if (!isDir)
return;
NSString *infoPlistPath = [dirPath stringByAppendingPathComponent:@"Info.plist"];
if ([fileMgr fileExistsAtPath:infoPlistPath]) {
NSDictionary *infoDict = [NSDictionary dictionaryWithContentsOfFile:infoPlistPath];
NSString *exeName = [infoDict objectForKey:@"CFBundleExecutable"];
NSString *exePath = [dirPath stringByAppendingPathComponent:exeName];
if ([fileMgr fileExistsAtPath:exePath]) {
NSDictionary *attributes = [fileMgr attributesOfItemAtPath:exePath error:nil];
if ([[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeRegular]) {
NSMutableDictionary *executableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes];
[executableAttributes setObject:[NSNumber numberWithShort:0755] forKey:NSFilePosixPermissions];
[fileMgr setAttributes:executableAttributes ofItemAtPath:exePath error:nil];
}
}
}
for (NSString *subPath in [fileMgr contentsOfDirectoryAtPath:dirPath error:nil]) {
NSString *subDirPath = [dirPath stringByAppendingPathComponent:subPath];
NSDictionary *attributes = [fileMgr attributesOfItemAtPath:subDirPath error:nil];
if ([[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory])
setExecutables(subDirPath);
}
}
static int versionCompare(NSString *ver1, NSString *ver2) {
//-1: ver1<ver2; 0: ver1=ver2; 1: ver1>ver2
BOOL isEmpty1 = (ver1 == nil || [ver1 length] == 0);
BOOL isEmpty2 = (ver2 == nil || [ver2 length] == 0);
if (isEmpty1 && isEmpty2)
return 0;
else if (isEmpty1 && !isEmpty2)
return -1;
else if (!isEmpty1 && isEmpty2)
return 1;
else {
NSArray *components1 = [ver1 componentsSeparatedByString:@"."];
NSArray *components2 = [ver2 componentsSeparatedByString:@"."];
int count = [components1 count] > [components2 count] ? [components2 count] : [components1 count];
for (int i=0; i<count; i++) {
int num1 = [[components1 objectAtIndex:i] intValue];
int num2 = [[components2 objectAtIndex:i] intValue];
if (num1 < num2)
return -1;
else if (num1 > num2)
return 1;
else {
if ([[components1 objectAtIndex:i] isEqualToString:[components2 objectAtIndex:i]])
continue;
else
return [[components1 objectAtIndex:i] compare:[components2 objectAtIndex:i]] == NSOrderedDescending ? 1 : -1;
}
}
if ([components1 count] != [components2 count])
return [components1 count] > [components2 count] ? 1 : -1;
else
return 0;
}
}
static NSArray *getInstalledApplications() {
if (kCFCoreFoundationVersionNumber < 1140.10) {
NSDictionary *mobileInstallationPlist = [NSDictionary dictionaryWithContentsOfFile:@"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
NSDictionary *installedAppDict = (NSDictionary*)[mobileInstallationPlist objectForKey:@"User"];
NSArray * identifiers = [[installedAppDict allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
return identifiers;
} else {
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
if (LSApplicationWorkspace_class) {
LSApplicationWorkspace *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
if (workspace) {
NSArray *allApps = [workspace applicationsOfType:0];
NSMutableArray *identifiers = [NSMutableArray arrayWithCapacity:[allApps count]];
for (LSApplicationProxy *appBundle in allApps)
[identifiers addObject:appBundle.bundleIdentifier];
return [identifiers sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
}
}
return nil;
}
static NSString *formatDictValue(NSObject *object) {
return object ? (NSString *)object : @"";
}
static NSString *getBestString(NSString *main, NSString *minor) {
return (minor && [minor length] > 0) ? minor : (main ? main : @"");
}
static NSDictionary *getInstalledAppInfo(NSString *appIdentifier) {
if (kCFCoreFoundationVersionNumber < 1140.10) {
NSDictionary *mobileInstallationPlist = [NSDictionary dictionaryWithContentsOfFile:@"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
NSDictionary *installedAppDict = (NSDictionary*)[mobileInstallationPlist objectForKey:@"User"];
NSDictionary *appInfo = [installedAppDict objectForKey:appIdentifier];
if (appInfo) {
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithCapacity:8];
[info setObject:formatDictValue([appInfo objectForKey:@"CFBundleIdentifier"]) forKey:@"APP_ID"];
[info setObject:formatDictValue([appInfo objectForKey:@"Container"]) forKey:@"BUNDLE_PATH"];
[info setObject:formatDictValue([appInfo objectForKey:@"Path"]) forKey:@"APP_PATH"];
[info setObject:formatDictValue([appInfo objectForKey:@"Container"]) forKey:@"DATA_PATH"];
[info setObject:formatDictValue([appInfo objectForKey:@"CFBundleVersion"]) forKey:@"VERSION"];
[info setObject:formatDictValue([appInfo objectForKey:@"CFBundleShortVersionString"]) forKey:@"SHORT_VERSION"];
[info setObject:formatDictValue([appInfo objectForKey:@"CFBundleName"]) forKey:@"NAME"];
[info setObject:formatDictValue([appInfo objectForKey:@"CFBundleDisplayName"]) forKey:@"DISPLAY_NAME"];
return info;
}
} else {
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
if (LSApplicationWorkspace_class) {
LSApplicationWorkspace *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
if (workspace && [workspace applicationIsInstalled:appIdentifier]) {
Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy");
if (LSApplicationProxy_class) {
LSApplicationProxy *app = [LSApplicationProxy_class applicationProxyForIdentifier:appIdentifier];
if (app) {
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithCapacity:9];
[info setObject:formatDictValue(app.bundleIdentifier) forKey:@"APP_ID"];
[info setObject:formatDictValue([app.bundleContainerURL path]) forKey:@"BUNDLE_PATH"];
[info setObject:formatDictValue([app.bundleURL path]) forKey:@"APP_PATH"];
[info setObject:formatDictValue([app.dataContainerURL path]) forKey:@"DATA_PATH"];
[info setObject:formatDictValue(app.bundleVersion) forKey:@"VERSION"];
[info setObject:formatDictValue(app.shortVersionString) forKey:@"SHORT_VERSION"];
[info setObject:formatDictValue(app.localizedName) forKey:@"NAME"];
[info setObject:formatDictValue(app.localizedShortName) forKey:@"DISPLAY_NAME"];
return info;
}
}
}
}
}
return nil;
}
static int installApp(NSString *ipaPath, NSString *ipaId) {
int ret = -1;
if (kCFCoreFoundationVersionNumber < 1140.10) {
void *lib = dlopen(KEY_SDKPATH, RTLD_LAZY);
if (lib) {
MobileInstallationInstall install = (MobileInstallationInstall)dlsym(lib, "MobileInstallationInstall");
if (install)
ret = install(ipaPath, [NSDictionary dictionaryWithObject:KEY_INSTALL_TYPE forKey:@"ApplicationType"], 0, ipaPath);
dlclose(lib);
}
} else {
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
if (LSApplicationWorkspace_class) {
LSApplicationWorkspace *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
if (workspace && [workspace installApplication:[NSURL fileURLWithPath:ipaPath] withOptions:[NSDictionary dictionaryWithObject:ipaId forKey:@"CFBundleIdentifier"]])
ret = 0;
}
}
return ret;
}
static BOOL uninstallApplication(NSString *appIdentifier) {
if (kCFCoreFoundationVersionNumber < 1140.10) {
void *lib = dlopen(KEY_SDKPATH, RTLD_LAZY);
if (lib) {
MobileInstallationUninstall uninstall = (MobileInstallationUninstall)dlsym(lib, "MobileInstallationUninstall");
if (uninstall)
return 0 == uninstall(appIdentifier, nil, nil);
dlclose(lib);
}
} else {
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
if (LSApplicationWorkspace_class) {
LSApplicationWorkspace *workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];
if (workspace && [workspace uninstallApplication:appIdentifier withOptions:nil])
return YES;
}
}
return NO;
}
int main (int argc, char **argv, char **envp) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
freopen("/dev/null", "w", stderr); //Suppress output from NSLog
//Get system info
SystemVersion = [UIDevice currentDevice].systemVersion;
NSString *deviceString = [UIDevice currentDevice].model;
if ([deviceString isEqualToString:@"iPhone"] || [deviceString isEqualToString:@"iPod touch"])
DeviceModel = 1;
else if ([deviceString isEqualToString:@"iPad"])
DeviceModel = 2;
else
DeviceModel = 3; //Apple TV maybe?
//Process parameters
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
if ([arguments count] < 1) {
[pool release];
return IPA_FAILED;
}
NSString *executableName = [[arguments objectAtIndex:0] lastPathComponent];
NSString *helpString = [NSString stringWithFormat:@"Usage: %@ [OPTION]... [FILE]...\n %@ -{bB} [APP_ID] [-o OUTPUT_PATH]\n %@ -i [APP_ID]...\n %@ -l\n %@ -u [APP_ID]...\n\n\nOptions:\n -a Show tool about information.\n -b Back up application with given identifier to IPA.\n -B Back up application with given identifier and its documents and settings to IPA.\n -c Perform a clean install.\n If the application has already been installed, the existing documents and other resources will be cleared.\n This implements -n automatically.\n -d Delete IPA file(s) after installation.\n -f Force installation, do not check capabilities and system version.\n Installed application may not work properly.\n -h Display this usage information.\n -i Display information of installed application(s).\n -l List identifiers of all installed App Store applications.\n -n Do not restore saved documents and other resources.\n -o Output IPA to specified path, or the IPA will be saved under /var/mobile/Documents/.\n -q Quiet mode, suppress all normal outputs.\n -Q Quieter mode, suppress all outputs including errors.\n -r Remove iTunesMetadata.plist after installation.\n -u Uninstall application with given identifier(s).", executableName, executableName, executableName, executableName, executableName];
NSDate *today = [NSDate date];
NSDateFormatter *currentFormatter = [[NSDateFormatter alloc] init];
[currentFormatter setDateFormat:@"yyyy"];
NSString *aboutString = [NSString stringWithFormat:@"About %@\nInstall IPAs via command line or back up/browse/uninstall installed applications.\nVersion: %@\nAuthor: Merlin Mao\n\nZipArchive from Matt Connolly\nFSSystemHasCapability from Ryan Petrich\n\nCopyright \u00A9 2012%@ Merlin Mao. All rights reserved.", executableName, EXECUTABLE_VERSION, [[currentFormatter stringFromDate:today] isEqualToString:@"2012"] ? @"" : [@"-" stringByAppendingString:[currentFormatter stringFromDate:today]]];
[currentFormatter release];
if ([arguments count] == 1) {
printf("%s\n", [helpString cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return 0;
}
NSFileManager *fileMgr = [NSFileManager defaultManager];
if ([arguments count] >= 3) {
NSMutableArray *identifiers = [NSMutableArray array];
NSString *op1 = [arguments objectAtIndex:1];
if ([op1 isEqualToString:@"-uq"] || [op1 isEqualToString:@"-qu"]) {
isUninstall = YES;
quietInstall = 1;
for (unsigned int i=2; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
if ([op1 isEqualToString:@"-uQ"] || [op1 isEqualToString:@"-Qu"]) {
isUninstall = YES;
quietInstall = 2;
for (unsigned int i=2; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
NSString *op2 = [arguments objectAtIndex:2];
if ([op1 isEqualToString:@"-u"]) {
isUninstall = YES;
if ([op2 isEqualToString:@"-q"]) {
quietInstall = 1;
for (unsigned int i=3; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
else if ([op2 isEqualToString:@"-Q"]) {
quietInstall = 2;
for (unsigned int i=3; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
} else {
for (unsigned int i=2; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
}
if ([op1 isEqualToString:@"-i"]) {
isGetInfo = YES;
for (unsigned int i=2; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
if ([op2 isEqualToString:@"-u"]) {
if ([op1 isEqualToString:@"-q"]) {
isUninstall = YES;
quietInstall = 1;
for (unsigned int i=3; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
if ([op1 isEqualToString:@"-Q"]) {
quietInstall = 2;
for (unsigned int i=3; i<[arguments count]; i++)
[identifiers addObject:[arguments objectAtIndex:i]];
}
}
if (isGetInfo) {
if ([identifiers count] < 1) {
printf("You must specify at least one application identifier.\n");
[pool release];
return IPA_FAILED;
}
NSArray *installedApps = getInstalledApplications();
for (unsigned int i=0; i<[identifiers count]; i++) {
NSString *identifier = [identifiers objectAtIndex:i];
if ([installedApps containsObject:identifier]) {
NSDictionary *installedAppInfo = getInstalledAppInfo(identifier);
NSString *appDirPath = [installedAppInfo objectForKey:@"BUNDLE_PATH"];
NSString *appPath = [installedAppInfo objectForKey:@"APP_PATH"];
NSString *dataPath = [installedAppInfo objectForKey:@"DATA_PATH"];
NSString *appName = [installedAppInfo objectForKey:@"NAME"];
NSString *appDisplayName = [installedAppInfo objectForKey:@"DISPLAY_NAME"];
NSString *appVersion = [installedAppInfo objectForKey:@"VERSION"];
NSString *appShortVersion = [installedAppInfo objectForKey:@"SHORT_VERSION"];
printf("Identifier: %s\n", [identifier cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appVersion length] > 0)
printf("Version: %s\n", [appVersion cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appShortVersion length] > 0)
printf("Short Version: %s\n", [appShortVersion cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appName length] > 0)
printf("Name: %s\n", [appName cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appDisplayName length] > 0)
printf("Display Name: %s\n", [appDisplayName cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appDirPath length] > 0)
printf("Bundle: %s\n", [appDirPath cStringUsingEncoding:NSUTF8StringEncoding]);
if ([appPath length] > 0)
printf("Application: %s\n", [appPath cStringUsingEncoding:NSUTF8StringEncoding]);
if ([dataPath length] > 0)
printf("Data: %s\n", [dataPath cStringUsingEncoding:NSUTF8StringEncoding]);
} else {
if (quietInstall < 2)
printf("Application \"%s\" is not installed.\n", [identifier cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (i < [identifiers count] - 1)
printf("\n");
}
return 0;
}
if (isUninstall) {
if ([identifiers count] < 1) {
printf("You must specify at least one application identifier.\n");
[pool release];
return IPA_FAILED;
} else {
NSArray *installedApps = getInstalledApplications();
for (unsigned int i=0; i<[identifiers count]; i++) {
if ([installedApps containsObject:[identifiers objectAtIndex:i]]) {
printf("Removing application \"%s\".\n", [[identifiers objectAtIndex:i] cStringUsingEncoding:NSUTF8StringEncoding]);
if (uninstallApplication([identifiers objectAtIndex:i])) {
if (quietInstall == 0)
printf("Successfully removed application \"%s\".\n", [[identifiers objectAtIndex:i] cStringUsingEncoding:NSUTF8StringEncoding]);
} else {
if (quietInstall < 2)
printf("Failed to remove application \"%s\".\n", [[identifiers objectAtIndex:i] cStringUsingEncoding:NSUTF8StringEncoding]);
}
} else {
if (quietInstall < 2)
printf("Application \"%s\" is not installed.\n", [[identifiers objectAtIndex:i] cStringUsingEncoding:NSUTF8StringEncoding]);
}
}
[pool release];
return 0;
}
}
NSString *identifier = nil, *savePath = nil;
if ([op1 isEqualToString:@"-bq"] || [op1 isEqualToString:@"-qb"]) {
isBackup = YES;
quietInstall = 1;
if ([arguments count] == 5) {
identifier = [arguments objectAtIndex:2];
NSString *opOutput = [arguments objectAtIndex:3];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:4];
} else if ([arguments count] != 3) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:2];
}
if ([op1 isEqualToString:@"-bQ"] || [op1 isEqualToString:@"-Qb"]) {
isBackup = YES;
quietInstall = 2;
if ([arguments count] == 5) {
identifier = [arguments objectAtIndex:2];
NSString *opOutput = [arguments objectAtIndex:3];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:4];
} else if ([arguments count] != 3) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:2];
}
if ([op1 isEqualToString:@"-Bq"] || [op1 isEqualToString:@"-qB"]) {
isBackupFull = YES;
quietInstall = 1;
if ([arguments count] == 5) {
identifier = [arguments objectAtIndex:2];
NSString *opOutput = [arguments objectAtIndex:3];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:4];
} else if ([arguments count] != 3) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:2];
}
if ([op1 isEqualToString:@"-BQ"] || [op1 isEqualToString:@"-QB"]) {
isBackupFull = YES;
quietInstall = 2;
if ([arguments count] == 5) {
identifier = [arguments objectAtIndex:2];
NSString *opOutput = [arguments objectAtIndex:3];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:4];
} else if ([arguments count] != 3) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:2];
}
if ([op1 isEqualToString:@"-b"] || [op1 isEqualToString:@"-B"]) {
if ([op1 isEqualToString:@"-b"])
isBackup = YES;
else
isBackupFull = YES;
if ([op2 isEqualToString:@"-q"] || [op2 isEqualToString:@"-Q"]) {
quietInstall = [op2 isEqualToString:@"-q"] ? 1 : 2;
if ([arguments count] == 6) {
identifier = [arguments objectAtIndex:3];
NSString *opOutput = [arguments objectAtIndex:4];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:5];
} else if ([arguments count] != 4) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:3];
} else {
if ([arguments count] == 5) {
identifier = [arguments objectAtIndex:2];
NSString *opOutput = [arguments objectAtIndex:3];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:4];
} else if ([arguments count] != 3) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:2];
}
}
if ([op2 isEqualToString:@"-b"] || [op2 isEqualToString:@"-B"]) {
if ([op1 isEqualToString:@"-q"] || [op1 isEqualToString:@"-Q"]) {
if ([op2 isEqualToString:@"-b"])
isBackup = YES;
else
isBackupFull = YES;
quietInstall = [op1 isEqualToString:@"-q"] ? 1 : 2;
if ([arguments count] == 6) {
identifier = [arguments objectAtIndex:3];
NSString *opOutput = [arguments objectAtIndex:4];
if (![opOutput isEqualToString:@"-o"]) {
printf("Invalid parameters.\n");
[pool release];
return 0;
}
savePath = [arguments objectAtIndex:5];
} else if ([arguments count] != 4) {
printf("Invalid parameters.\n");
[pool release];
return 0;
} else
identifier = [arguments objectAtIndex:3];
}
}
if (isBackup || isBackupFull) {
if ([identifier length] < 1) {
printf("You must specify an application identifier.\n");
[pool release];
return 0;
}
if (savePath) {
if (![savePath hasPrefix:@"/"])
savePath = [[fileMgr currentDirectoryPath] stringByAppendingPathComponent:savePath];
savePath = [savePath stringByStandardizingPath];;
}
if ([fileMgr fileExistsAtPath:savePath]) {
printf("%s already exists.\n", [savePath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
NSDictionary *installedAppInfo = getInstalledAppInfo(identifier);
if (!installedAppInfo) {
if (quietInstall < 2)
printf("Application \"%s\" is not installed.\n", [identifier cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
} else
printf("Backing up application with identifier \"%s\"...\n", [identifier cStringUsingEncoding:NSUTF8StringEncoding]);
NSString *appDirPath = [installedAppInfo objectForKey:@"BUNDLE_PATH"];
NSString *appPath = [installedAppInfo objectForKey:@"APP_PATH"];
NSString *dataPath = [installedAppInfo objectForKey:@"DATA_PATH"];
NSString *appName = [installedAppInfo objectForKey:@"NAME"];
NSString *appDisplayName = [installedAppInfo objectForKey:@"DISPLAY_NAME"];
NSString *appVersion = [installedAppInfo objectForKey:@"VERSION"];
NSString *appShortVersion = [installedAppInfo objectForKey:@"SHORT_VERSION"];
if (!appDisplayName || [appDisplayName length] < 1)
appDisplayName = appName;
if (!appShortVersion || [appShortVersion length] < 1)
appShortVersion = appVersion;
BOOL isDirectory;
if (![fileMgr fileExistsAtPath:appDirPath isDirectory:&isDirectory]) {
if (quietInstall < 2)
printf("Cannot find %s.\n", [appDirPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
if (!isDirectory) {
if (quietInstall < 2)
printf("%s is not a directory.\n", [appDirPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
if (![fileMgr fileExistsAtPath:appPath isDirectory:&isDirectory]) {
if (quietInstall < 2)
printf("Cannot find %s.\n", [appPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
if (!isDirectory) {
if (quietInstall < 2)
printf("%s is not a directory.\n", [appPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
if (isBackupFull) {
if (![fileMgr fileExistsAtPath:dataPath isDirectory:&isDirectory]) {
if (quietInstall < 2)
printf("Cannot find %s.\n", [dataPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
if (!isDirectory) {
if (quietInstall < 2)
printf("%s is not a directory.\n", [dataPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return IPA_FAILED;
}
}
//Clean before
NSArray *filesInTemp = [fileMgr contentsOfDirectoryAtPath:NSTemporaryDirectory() error:nil];
for (NSString *file in filesInTemp) {
file = [NSTemporaryDirectory() stringByAppendingPathComponent:[file lastPathComponent]];
if ([[file lastPathComponent] hasPrefix:@"com.autopear.ipainstaller."] && ![fileMgr removeItemAtPath:file error:nil]) {
if (quietInstall < 2)
printf("Failed to delete %s.\n", [file cStringUsingEncoding:NSUTF8StringEncoding]);
}
}
//Create temp path
NSString *workPath = nil;
while (YES) {
workPath = [NSString stringWithFormat:@"com.autopear.ipainstaller.%@", randomStringInLength(6)];
workPath = [NSTemporaryDirectory() stringByAppendingPathComponent:workPath];
if (![fileMgr fileExistsAtPath:workPath])
break;
}
if(![fileMgr createDirectoryAtPath:workPath withIntermediateDirectories:YES attributes:nil error:NULL] ) {
if (quietInstall < 2)
printf("Failed to create workspace.\n");
[pool release];
return IPA_FAILED;
}
ZipArchive *ipaArchive = [[ZipArchive alloc] init];
// APPEND_STATUS_ADDINZIP = 2
if (![ipaArchive openZipFile2:[workPath stringByAppendingPathComponent:@"temp.zip"] withZipModel:APPEND_STATUS_ADDINZIP]) {
[ipaArchive release];
if (quietInstall < 2)
printf("Failed to create IPA file.\n");
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
if (![ipaArchive addDirectoryToZip:appPath toPathInZip:[NSString stringWithFormat:@"Payload/%@/", [appPath lastPathComponent]]]) {
if (quietInstall < 2)
printf("Failed to create ipa file.\n");
[ipaArchive release];
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
if ([fileMgr fileExistsAtPath:[appDirPath stringByAppendingPathComponent:@"iTunesArtwork"]])
[ipaArchive addFileToZip:[appDirPath stringByAppendingPathComponent:@"iTunesArtwork"] newname:@"iTunesArtwork"];
if ([fileMgr fileExistsAtPath:[appDirPath stringByAppendingPathComponent:@"iTunesMetadata.plist"]])
[ipaArchive addFileToZip:[appDirPath stringByAppendingPathComponent:@"iTunesMetadata.plist"] newname:@"iTunesMetadata.plist"];
if (isBackupFull) {
if (quietInstall == 0)
printf("Backing up application data...\n");
NSArray *dataContents = [fileMgr contentsOfDirectoryAtPath:dataPath error:nil];
for (NSString *file in dataContents) {
if ([file hasSuffix:@".app"] ||
[file isEqualToString:@".com.apple.mobile_container_manager.metadata.plist"] ||
[file isEqualToString:@".com.apple.mobileinstallation.placeholder"] ||
[file isEqualToString:@".GlobalPreferences.plist"] ||
[file isEqualToString:@"com.apple.PeoplePicker.plist"] ||
[file isEqualToString:@"iTunesArtwork"] ||
[file isEqualToString:@"iTunesMetadata.plist"])
continue;
if ([file isEqualToString:@"Library"]){
BOOL globalMoved = NO;
if ([fileMgr moveItemAtPath:[dataPath stringByAppendingPathComponent:@"Library/Preferences/.GlobalPreferences.plist"] toPath:[dataPath stringByAppendingPathComponent:@".GlobalPreferences.plist"] error:nil])
globalMoved = YES;
BOOL pickerMoved = NO;
if ([fileMgr moveItemAtPath:[dataPath stringByAppendingPathComponent:@"Library/Preferences/com.apple.PeoplePicker.plist"] toPath:[dataPath stringByAppendingPathComponent:@"com.apple.PeoplePicker.plist"] error:nil])
pickerMoved = YES;
[ipaArchive addDirectoryToZip:[dataPath stringByAppendingPathComponent:@"Library"] toPathInZip:@"Container/Library/"];
if (globalMoved)
[fileMgr moveItemAtPath:[dataPath stringByAppendingPathComponent:@".GlobalPreferences.plist"] toPath:[dataPath stringByAppendingPathComponent:@"Library/Preferences/.GlobalPreferences.plist"] error:nil];
if (pickerMoved)
[fileMgr moveItemAtPath:[dataPath stringByAppendingPathComponent:@"com.apple.PeoplePicker.plist"] toPath:[dataPath stringByAppendingPathComponent:@"Library/Preferences/com.apple.PeoplePicker.plist"] error:nil];
} else {
NSString *sourcePath = [dataPath stringByAppendingPathComponent:file];
BOOL isDir;
if ([fileMgr fileExistsAtPath:sourcePath isDirectory:&isDir] && isDir)
[ipaArchive addDirectoryToZip:sourcePath toPathInZip:[NSString stringWithFormat:@"Container/%@/", file]];
else
[ipaArchive addFileToZip:sourcePath newname:[NSString stringWithFormat:@"Container/%@/", file]];
}
}
}
[ipaArchive release];
if (savePath) {
NSString *saveDir = [savePath stringByDeletingLastPathComponent];
BOOL isDirectory;
if ([fileMgr fileExistsAtPath:saveDir isDirectory:&isDirectory]) {
if (!isDirectory) {
if (quietInstall < 2)
printf("%s is not a directory.\n", [saveDir cStringUsingEncoding:NSUTF8StringEncoding]);
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
} else {
if(![fileMgr createDirectoryAtPath:saveDir withIntermediateDirectories:YES attributes:nil error:NULL] ) {
if (quietInstall < 2)
printf("Failed to create directory %s.\n", [saveDir cStringUsingEncoding:NSUTF8StringEncoding]);
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
//Set root folder's attributes
NSDictionary *directoryAttributes = [fileMgr attributesOfItemAtPath:saveDir error:nil];
NSMutableDictionary *defaultDirectoryAttributes = [NSMutableDictionary dictionaryWithCapacity:[directoryAttributes count]];
[defaultDirectoryAttributes setDictionary:directoryAttributes];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileGroupOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileGroupOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithShort:0755] forKey:NSFilePosixPermissions];
[fileMgr setAttributes:defaultDirectoryAttributes ofItemAtPath:saveDir error:nil];
}
//Move
if (![fileMgr moveItemAtPath:[workPath stringByAppendingPathComponent:@"temp.zip"] toPath:savePath error:nil]) {
if (quietInstall < 2)
printf("Failed to create IPA file.\n");
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
if (quietInstall == 0)
printf("The application has been backed up as %s.\n", [savePath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return 0;
} else {
NSString *nameBase;
if (isBackup)
nameBase = [NSString stringWithFormat:@"%@ (%@) v%@", getBestString(appName, appDisplayName), identifier, getBestString(appVersion, appShortVersion)];
else
nameBase = [NSString stringWithFormat:@"%@ (%@) v%@ (Full)", getBestString(appName, appDisplayName), identifier, getBestString(appVersion, appShortVersion)];
NSString *saveDir = @"/private/var/mobile/Documents";
if (![fileMgr fileExistsAtPath:saveDir]) {
if(![fileMgr createDirectoryAtPath:saveDir withIntermediateDirectories:YES attributes:nil error:NULL] ) {
if (quietInstall < 2)
printf("Failed to create /var/mobile/Documents.\n");
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
//Set root folder's attributes
NSDictionary *directoryAttributes = [fileMgr attributesOfItemAtPath:saveDir error:nil];
NSMutableDictionary *defaultDirectoryAttributes = [NSMutableDictionary dictionaryWithCapacity:[directoryAttributes count]];
[defaultDirectoryAttributes setDictionary:directoryAttributes];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithInt:501] forKey:NSFileGroupOwnerAccountID];
[defaultDirectoryAttributes setObject:@"mobile" forKey:NSFileGroupOwnerAccountName];
[defaultDirectoryAttributes setObject:[NSNumber numberWithShort:0755] forKey:NSFilePosixPermissions];
[fileMgr setAttributes:defaultDirectoryAttributes ofItemAtPath:saveDir error:nil];
}
//Move
NSString *ipaPath = [[NSString stringWithFormat:@"%@/%@.ipa", saveDir, nameBase] stringByStandardizingPath];
if ([fileMgr fileExistsAtPath:ipaPath]) {
for (int i=1; ; i++) {
ipaPath = [NSString stringWithFormat:@"%@/%@ %d.ipa", saveDir, nameBase, i];
if (![fileMgr fileExistsAtPath:ipaPath])
break;
}
}
if (![fileMgr moveItemAtPath:[workPath stringByAppendingPathComponent:@"temp.zip"] toPath:ipaPath error:nil]) {
if (quietInstall < 2)
printf("Failed to create IPA file.\n");
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
[pool release];
return IPA_FAILED;
}
if (!removeAllContentsUnderPath(workPath)) {
if (quietInstall < 2)
printf("Failed to clean caches.\n");
}
if (quietInstall == 0)
printf("The application has been backed up as %s.\n", [ipaPath cStringUsingEncoding:NSUTF8StringEncoding]);
[pool release];
return 0;
}
}
}
NSMutableArray *ipaFiles = [NSMutableArray arrayWithCapacity:0];
NSMutableArray *filesNotFound = [NSMutableArray arrayWithCapacity:0];
BOOL noParameters = NO;
BOOL showHelp = NO;
BOOL showAbout = NO;
for (unsigned int i=1; i<[arguments count]; i++) {
NSString *arg = [arguments objectAtIndex:i];
if ([arg hasPrefix:@"-" ]) {
if ([arg length] < 2 || noParameters) {
printf("Invalid parameters.\n");
[pool release];
return IPA_FAILED;
}
for (unsigned int j=1; j<[arg length]; j++) {
NSString *p = [arg substringWithRange:NSMakeRange(j, 1)];
if ([p isEqualToString:@"u"])
isUninstall = YES;
else if ([p isEqualToString:@"l"])
isListing = YES;
else if ([p isEqualToString:@"b"]) {
if (isBackupFull) {
printf("Parameter b and B cannot be specified at the same time.\n");
[pool release];
return IPA_FAILED;
}
isBackup = YES;
} else if ([p isEqualToString:@"B"]) {
if (isBackup) {
printf("Parameter -b and -B cannot be specified at the same time.\n");
[pool release];
return IPA_FAILED;
}
isBackupFull = YES;
} else if ([p isEqualToString:@"a"])
showAbout = YES;
else if ([p isEqualToString:@"c"])
cleanInstall = YES;
else if ([p isEqualToString:@"d"])
deleteFile = YES;
else if ([p isEqualToString:@"i"] || [p isEqualToString:@"I"])
isGetInfo = YES;
else if ([p isEqualToString:@"f"])