123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- #import "NSTask.h"
- #define CORE_SERVICE_FRAMEWORK "/System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices"
- @interface LSApplicationWorkspace: NSObject
- - (id)allApplications;
- - (void)openApplicationWithBundleID:(NSString *)string;
- - (id)defaultWorkspace;
- @end
- @interface NSDistributedNotificationCenter : NSNotificationCenter
- + (id)defaultCenter;
- - (void)addObserver:(id)arg1 selector:(SEL)arg2 name:(id)arg3 object:(id)arg4;
- - (void)postNotificationName:(id)arg1 object:(id)arg2 userInfo:(id)arg3;
- @end
- @interface PBSSystemService : NSObject
- +(id)sharedInstance;
- -(void)deactivateScreenSaver;
- @end
- @interface PBSPowerManager : NSObject
- +(id)sharedInstance;
- +(void)load;
- +(void)setupPowerManagement;
- -(void)_performUserEventWakeDevice;
- -(void)wakeDeviceWithOptions:(id)arg1;
- -(void)setNeedsDisplayWakeOnPowerOn:(BOOL)arg1;
- - (void)sleepDeviceWithOptions:(id)arg1;
- -(void)_registerForPowerNotifications;
- -(void)_registerForThermalNotifications;
- -(void)_enableIdleSleepAndWatchdog;
- -(void)_registerForBackBoardNotifications;
- -(void)_updateIdleTimer;
- @end
- %hook PBApplication
- %new - (void)openApp:(NSString *)bundleID {
-
- %log;
- id workspace = nil;
- Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
- if (!LSApplicationWorkspace_class) {
-
- fprintf(stderr,"Unable to get Workspace class\n");
-
- }
-
- workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
- if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
- /*
- void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
- if (!CS_handle) {
- fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
- return;
- }
- */
- if (workspace){
- [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
- }
-
-
- }
- - (void)finishSystemAppLaunch {
-
- %log;
- %orig;
- NSFileManager *man = [NSFileManager defaultManager];
- NSString *nl = @"/var/mobile/Library/Preferences/.nitolaunch";
- if ([man fileExistsAtPath:nl]){
- NSLog(@"launch nitoTV");
-
- [self openApp:@"com.nito.nitoTV4"];
- [man removeItemAtPath:nl error:nil];
- //[NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
- }
-
-
- }
- %end
- %hook PBAppDelegate
- %new - (void)openApp:(NSString *)bundleID {
-
- id workspace = nil;
- Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
- if (!LSApplicationWorkspace_class) {
-
- fprintf(stderr,"Unable to get Workspace class\n");
-
- }
-
- workspace = [LSApplicationWorkspace_class performSelector:@selector (defaultWorkspace)];
- if (!workspace) {fprintf(stderr,"Unable to get Workspace\n"); }
- /*
- void *CS_handle = dlopen (CORE_SERVICE_FRAMEWORK, RTLD_NOW);
- if (!CS_handle) {
- fprintf(stderr,"Can't find %s!\n", CORE_SERVICE_FRAMEWORK);
- return;
- }
- */
- if (workspace){
- [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:(id) bundleID ];
- }
-
-
- }
- %new - (void)sleepNowInTheFire {
- Class pss = objc_getClass("PBSSystemService");
- id sysService = [pss sharedInstance];
- [sysService deactivateScreenSaver];
- Class powermanager = objc_getClass("PBSPowerManager");
- id power = [powermanager sharedInstance];
- [power sleepDeviceWithOptions:@{@"SleepReason": @"UserSettings"}];
- }
- %new - (void)wakeyWakey {
- Class powermanager = objc_getClass("PBSPowerManager");
- id power = [powermanager sharedInstance];
- if ([power respondsToSelector:@selector(_performUserEventWakeDevice)]){
- [power _performUserEventWakeDevice];
- }
- [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
- }
- %new - (void)delayedNitoTVLaunch:(id)note {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-
- NSLog(@"opening nitoTV");
- [self openApp:@"com.nito.nitoTV4"];
- });
- }
- - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
-
- _Bool orig = %orig;
- %log;
- NSFileManager *man = [NSFileManager defaultManager];
- NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
-
- //NSLog(@"after note center");
- [notificationCenter addObserver:self selector:@selector(delayedNitoTVLaunch:) name:@"com.nitoTV.relaunch" object:nil];
- [notificationCenter addObserver:self selector:@selector(wakeyWakey) name:@"com.nitoTV.wakeup" object:nil];
- [notificationCenter addObserver:self selector:@selector(sleepNowInTheFire) name:@"com.nitoTV.sleep" object:nil];
- NSString *kickstartPath = @"/var/mobile/Library/Preferences/.kickstart";
- if ([man fileExistsAtPath:kickstartPath]){
- NSLog(@"kickstart");
-
- //[self openApp:@"com.nito.nitoTV4"];
- [man removeItemAtPath:kickstartPath error:nil];
- [NSTask launchedTaskWithLaunchPath:@"/usr/bin/uicache" arguments:@[]];
- [FM createFileAtPath:@"/var/mobile/Library/Preferences/.nitolaunch" contents:[@"" dataUsingEncoding:NSASCIIStringEncoding] attributes:nil];
- }
- return orig;
-
- }
- %end
- %hook PBSMutableAppState
- -(BOOL)isEnabled
- {
- //%log;
- NSString *ourID = [self applicationIdentifier];
- //don't interfere with stuff that is already enabled properly
- if (%orig == YES){
- //NSLog(@"already yes: %@",ourID );
- return %orig;
- }
- return YES;
- NSArray *whitelistArray = [NSArray arrayWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.whitelist.plist"];
- NSString *recentlyDeleted = @"/var/mobile/Library/Preferences/com.nito.deleted.plist";
- NSArray *deletedArray = nil;
- if ([[NSFileManager defaultManager] fileExistsAtPath:recentlyDeleted])
- {
- deletedArray = [NSArray arrayWithContentsOfFile:recentlyDeleted];
- }
- if ([whitelistArray containsObject:ourID] && ![deletedArray containsObject:ourID])
- {
- //NSLog(@"whitelisted: %@",ourID );
- return YES;
- } else {
- return NO;
- }
- // return %orig;
- }
- %end
- %hook PBAppInfo
- - (BOOL)isEnabled {
- //%log;
- return true;
- }
- %end
- %hook PBSAppState
- + (BOOL)isEnabledForApplicationWithIdentifier:(id)ident {
- //%log;
- return YES;
- }
- %end
|