Whitelist.xm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. @interface NSDistributedNotificationCenter : NSNotificationCenter
  9. + (id)defaultCenter;
  10. - (void)addObserver:(id)arg1 selector:(SEL)arg2 name:(id)arg3 object:(id)arg4;
  11. - (void)postNotificationName:(id)arg1 object:(id)arg2 userInfo:(id)arg3;
  12. @end
  13. %hook PBApplication
  14. %new - (void)openApp:(NSString *)bundleID {
  15. %log;
  16. id workspace = nil;
  17. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  18. if (!LSApplicationWorkspace_class) {
  19. fprintf(stderr,"Unable to get Workspace class\n");
  20. }
  21. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  22. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  23. /*
  24. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  25. if (!CS_handle) {
  26. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  27. return;
  28. }
  29. */
  30. if (workspace){
  31. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  32. }
  33. }
  34. - (void)finishSystemAppLaunch {
  35. %log;
  36. %orig;
  37. NSFileManager *man = [NSFileManager defaultManager];
  38. NSString *nl = @"/var/mobile/Library/Preferences/.nitolaunch";
  39. if ([man fileExistsAtPath:nl]){
  40. NSLog(@"launch nitoTV");
  41. [self openApp:@"com.nito.nitoTV4"];
  42. [man removeItemAtPath:nl error:nil];
  43. //[NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  44. }
  45. }
  46. %end
  47. %hook PBAppDelegate
  48. %new - (void)openApp:(NSString *)bundleID {
  49. id workspace = nil;
  50. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  51. if (!LSApplicationWorkspace_class) {
  52. fprintf(stderr,"Unable to get Workspace class\n");
  53. }
  54. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  55. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  56. /*
  57. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  58. if (!CS_handle) {
  59. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  60. return;
  61. }
  62. */
  63. if (workspace){
  64. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  65. }
  66. }
  67. %new - (void)delayedNitoTVLaunch:(id)note {
  68. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  69. NSLog(@"opening nitoTV");
  70. [self openApp:@"com.nito.nitoTV4"];
  71. });
  72. }
  73. - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
  74. _Bool orig = %orig;
  75. %log;
  76. NSFileManager *man = [NSFileManager defaultManager];
  77. NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
  78. //NSLog(@"after note center");
  79. [notificationCenter addObserver:self selector:@selector(delayedNitoTVLaunch:) name:@"com.nitoTV.relaunch" object:nil];
  80. NSString *kickstartPath = @"/var/mobile/Library/Preferences/.kickstart";
  81. if ([man fileExistsAtPath:kickstartPath]){
  82. NSLog(@"kickstart");
  83. //[self openApp:@"com.nito.nitoTV4"];
  84. [man removeItemAtPath:kickstartPath error:nil];
  85. [NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  86. [FM createFileAtPath:@"/var/mobile/Library/Preferences/.nitolaunch" contents:[@"" dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];
  87. }
  88. return orig;
  89. }
  90. %end
  91. %hook PBSMutableAppState
  92. -(BOOL)isEnabled
  93. {
  94. //%log;
  95. NSString *ourID = [self applicationIdentifier];
  96. //don't interfere with stuff that is already enabled properly
  97. if (%orig == YES){
  98. //NSLog(@"already yes: %@",ourID );
  99. return %orig;
  100. }
  101. NSArray *whitelistArray = [NSArray arrayWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.whitelist.plist"];
  102. NSString *recentlyDeleted = @"/var/mobile/Library/Preferences/com.nito.deleted.plist";
  103. NSArray *deletedArray = nil;
  104. if ([[NSFileManager defaultManager] fileExistsAtPath:recentlyDeleted])
  105. {
  106. deletedArray = [NSArray arrayWithContentsOfFile:recentlyDeleted];
  107. }
  108. if ([whitelistArray containsObject:ourID] && ![deletedArray containsObject:ourID])
  109. {
  110. //NSLog(@"whitelisted: %@",ourID );
  111. return YES;
  112. } else {
  113. return NO;
  114. }
  115. // return %orig;
  116. }
  117. %end