#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