Whitelist.xm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. [power _performUserEventWakeDevice];
  97. [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
  98. }
  99. %new - (void)delayedNitoTVLaunch:(id)note {
  100. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  101. NSLog(@"opening nitoTV");
  102. [self openApp:@"com.nito.nitoTV4"];
  103. });
  104. }
  105. - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
  106. _Bool orig = %orig;
  107. %log;
  108. NSFileManager *man = [NSFileManager defaultManager];
  109. NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
  110. //NSLog(@"after note center");
  111. [notificationCenter addObserver:self selector:@selector(delayedNitoTVLaunch:) name:@"com.nitoTV.relaunch" object:nil];
  112. [notificationCenter addObserver:self selector:@selector(wakeyWakey) name:@"com.nitoTV.wakeup" object:nil];
  113. [notificationCenter addObserver:self selector:@selector(sleepNowInTheFire) name:@"com.nitoTV.sleep" object:nil];
  114. NSString *kickstartPath = @"/var/mobile/Library/Preferences/.kickstart";
  115. if ([man fileExistsAtPath:kickstartPath]){
  116. NSLog(@"kickstart");
  117. //[self openApp:@"com.nito.nitoTV4"];
  118. [man removeItemAtPath:kickstartPath error:nil];
  119. [NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
  120. [FM createFileAtPath:@"/var/mobile/Library/Preferences/.nitolaunch" contents:[@"" dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];
  121. }
  122. return orig;
  123. }
  124. %end
  125. %hook PBSMutableAppState
  126. -(BOOL)isEnabled
  127. {
  128. //%log;
  129. NSString *ourID = [self applicationIdentifier];
  130. //don't interfere with stuff that is already enabled properly
  131. if (%orig == YES){
  132. //NSLog(@"already yes: %@",ourID );
  133. return %orig;
  134. }
  135. return YES;
  136. NSArray *whitelistArray = [NSArray arrayWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.whitelist.plist"];
  137. NSString *recentlyDeleted = @"/var/mobile/Library/Preferences/com.nito.deleted.plist";
  138. NSArray *deletedArray = nil;
  139. if ([[NSFileManager defaultManager] fileExistsAtPath:recentlyDeleted])
  140. {
  141. deletedArray = [NSArray arrayWithContentsOfFile:recentlyDeleted];
  142. }
  143. if ([whitelistArray containsObject:ourID] && ![deletedArray containsObject:ourID])
  144. {
  145. //NSLog(@"whitelisted: %@",ourID );
  146. return YES;
  147. } else {
  148. return NO;
  149. }
  150. // return %orig;
  151. }
  152. %end