forked from theiostream/Libhide
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhide.m
More file actions
1168 lines (1025 loc) · 35.4 KB
/
hide.m
File metadata and controls
1168 lines (1025 loc) · 35.4 KB
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
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <stdio.h>
#import "hide.h"
#import <sys/utsname.h> /* for uname structure */
#include <sys/stat.h>
#include <unistd.h>
#include <notify.h>
//*************************************************************************************************
// IsPlistFileBinary - determines of the plist file is in binary format or not
//*************************************************************************************************
BOOL IsPlistFileBinary(char* Title)
{
BOOL Binary = YES;
char t1;
char t2;
char t3;
FILE* fp = fopen(Title, "r");
if(fp != NULL)
{
t1 = fgetc(fp);
t2 = fgetc(fp);
t3 = fgetc(fp);
if(t1 == '<' && t2 == '?' && t3 == 'x')
{
Binary = NO;
}
fclose(fp);
}
return Binary;
}
//*************************************************************************************************
// IsPlistBinary - Determines if the plist is binary or xml.
// Returns YES for binary, NO for XML
//*************************************************************************************************
BOOL IsPlistFileBinaryNS(NSString* Path)
{
return IsPlistFileBinary((char*)[Path UTF8String]);
}
//*************************************************************************************************
// HideLibIsTouch - Gets the OS version and optionally the platform
//*************************************************************************************************
BOOL HideLibIsTouch()
{
static BOOL Touch = NO;
struct utsname UtsName;
uname(&UtsName);
if(strstr(UtsName.machine, "iPod") != NULL)
{
Touch = YES;
}
else
{
Touch = NO;
}
return Touch;
}
//*************************************************************************************************
// Respring - Restarts springboard.
//*************************************************************************************************
void Respring()
{
notify_post("com.apple.language.changed");
}
//*************************************************************************************************
// ConvertPlistToXml - Converts the plist file to XML format
//*************************************************************************************************
void ConvertPlistToXml(NSString* Path)
{
// Convert the plist by opening it, reading it, and saving it.
NSMutableDictionary* List = [[NSMutableDictionary alloc] initWithContentsOfFile:Path];
[List writeToFile:Path atomically: YES];
[List release];
}
//*************************************************************************************************
// UnHideSpecialIcon - UnHides the camera or photos icons.
//*************************************************************************************************
BOOL UnHideSpecialIcon(NSString* Path, BOOL UpdateMaster)
{
FILE* fp = NULL;
FILE* Out = NULL;
char Temp[512];
int i = 0;
long PrevLine = 0;
int UIRoleDisplayCount = 0;
int UIRoleFoundCount = 0;
BOOL Hidden = NO;
BOOL Changed = NO;
BOOL Photos = NO;
BOOL IsTouch = NO;
if([Path isEqualToString:@"Photos.app"] == YES)
{
Photos = YES;
}
// Check for camera and touch. Camera isnt supported on the touch.
IsTouch = HideLibIsTouch();
if(Photos == NO && IsTouch == YES)
{
return NO;
}
// UIRoleDisplayCount occurs 3 times in the file and depending if its touch, photos, or camera will be in 3 locations. We are assuming the file is always in the same order
// and just counting instances to know where to add the hidden tags.
if(Photos == NO)
{
UIRoleDisplayCount = 2;
}
else if(IsTouch == YES)
{
UIRoleDisplayCount = 3;
}
else
{
UIRoleDisplayCount = 1;
}
NSString* InfoPlist = [[NSString alloc] initWithString:@"/Applications/MobileSlideShow.app/Info.plist"];
NSString* InfoPlistOut = [[NSString alloc] initWithFormat:@"/Applications/MobileSlideShow.app/Info.plist_Info.Out"]; //, Path];
if(IsPlistFileBinaryNS(InfoPlist) == YES)
{
NSLog(@"HideIcon: Plist is still in binary, converting to XML for %@\n", Path);
ConvertPlistToXml(InfoPlist);
}
fp = fopen([InfoPlist UTF8String], "r");
if(fp != NULL)
{
// Find the line with >hidden<
while(!feof(fp))
{
if(fgets(Temp, 511, fp) == NULL) break;
if(strstr(Temp, "</plist>") != NULL) break;
// Scan for the location of the "UIRoleDisplayName"
if(strstr(Temp, ">UIRoleDisplayName<") != NULL)
{
UIRoleFoundCount++;
if(UIRoleFoundCount == UIRoleDisplayCount)
{
// Once the role is found, look to see if it is already hidden.
if(fgets(Temp, 511, fp) == NULL) break;
if(fgets(Temp, 511, fp) == NULL) break;
if(fgets(Temp, 511, fp) == NULL) break;
if(fgets(Temp, 511, fp) == NULL) break;
if(strstr(Temp, ">hidden<") != NULL)
{
Hidden = YES;
}
break;
}
}
PrevLine++;
}
rewind(fp);
if(Hidden == YES)
{
Out = fopen([InfoPlistOut UTF8String], "w");
if(Out != NULL)
{
NSLog(@"Opened %@ for writing, PrevLine = %ld\n", InfoPlistOut, PrevLine);
for(i = 0; i < PrevLine + 2; i++)
{
if(fgets(Temp, 511, fp) == NULL) break;
fputs(Temp, Out);
}
// Delete the 4 lines containing the "hidden" key.
NSLog(@"Deleting hidden section\n");
fgets(Temp, 511, fp);
fgets(Temp, 511, fp);
fgets(Temp, 511, fp);
fgets(Temp, 511, fp);
while(!feof(fp))
{
if(fgets(Temp, 511, fp) == NULL) break;
fputs(Temp, Out);
}
fclose(Out);
}
}
fclose(fp);
if(Hidden == YES)
{
remove([InfoPlist UTF8String]);
rename([InfoPlistOut UTF8String], [InfoPlist UTF8String]);
Changed = YES;
}
}
[InfoPlist release];
[InfoPlistOut release];
return Changed;
}
//*************************************************************************************************
// GetDisplayNameFromPath - Returns the name of the icon file used in the info.plist passed in.
//*************************************************************************************************
NSString* GetDisplayNameFromPath(NSString* PlistPath)
{
NSString* IconFile = nil;
NSString* IconFileTemp = nil;
NSMutableDictionary* List = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath];
if(List)
{
// Get the bundle ID
IconFileTemp = [List objectForKey:@"CFBundleDisplayName"];
if(IconFileTemp != nil)
{
IconFile = [[NSString alloc] initWithString:IconFileTemp];
}
[List release];
}
return IconFile;
}
//*************************************************************************************************
// GetIconFromePath - Returns the icon out of the plist passed in.
// Note: this function is misnamed but already used in bossprefs so cant be removed for now.
//*************************************************************************************************
NSString* GetIconFromPath(NSString* PlistPath)
{
return GetIconFromPlist(PlistPath);
}
//*************************************************************************************************
// GetIconFromPath - Returns the name of the icon file used in the info.plist passed in.
//*************************************************************************************************
NSString* GetIconFromPlist(NSString* PlistPath)
{
NSString* IconFile = nil;
NSString* IconFileTemp = nil;
NSMutableDictionary* List = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath];
if(List)
{
// Get the bundle ID
IconFileTemp = [List objectForKey:@"CFBundleIconFile"];
if(IconFileTemp != nil)
{
IconFile = [[NSString alloc] initWithString:IconFileTemp];
}
[List release];
}
return IconFile;
}
//*************************************************************************************************
// GetIconFromFilePath - Returns the name of the icon file used in the info.plist passed in.
//
// Note: For exception cases, camera and photos, pass in just "/Applications/Photos.app" or
// "/Applications/Camera.app" for the path.
//*************************************************************************************************
NSString* GetIconFromFilePath(NSString* ApplicationPath)
{
NSString* IconString = nil;
NSString* IconFile = nil;
NSFileManager* FileManager = [NSFileManager defaultManager];
if([ApplicationPath isEqualToString:@"/Applications/Camera.app"] == YES)
{
IconString = [[NSString alloc] initWithString: @"/Applications/MobileSlideShow.app/icon-Camera.png"];
}
else if([ApplicationPath isEqualToString:@"/Applications/Photos.app"] == YES)
{
IconString = [[NSString alloc] initWithString:@"/Applications/MobileSlideShow.app/icon-Photos.png"];
}
else if([FileManager fileExistsAtPath: [NSString stringWithFormat:@"%@/icon.png", ApplicationPath]])
{
IconString = [[NSString alloc] initWithFormat:@"%@/icon.png", ApplicationPath];
}
else if([FileManager fileExistsAtPath: [NSString stringWithFormat:@"%@/Icon.png", ApplicationPath]])
{
IconString = [[NSString alloc] initWithFormat:@"%@/Icon.png", ApplicationPath];
}
else
{
IconFile = GetIconFromPlist([NSString stringWithFormat:@"%@/Info.plist", ApplicationPath]);
if(IconFile != nil)
{
if([[IconFile substringFromIndex:([IconFile length] - 4)] isEqualToString:@".png"] == NO)
{
IconString = [[NSString alloc] initWithFormat:@"%@/%@.png", ApplicationPath, IconFile];
}
else
{
IconString = [[NSString alloc] initWithFormat:@"%@/%@", ApplicationPath, IconFile];
}
}
if(IconString != nil)
{
if([FileManager fileExistsAtPath: IconString] == NO)
{
[IconString release];
IconString = nil;
}
}
}
return IconString;
}
//*************************************************************************************************
// GetPathFromAppFolderName - Gets the path to the file from the folder name.
//
// Note: Camera.app and Photos.app just return /Applications/Cameras.app / /Applications/Photos.app
//*************************************************************************************************
NSString* GetPathFromAppFolderName(NSString* FolderName)
{
NSString* Path = nil;
NSFileManager* FileManager = [NSFileManager defaultManager];
NSString* TempFolder = nil;
if([FolderName isEqualToString:@"Camera.app"] == YES)
{
Path = [[NSString alloc] initWithString:@"/Applications/Camera.app"];
}
else if([FolderName isEqualToString:@"Photos.app"] == YES)
{
Path = [[NSString alloc] initWithString:@"/Applications/Photos.app"];
}
else
{
// Check /Applications for it
TempFolder = [NSString stringWithFormat:@"/Applications/%@", FolderName];
if([FileManager fileExistsAtPath: TempFolder] == YES)
{
Path = [[NSString alloc] initWithString:TempFolder];
}
// Check AppStore apps for it
if(Path == nil)
{
NSArray* AppDirs = [[NSArray alloc] initWithArray:[FileManager contentsOfDirectoryAtPath:@"/var/mobile/Applications" error:NULL]];
int i = 0;
for(i = 0; i < [AppDirs count]; i++)
{
TempFolder = [NSString stringWithFormat:@"/var/mobile/Applications/%@/%@", [AppDirs objectAtIndex:i], FolderName];
if([FileManager fileExistsAtPath: TempFolder] == YES)
{
Path = [[NSString alloc] initWithString:TempFolder];
break;
}
}
[AppDirs release];
}
}
return Path;
}
//*************************************************************************************************
// GetPathFromBundleId - Takes the BundleId passed in and returns the path to the bundle.
//
// Note: For Camera and Photos, it returns "/Applications/Camera.app" / "/Applications/Photos.app"
// Note: Function never tested
//*************************************************************************************************
NSString* GetPathFromBundleId(NSString* BundleId)
{
NSString* Path = nil;
// Exception case - Photos.
if([BundleId isEqualToString:@"com.apple.mobileslideshow-Photos"])
{
Path = [[NSString alloc] initWithString:@"/Applications/Photos.app"];
}
// Exception case - Camera
else if([BundleId isEqualToString:@"com.apple.mobileslideshow-Camera"])
{
Path = [[NSString alloc] initWithString:@"/Applications/Camera.app"];
}
// Scan each apps folder, take the path and get the bundle ID and see if it equals the bundle we need.
else
{
NSFileManager* FileManager = [NSFileManager defaultManager];
NSArray* AppDirs = nil;
NSArray* AppStoreApps = nil;
NSString* AppDirTitle = nil;
NSString* PrefixDir = nil;
NSString* AppPath = nil;
NSString* ThisBundle = nil;
int i = 0;
int j = 0;
// First scan /Applications
AppDirs = [[NSArray alloc] initWithArray:[FileManager contentsOfDirectoryAtPath:@"/Applications" error:NULL]];
for(i = 0; i < [AppDirs count]; i++)
{
AppDirTitle = [NSString stringWithString:[AppDirs objectAtIndex:i]];
NSLog(@"AppDirTitle = %@\n", AppDirTitle);
// Filter some garbage such as . folders and folders without .app (none of these should exist but sometimes do)
if(strstr([AppDirTitle UTF8String], ".app") == NULL) continue;
if(([AppDirTitle UTF8String])[0] == '.') continue;
AppPath = [NSString stringWithFormat:@"/Applications/%@/Info.plist", AppDirTitle];
ThisBundle = GetBundleFromPath(AppPath);
if(ThisBundle != nil)
{
// Found it! Store it off and break the search loop.
if([ThisBundle isEqualToString: BundleId] == YES)
{
Path = [[NSString alloc] initWithString: AppPath];
[ThisBundle release];
break;
}
[ThisBundle release];
}
}
NSLog(@"Freeing AppDirs array for /Applications\n");
// Free the array
for(i = 0; i < [AppDirs count]; i++)
{
[[AppDirs objectAtIndex:i] release];
}
[AppDirs release];
// If we're still here, time to scan AppStore folders.
if(Path != nil)
{
NSString* FullAppPath = nil;
BOOL AppExists = NO;
AppDirs = [[NSArray alloc] initWithArray:[FileManager contentsOfDirectoryAtPath:@"/var/mobile/Applications" error:NULL]];
for(i = 0; i < [AppDirs count]; i++)
{
PrefixDir = [NSString stringWithFormat:@"/var/mobile/Applications/%@", [AppDirs objectAtIndex: i]];
NSLog(@"PrefixDir = %@\n", PrefixDir);
AppStoreApps = [[NSArray alloc] initWithArray:[FileManager contentsOfDirectoryAtPath:PrefixDir error:NULL]];
AppExists = NO;
for(j = 0; j < [AppStoreApps count]; j++)
{
AppDirTitle = [AppStoreApps objectAtIndex: j];
NSLog(@"AppDirTitle = %@\n", AppDirTitle);
// Filter garbage
if(strstr([AppDirTitle UTF8String], ".app") == NULL) continue;
if(([AppDirTitle UTF8String])[0] == '.') continue;
AppExists = YES;
break;
}
NSLog(@"Freeing AppStoreApps array iteration %d\n", i);
for(j = 0; j < [AppStoreApps count]; j++)
{
[[AppStoreApps objectAtIndex:i] release];
}
[AppStoreApps release];
if(AppExists == NO) continue;
FullAppPath = [NSString stringWithFormat:@"%@/%@/Info.plist", PrefixDir, AppDirTitle];
NSLog(@"FullAppPath = %@\n", FullAppPath);
ThisBundle = GetBundleFromPath(FullAppPath);
if(ThisBundle != nil)
{
// Found it! Store it off and break the search loop.
if([ThisBundle isEqualToString: BundleId] == YES)
{
Path = [[NSString alloc] initWithString: AppPath];
[ThisBundle release];
break;
}
[ThisBundle release];
}
}
NSLog(@"Freeing AppDirs array for /var/mobile/Applications\n");
// Free the array
for(i = 0; i < [AppDirs count]; i++)
{
[[AppDirs objectAtIndex:i] release];
}
[AppDirs release];
}
}
return Path;
}
//*************************************************************************************************
// GetBundleFromPath - Returns an allocated NSString that contains the bundle from the path passed in. The returned string should
// be freed later with release.
//*************************************************************************************************
NSString* GetBundleFromPath(NSString* PlistPath)
{
NSString* BundleId = nil;
if([PlistPath isEqualToString:@"/Applications/Photos.app/Info.plist"])
{
BundleId = [[NSString alloc] initWithString:@"com.apple.mobileslideshow-Photos"];
}
else if([PlistPath isEqualToString:@"/Applications/Camera.app/Info.plist"])
{
BundleId = [[NSString alloc] initWithString:@"com.apple.mobileslideshow-Camera"];
}
else
{
NSMutableDictionary* List = [[NSMutableDictionary alloc] initWithContentsOfFile:PlistPath];
if(List)
{
// Get the bundle ID
BundleId = [[NSString alloc] initWithString:[List objectForKey:@"CFBundleIdentifier"]];
[List release];
}
}
return BundleId;
}
BOOL UseRestrictionsForHide(NSString* Path)
{
BOOL Restrictions = YES;
if([Path isEqualToString:@"/Applications/MobileSafari.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileMusicPlayer.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/YouTube.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileStore.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileSMS.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/BossPrefs.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Maps.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileAddressBook.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileCal.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileMail.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileNotes.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobilePhone.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileTimer.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Preferences.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MobileSlideShow.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Stocks.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Weather.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Cydia.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Installer.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/FileViewer.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/Calendar.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/iRealSMS.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/MySMS.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/biteSMS.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/WinterBoard.app/Info.plist"] ||
[Path isEqualToString:@"/Applications/AppStore.app/Info.plist"])
{
Restrictions = NO;
}
return Restrictions;
}
//*************************************************************************************************
// IsIconHiddenCharPtr - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL IsIconHiddenCharPtr(char* Path)
{
NSString* Temp = [NSString stringWithUTF8String: Path];
return IsIconHidden(Temp);
}
//*************************************************************************************************
// IsIconHiddenDisplayId - determines if icon is hidden by display ID.
//*************************************************************************************************
BOOL IsIconHiddenDisplayId(NSString* BundleId)
{
BOOL Hidden = NO;
if([[NSFileManager defaultManager] fileExistsAtPath:@HIDLIBPATH])
{
NSMutableDictionary* Dict = [NSMutableDictionary dictionaryWithContentsOfFile:@HIDLIBPATH];
NSMutableArray* HiddenIconIds = [Dict objectForKey:@"Hidden"];
if(HiddenIconIds != nil && [HiddenIconIds count] > 0)
{
for(int i = 0; i < [HiddenIconIds count]; i++)
{
if([BundleId isEqualToString:[HiddenIconIds objectAtIndex:i]])
{
Hidden = YES;
break;
}
}
}
}
return Hidden;
}
//*************************************************************************************************
// IsIconHidden - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL IsIconHidden(NSString* Path)
{
BOOL Hidden = NO;
NSString* BundleId = GetBundleFromPath(Path);
Hidden = IsIconHiddenDisplayId(BundleId);
if(Hidden == NO) Hidden = IsIconHiddenOld(Path);
return Hidden;
}
//*************************************************************************************************
// IsIconHidden - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL IsIconHiddenOld(NSString* Path)
{
NSString* CurrentPlist;
BOOL Hidden = NO;
BOOL HiddenOld = NO;
NSLog(@"Checking if %@ is hidden\n", Path);
// Get the bundle ID
if(UseRestrictionsForHide(Path) == NO)
{
HiddenOld = IsIconHiddenInfoPlist(Path);
}
if(HiddenOld == YES)
{
return YES;
}
NSString* BundleId = GetBundleFromPath(Path);
if(BundleId != nil)
{
NSMutableDictionary* List = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
if(List)
{
NSMutableArray* Packages = [[NSMutableArray alloc] initWithArray:[List objectForKey:@"SBParentalControlsApplications"]];
if(Packages)
{
// Make sure the package is not already hidden.
int Count = [Packages count];
for(int i = 0; i < Count; i ++)
{
CurrentPlist = [Packages objectAtIndex:i];
if([CurrentPlist isEqualToString:BundleId])
{
Hidden = YES;
break;
}
}
[Packages release];
}
[List release];
}
[BundleId release];
}
return Hidden;
}
//*************************************************************************************************
// IsIconHidden - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL IsIconHiddenInfoPlist(NSString* PlistPath)
{
char Temp[512];
BOOL Hidden = NO;
ConvertPlistToXml(PlistPath);
FILE* fp = fopen([PlistPath UTF8String], "r");
if(fp != NULL)
{
// Find the line with >hidden<
while(!feof(fp))
{
if(fgets(Temp, 511, fp) == NULL) break;
if(strstr(Temp, ">hidden<") != NULL)
{
Hidden = YES;
}
if(strstr(Temp, "</plist>") != NULL) break;
}
fclose(fp);
}
return Hidden;
}
//*************************************************************************************************
// HideIcon - Hides the icon at the path passed in.
//*************************************************************************************************
BOOL HideIconInPlist(NSString* Path)
{
FILE* fp = NULL;
FILE* Out = NULL;
char Temp[512];
int i = 0;
long PrevLine = 0;
BOOL Hidden = NO;
BOOL Changed = NO;
NSString* InfoPlist = [[NSString alloc] initWithString:Path];
NSString* InfoPlistOut = [[NSString alloc] initWithFormat:@"%@_Info.Out", Path];
ConvertPlistToXml(InfoPlist);
fp = fopen([InfoPlist UTF8String], "r");
if(fp != NULL)
{
// Find the line with >hidden<
while(!feof(fp))
{
if(fgets(Temp, 511, fp) == NULL) break;
if(strstr(Temp, ">hidden<") != NULL)
{
Hidden = YES;
}
if(strstr(Temp, "</plist>") != NULL) break;
PrevLine++;
}
rewind(fp);
if(Hidden == NO)
{
Out = fopen([InfoPlistOut UTF8String], "w");
if(Out != NULL)
{
NSLog(@"Opened %@ for writing, PrevLine = %ld\n", InfoPlistOut, PrevLine);
for(i = 0; i < PrevLine - 1; i++)
{
if(fgets(Temp, 511, fp) == NULL) break;
fputs(Temp, Out);
}
NSLog(@"Writing hidden section\n");
// Write the 4 lines with array, hidden, /array
fprintf(Out, "\t<key>SBAppTags</key>\n");
fprintf(Out, "\t<array>\n");
fprintf(Out, "\t\t<string>hidden</string>\n");
fprintf(Out, "\t</array>\n");
while(!feof(fp))
{
if(fgets(Temp, 511, fp) == NULL) break;
fputs(Temp, Out);
}
fclose(Out);
}
}
fclose(fp);
if(Hidden == NO)
{
remove([InfoPlist UTF8String]);
rename([InfoPlistOut UTF8String], [InfoPlist UTF8String]);
Changed = YES;
}
}
[InfoPlist release];
[InfoPlistOut release];
return Changed;
}
//*************************************************************************************************
// HideIconCharPtr - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL HideIconCharPtr(char* Path)
{
NSString* Temp = [NSString stringWithUTF8String: Path];
return HideIcon(Temp);
}
//*************************************************************************************************
// HideIconViaDisplayId - Hides the icon using the display ID passed in.
//*************************************************************************************************
BOOL HideIconViaDisplayId(NSString* BundleId)
{
BOOL DeletedSomething = NO;
if(IsIconHiddenDisplayId(BundleId) == NO)
{
NSMutableArray* HiddenIconIds = nil;
NSMutableDictionary* Dict = nil;
if([[NSFileManager defaultManager] fileExistsAtPath:@HIDLIBPATH])
{
NSLog(@"LibHide: plist exists already\n");
Dict = [NSMutableDictionary dictionaryWithContentsOfFile:@HIDLIBPATH];
HiddenIconIds = [Dict objectForKey:@"Hidden"];
}
else
{
NSLog(@"LibHide: plist does not exist, making folder at /var/mobile/Library/LibHide\n");
mkdir("/var/mobile/Library/LibHide", 0777);
Dict = [NSMutableDictionary dictionaryWithCapacity:1];
HiddenIconIds = [[[NSMutableArray alloc] initWithCapacity:1] autorelease];
}
if(HiddenIconIds != nil)
{
[HiddenIconIds addObject:BundleId];
[Dict setObject: HiddenIconIds forKey:@"Hidden"];
[Dict writeToFile:@HIDLIBPATH atomically:YES];
chmod(HIDLIBPATH, 0666);
DeletedSomething = YES;
}
}
return DeletedSomething;
}
//*************************************************************************************************
// HideIcon - Hides the icon at the path passed in.
//*************************************************************************************************
BOOL HideIcon(NSString* PlistPath)
{
BOOL DeletedSomething = NO;
NSLog(@"LibHide: Hiding %@\n", PlistPath);
NSString* BundleId = GetBundleFromPath(PlistPath);
DeletedSomething = HideIconViaDisplayId(BundleId);
return DeletedSomething;
}
//*************************************************************************************************
// UnHideIconCharPtr - Determines if the icon passed in is already hidden or not.
//*************************************************************************************************
BOOL UnHideIconCharPtr(char* Path)
{
NSString* Temp = [NSString stringWithUTF8String: Path];
return UnHideIcon(Temp);
}
//*************************************************************************************************
// UnHideIcon - Removes a hidden icon from the plist. Returns TRUE if something was done, FALSE ir not.
//*************************************************************************************************
BOOL UnHideIconViaDisplayId(NSString* BundleId)
{
BOOL DeletedSomething = NO;
if(IsIconHiddenDisplayId(BundleId) == YES)
{
if([[NSFileManager defaultManager] fileExistsAtPath:@HIDLIBPATH])
{
NSLog(@"LibHide: Deleting from dylib dictionary list\n");
NSMutableDictionary* Dict = [NSMutableDictionary dictionaryWithContentsOfFile:@HIDLIBPATH];
NSMutableArray* HiddenIconIds = [Dict objectForKey:@"Hidden"];
int Count = 0;
if(HiddenIconIds != nil)
{
NSLog(@"LibHide: Deleting from dylib dictionary list\n");
Count = [HiddenIconIds count];
[HiddenIconIds removeObject:BundleId];
[Dict setObject: HiddenIconIds forKey:@"Hidden"];
[Dict writeToFile:@HIDLIBPATH atomically:YES];
chmod(HIDLIBPATH, 0666);
if([HiddenIconIds count] != Count)
{
DeletedSomething = YES;
}
}
}
}
#if 0
// Convert to Binary
NSString* error;
NSData* plistData = [NSPropertyListSerialization dataFromPropertyList:List
format:NSPropertyListBinaryFormat_v1_0
errorDescription:&error];
[plistData writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
#endif
return DeletedSomething;
}
//*************************************************************************************************
// UnHideIcon - Removes a hidden icon from the plist. Returns TRUE if something was done, FALSE ir not.
//*************************************************************************************************
BOOL UnHideIcon(NSString* PlistPath)
{
NSString* BundleId = GetBundleFromPath(PlistPath);
BOOL DeletedSomething = UnHideIconViaDisplayId(BundleId);
if(DeletedSomething == NO)
{
NSLog(@"LibHide: Did not find something to delete in dylib dictionary, trying old method.\n");
DeletedSomething = UnHideIconOld(PlistPath);
}
return DeletedSomething;
}
//*************************************************************************************************
// UnHideIconOld - Removes a hidden icon from the plist. Returns TRUE if something was done, FALSE ir not.
//*************************************************************************************************
BOOL UnHideIconOld(NSString* Path)
{
NSString* CurrentPlist;
int Count = 0;
int i = 0;
BOOL SomethingDone = NO;
BOOL SomethingDonePlist = NO;
if(IsIconHidden(Path) == YES)
{
NSString* BundleId = GetBundleFromPath(Path);
if(BundleId != nil)
{
NSMutableDictionary* NList = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
if(NList)
{
NSMutableArray* Packages = [[NSMutableArray alloc] initWithArray:[NList objectForKey:@"SBParentalControlsApplications"]];
if(Packages)
{
// Make sure the package is not already hidden.
Count = [Packages count];
for(i = 0; i < Count; i ++)
{
CurrentPlist = [Packages objectAtIndex:i];
if([CurrentPlist isEqualToString:BundleId])
{
NSLog(@"Found entry, removing it.\n");
[Packages removeObjectAtIndex:i];
SomethingDone = YES;
break;
}
}
if(SomethingDone == YES)
{
[NList setObject:Packages forKey:@"SBParentalControlsApplications"];
#if 0
// Convert to Binary
NSString* error;
NSData* plistData = [NSPropertyListSerialization dataFromPropertyList:List
format:NSPropertyListBinaryFormat_v1_0
errorDescription:&error];
[plistData writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
#endif
[NList writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
chmod("/var/mobile/Library/Preferences/com.apple.springboard.plist", 0666);
}
[Packages release];
}
else
{
NSLog(@"Packages = nil\n");
}
[NList release];
}
[BundleId release];
}
}
// These apps are unusable if hidden in springboard cause they will be restricted.
if(UseRestrictionsForHide(Path) == NO)
{
SomethingDonePlist = UnHideIconOlder(Path);
}
if(SomethingDone == YES || SomethingDonePlist == YES)
{
SomethingDone = YES;
}
return SomethingDone;
}
//*************************************************************************************************
// RemoveEntryFromDisplay - Pulls the entry out of the main springboard display special section allowing it to