Whitelist.xm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. @interface PBSSystemService : NSObject
  14. +(id)sharedInstance;
  15. -(void)deactivateScreenSaver;
  16. @end
  17. @interface PBSPowerManager : NSObject
  18. +(id)sharedInstance;
  19. +(void)load;
  20. +(void)setupPowerManagement;
  21. -(void)_performUserEventWakeDevice;
  22. -(void)wakeDeviceWithOptions:(id)arg1;
  23. -(void)setNeedsDisplayWakeOnPowerOn:(BOOL)arg1;
  24. - (void)sleepDeviceWithOptions:(id)arg1;
  25. -(void)_registerForPowerNotifications;
  26. -(void)_registerForThermalNotifications;
  27. -(void)_enableIdleSleepAndWatchdog;
  28. -(void)_registerForBackBoardNotifications;
  29. -(void)_updateIdleTimer;
  30. @end
  31. %hook PBApplication
  32. %new - (void)openApp:(NSString *)bundleID {
  33. %log;
  34. id workspace = nil;
  35. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  36. if (!LSApplicationWorkspace_class) {
  37. fprintf(stderr,"Unable to get Workspace class\n");
  38. }
  39. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  40. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  41. /*
  42. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  43. if (!CS_handle) {
  44. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  45. return;
  46. }
  47. */
  48. if (workspace){
  49. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  50. }
  51. }
  52. - (void)finishSystemAppLaunch {
  53. %log;
  54. %orig;
  55. NSFileManager *man = [NSFileManager defaultManager];
  56. NSString *nl = @"/var/mobile/Library/Preferences/.nitolaunch";
  57. if ([man fileExistsAtPath:nl]){
  58. NSLog(@"launch nitoTV");
  59. [self openApp:@"com.nito.nitoTV4"];
  60. [man removeItemAtPath:nl error:nil];
  61. //[NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  62. }
  63. }
  64. %end
  65. %hook PBAppDelegate
  66. %new - (void)openApp:(NSString *)bundleID {
  67. id workspace = nil;
  68. Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
  69. if (!LSApplicationWorkspace_class) {
  70. fprintf(stderr,"Unable to get Workspace class\n");
  71. }
  72. workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
  73. if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
  74. /*
  75. void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
  76. if (!CS_handle) {
  77. fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
  78. return;
  79. }
  80. */
  81. if (workspace){
  82. [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
  83. }
  84. }
  85. %new - (void)sleepNowInTheFire {
  86. Class pss = objc_getClass("PBSSystemService");
  87. id sysService = [pss sharedInstance];
  88. [sysService deactivateScreenSaver];
  89. Class powermanager = objc_getClass("PBSPowerManager");
  90. id power = [powermanager sharedInstance];
  91. [power sleepDeviceWithOptions:@{@"SleepReason": @"UserSettings"}];
  92. }
  93. %new - (void)wakeyWakey {
  94. Class powermanager = objc_getClass("PBSPowerManager");
  95. id power = [powermanager sharedInstance];
  96. if ([power respondsToSelector:@selector(_performUserEventWakeDevice)]){
  97. [power _performUserEventWakeDevice];
  98. }
  99. [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
  100. }
  101. %new - (void)delayedNitoTVLaunch:(id)note {
  102. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  103. NSLog(@"opening nitoTV");
  104. [self openApp:@"com.nito.nitoTV4"];
  105. });
  106. }
  107. - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
  108. _Bool orig = %orig;
  109. %log;
  110. NSFileManager *man = [NSFileManager defaultManager];
  111. NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
  112. //NSLog(@"after note center");
  113. [notificationCenter addObserver:self selector:@selector(delayedNitoTVLaunch:) name:@"com.nitoTV.relaunch" object:nil];
  114. [notificationCenter addObserver:self selector:@selector(wakeyWakey) name:@"com.nitoTV.wakeup" object:nil];
  115. [notificationCenter addObserver:self selector:@selector(sleepNowInTheFire) name:@"com.nitoTV.sleep" object:nil];
  116. NSString *kickstartPath = @"/var/mobile/Library/Preferences/.kickstart";
  117. if ([man fileExistsAtPath:kickstartPath]){
  118. NSLog(@"kickstart");
  119. //[self openApp:@"com.nito.nitoTV4"];
  120. [man removeItemAtPath:kickstartPath error:nil];
  121. [NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  122. [FM createFileAtPath:@"/var/mobile/Library/Preferences/.nitolaunch" contents:[@"" dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];
  123. }
  124. return orig;
  125. }
  126. %end
  127. %hook PBSMutableAppState
  128. -(BOOL)isEnabled
  129. {
  130. //%log;
  131. NSString *ourID = [self applicationIdentifier];
  132. //don't interfere with stuff that is already enabled properly
  133. if (%orig == YES){
  134. //NSLog(@"already yes: %@",ourID );
  135. return %orig;
  136. }
  137. return YES;
  138. NSArray *whitelistArray = [NSArray arrayWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.whitelist.plist"];
  139. NSString *recentlyDeleted = @"/var/mobile/Library/Preferences/com.nito.deleted.plist";
  140. NSArray *deletedArray = nil;
  141. if ([[NSFileManager defaultManager] fileExistsAtPath:recentlyDeleted])
  142. {
  143. deletedArray = [NSArray arrayWithContentsOfFile:recentlyDeleted];
  144. }
  145. if ([whitelistArray containsObject:ourID] && ![deletedArray containsObject:ourID])
  146. {
  147. //NSLog(@"whitelisted: %@",ourID );
  148. return YES;
  149. } else {
  150. return NO;
  151. }
  152. // return %orig;
  153. }
  154. %end
  155. %hook PBAppInfo
  156. - (BOOL)isEnabled {
  157. //%log;
  158. return true;
  159. }
  160. %end
  161. %hook PBSAppState
  162. + (BOOL)isEnabledForApplicationWithIdentifier:(id)ident {
  163. //%log;
  164. return YES;
  165. }
  166. %end