Whitelist.xm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #import "NSTask.h"
  2. #define CORE_SERVICE_FRAMEWORK "/System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices"
  3. @interface LSApplicationWorkspace: NSObject
  4. - (id)allApplications;
  5. - (void)openApplicationWithBundleID:(NSString *)string;
  6. - (id)defaultWorkspace;
  7. @end
  8. %hook PBApplication
  9. %new - (void)openApp:(NSString *)bundleID {
  10. %log;
  11. id workspace = nil;
  12. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  13. if (!LSApplicationWorkspace_class) {
  14. fprintf(stderr,"Unable to get Workspace class\n");
  15. }
  16. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  17. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  18. /*
  19. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  20. if (!CS_handle) {
  21. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  22. return;
  23. }
  24. */
  25. if (workspace){
  26. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  27. }
  28. }
  29. - (void)finishSystemAppLaunch {
  30. %log;
  31. %orig;
  32. NSFileManager *man = [NSFileManager defaultManager];
  33. NSString *nl = @"/var/mobile/Library/Preferences/.nitolaunch";
  34. if ([man fileExistsAtPath:nl]){
  35. NSLog(@"launch nitoTV");
  36. [self openApp:@"com.nito.nitoTV4"];
  37. [man removeItemAtPath:nl error:nil];
  38. //[NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  39. }
  40. }
  41. %end
  42. %hook PBAppDelegate
  43. %new - (void)openApp:(NSString *)bundleID {
  44. id workspace = nil;
  45. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  46. if (!LSApplicationWorkspace_class) {
  47. fprintf(stderr,"Unable to get Workspace class\n");
  48. }
  49. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  50. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  51. /*
  52. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  53. if (!CS_handle) {
  54. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  55. return;
  56. }
  57. */
  58. if (workspace){
  59. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  60. }
  61. }
  62. - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
  63. _Bool orig = %orig;
  64. %log;
  65. NSFileManager *man = [NSFileManager defaultManager];
  66. NSString *kickstartPath = @"/var/mobile/Library/Preferences/.kickstart";
  67. if ([man fileExistsAtPath:kickstartPath]){
  68. NSLog(@"kickstart");
  69. //[self openApp:@"com.nito.nitoTV4"];
  70. [man removeItemAtPath:kickstartPath error:nil];
  71. [NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  72. [FM createFileAtPath:@"/var/mobile/Library/Preferences/.nitolaunch" contents:[@"" dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];
  73. }
  74. return orig;
  75. }
  76. %end
  77. %hook PBSMutableAppState
  78. -(BOOL)isEnabled
  79. {
  80. //%log;
  81. NSString *ourID = [self applicationIdentifier];
  82. //don't interfere with stuff that is already enabled properly
  83. if (%orig == YES){
  84. //NSLog(@"already yes: %@",ourID );
  85. return %orig;
  86. }
  87. NSArray *whitelistArray = [NSArray arrayWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.whitelist.plist"];
  88. NSString *recentlyDeleted = @"/var/mobile/Library/Preferences/com.nito.deleted.plist";
  89. NSArray *deletedArray = nil;
  90. if ([[NSFileManager defaultManager] fileExistsAtPath:recentlyDeleted])
  91. {
  92. deletedArray = [NSArray arrayWithContentsOfFile:recentlyDeleted];
  93. }
  94. if ([whitelistArray containsObject:ourID] && ![deletedArray containsObject:ourID])
  95. {
  96. //NSLog(@"whitelisted: %@",ourID );
  97. return YES;
  98. } else {
  99. return NO;
  100. }
  101. // return %orig;
  102. }
  103. %end