Browse Source

slimmed down version that doesn't use PBReloadHelper at all.

Kevin Bradley 4 years ago
parent
commit
a9da192a48
8 changed files with 278 additions and 22 deletions
  1. 5 3
      AppEnabler/Makefile
  2. 43 0
      AppEnabler/Whitelist.xm
  3. 1 1
      Makefile
  4. 1 1
      control
  5. 62 6
      main.m
  6. 1 1
      theos/bin/fakeroot.sh
  7. 21 0
      uicache/Makefile
  8. 144 10
      uicache/uicache.m

+ 5 - 3
AppEnabler/Makefile

@@ -7,13 +7,15 @@ THEOS_DEVICE_IP=atv.local
 include $(THEOS)/makefiles/common.mk
 
 TWEAK_NAME = AppEnabler
-AppEnabler_FILES = main.x Whitelist.xm ../PBReloadHelper.m
-AppEnabler_LIBRARIES = substrate
+#AppEnabler_FILES = main.x Whitelist.xm ../PBReloadHelper.m
+AppEnabler_FILES = Whitelist.xm 
+AppEnabler_LIBRARIES = substrate 
 AppEnabler_FRAMEWORKS = Foundation UIKit CoreGraphics MobileCoreServices
-AppEnabler_LDFLAGS = -undefined dynamic_lookup
+#AppEnabler_LDFLAGS = -undefined dynamic_lookup
 AppEnabler_CODESIGN=ldid2
 #AppEnabler_LIBRARIES += rocketbootstrap
 AppEnabler_CODESIGN_FLAGS=-Slibrespring.xml
+#AppEnabler_USE_SUBSTRATE=0
 
 include $(THEOS_MAKE_PATH)/tweak.mk
 

+ 43 - 0
AppEnabler/Whitelist.xm

@@ -16,6 +16,27 @@
 
 @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
@@ -95,6 +116,25 @@
     
 }
 
+%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];
+        [power _performUserEventWakeDevice];
+        [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
+
+}
 
 %new - (void)delayedNitoTVLaunch:(id)note {
 
@@ -115,6 +155,8 @@
     
     //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]){
@@ -144,6 +186,7 @@
         //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;

+ 1 - 1
Makefile

@@ -4,7 +4,7 @@ export GO_EASY_ON_ME=1
 export SDKVERSION=10.1
 TARGET=appletv:clang:10.1:10.1
 SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS10.1.sdk
-THEOS_DEVICE_IP=btv.local
+THEOS_DEVICE_IP=bedroom.local
 
 include theos/makefiles/common.mk
 

+ 1 - 1
control

@@ -2,7 +2,7 @@ Package: com.nito.uicache
 Name: uicache
 Pre-Depends: cy+model.appletv
 Depends:
-Version: 0.0.2
+Version: 0.0.3
 Architecture: appletvos-arm64
 Description: Respring and reload any applications added to /Applications
 Maintainer: Kevin Bradley

+ 62 - 6
main.m

@@ -1,8 +1,8 @@
-#import "PBReloadHelper.h"
+//#import "PBReloadHelper.h"
 #import <Foundation/Foundation.h>
 #import <objc/runtime.h>
-#import "rocketbootstrap.h"
-#import "AppSupport/CPDistributedMessagingCenter.h"
+//#import "rocketbootstrap.h"
+//#import "AppSupport/CPDistributedMessagingCenter.h"
 
 @interface NSDistributedNotificationCenter : NSNotificationCenter
 
@@ -15,20 +15,75 @@
 
 @interface MessageHandler : NSObject
 -(void)runAppEnabler:(id)a;
+- (void)swizzleMeTimbers;
 @end
 @implementation MessageHandler
 
+- (BOOL)originalIsEnabled {
+    
+    NSLog(@"originalIsEnabled");
+    return TRUE;
+    
+}
+
+- (BOOL)ourIsEnabled {
+    
+    NSLog(@"ourIsEnabled");
+    BOOL orig = [(id)self ourIsEnabled];
+    
+    if (orig) return orig;
+
+    return TRUE;
+    
+}
+
+- (void)swizzleMeTimbers {
+    
+    NSLog(@"swizzleMeTimbers2");
+    
+    static dispatch_once_t onceToken2;
+    
+    Class mutableAppState = NSClassFromString(@"PBSMutableAppState");
+    
+    NSLog(@"mutableAppState: %@", mutableAppState);
+    
+    Method sourceMutableAppState = class_getInstanceMethod(mutableAppState, @selector(isEnabled));
+    
+    NSLog(@"mutableAppState: %@", sourceMutableAppState);
+    
+    dispatch_once(&onceToken2, ^{
+        
+        
+        // get the class definition responsible for populating the context menu
+      
+        
+        Method ourEnabledReplacement = class_getInstanceMethod([self class], @selector(ourIsEnabled));
+        class_addMethod(mutableAppState, @selector(originalIsEnabled), method_getImplementation(ourEnabledReplacement), method_getTypeEncoding(ourEnabledReplacement));
+        
+        
+        Method sourceEnabledOriginal = class_getInstanceMethod(mutableAppState, @selector(originalIsEnabled));
+        method_exchangeImplementations(sourceMutableAppState, sourceEnabledOriginal);
+        
+    });
+    
+}
+
 -(void)runAppEnabler:(id)a
 {
     //NSLog(@"#### for luck!");
-    [PBReloadHelper reloadApplications];
+  //  [PBReloadHelper reloadApplications];
 }
 
 @end
 __attribute__ ((__constructor__))
 void pre_func(void) {
-    //NSLog(@"pre_func\n");
-
+    NSLog(@"pre_func22\n");
+    
+    MessageHandler *mh = [MessageHandler new];
+    [mh swizzleMeTimbers];
+    
+    
+/*
     dispatch_async(dispatch_get_main_queue(), ^(void){
 
         NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
@@ -37,4 +92,5 @@ void pre_func(void) {
 
         
     });
+ */
 }

+ 1 - 1
theos/bin/fakeroot.sh

@@ -42,5 +42,5 @@ else
 	fi
 fi
 
-#echo $fakeroot $cmd
+echo $fakeroot $cmd
 $fakeroot $cmd

+ 21 - 0
uicache/Makefile

@@ -1,5 +1,6 @@
 IPHONE_ARCHS = arm64
 TARGET = appletv
+export GO_EASY_ON_ME=1
 #TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.0
 DEBUG = 0
 include $(THEOS)/makefiles/common.mk
@@ -12,5 +13,25 @@ uicache_CODESIGN=ldid2
 #uicache_LIBRARIES += rocketbootstrap
 uicache_Frameworks += WebCore ImageIO Foundation CFNetwork AppSupport UIKit IOKit MobileCoreServices
 #uicache_PRIVATE_FRAMEWORKS = GraphicsServices FMCore
+uicache_USE_SUBSTRATE=0
 
 include $(THEOS_MAKE_PATH)/tool.mk
+
+TOOL_NAME = wake
+wake_FILES = wake.m
+wake_INSTALL_PATH = /usr/bin
+wake_CODESIGN_FLAGS=-Suicache.xml
+wake_CODESIGN=ldid2
+wake_FRAMEWORKS = Foundation
+
+include $(THEOS_MAKE_PATH)/tool.mk
+
+TOOL_NAME = sleepy
+sleepy_FILES = sleep.m
+sleepy_INSTALL_PATH = /usr/bin
+sleepy_CODESIGN_FLAGS=-Suicache.xml
+sleepy_CODESIGN=ldid2
+sleepy_FRAMEWORKS = Foundation
+
+include $(THEOS_MAKE_PATH)/tool.mk
+include $(THEOS_MAKE_PATH)/aggregate.mk

+ 144 - 10
uicache/uicache.m

@@ -52,6 +52,42 @@
 #import <objc/runtime.h>
 #import "rocketbootstrap.h"
 #import "AppSupport/CPDistributedMessagingCenter.h"
+#import <MobileCoreServices/MobileCoreServices.h>
+#import "NSTask.h"
+
+#include <errno.h>
+#include <libgen.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+
+@interface PBSSystemService : NSObject
++(id)sharedInstance;
+-(void)endpointForProviderType:(id)arg1 withIdentifier:(id)arg2 responseBlock:(/*^block*/id)arg3 ;
+-(void)launchKioskApp;
+-(void)sleepSystemForReason:(id)arg1 ;
+-(void)wakeSystemForReason:(id)arg1 ;
+-(void)relaunchBackboardd;
+-(void)relaunch;
+-(void)reboot;
+-(id)infoForProvidersWithType:(id)arg1 ;
+-(void)deactivateApplication;
+-(void)registerServiceProviderEndpoint:(id)arg1 forProviderType:(id)arg2 ;
+-(void)deactivateScreenSaver;
+
+@end
+
+@interface LSApplicationWorkspace : NSObject
++ (id)defaultWorkspace;
+- (BOOL)_LSPrivateRebuildApplicationDatabasesForSystemApps:(BOOL)arg1 internal:(BOOL)arg2 user:(BOOL)arg3;
+- (BOOL)registerApplicationDictionary:(NSDictionary *)applicationDictionary;
+- (BOOL)registerBundleWithInfo:(NSDictionary *)bundleInfo options:(NSDictionary *)options type:(unsigned long long)arg3 progress:(id)arg4 ;
+- (BOOL)registerApplication:(NSURL *)url;
+- (BOOL)registerPlugin:(NSURL *)url;
+- (BOOL)unregisterApplication:(NSURL *)url;
+- (NSArray *)installedPlugins;
+-(void)_LSPrivateSyncWithMobileInstallation;
+@end
 
 #define DLog(format, ...) CFShow((__bridge CFStringRef)[NSString stringWithFormat:format, ## __VA_ARGS__]);
 
@@ -154,21 +190,92 @@ static void inject_dylib(const char* name, pid_t pid, const char* dylib) {
 @end
 @implementation MessageHandler
 
++ (NSString *)returnForProcess:(NSString *)call
+{
+    if (call==nil)
+        return 0;
+    char line[200];
+    FILE* fp = popen([call UTF8String], "r");
+    NSMutableArray *lines = [[NSMutableArray alloc]init];
+    if (fp)
+    {
+        while (fgets(line, sizeof line, fp))
+        {
+            NSString *s = [NSString stringWithCString:line encoding:NSUTF8StringEncoding];
+            s = [s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+            [lines addObject:s];
+        }
+    }
+    pclose(fp);
+    return [lines componentsJoinedByString:@"\n"];
+}
+
+- (BOOL)forceReboot {
+    
+    NSString *command = @"/usr/bin/dpkg -s com.nito.nitotv4 | grep Version | cut -d \" \" -f2";
+    int _returnCode = 0;
+    BOOL _finished = FALSE;
+    NSMutableArray *lines = [NSMutableArray new];
+    char line[200];
+    
+    FILE* fp = popen([command UTF8String], "r");
+    
+    if (fp)
+    {
+        while (fgets(line, sizeof line, fp))
+        {
+            NSString *s = [NSString stringWithCString:line encoding:NSUTF8StringEncoding];
+            s = [s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+            [lines addObject:s];
+        }
+    }
+    
+    pclose(fp);
+    BOOL reboot = FALSE;
+    NSString *version = [lines lastObject];
+    
+    //DLog(@"nitoTV version: -%@-", version);
+    
+    NSString *minimumVersion = @"2.4-103";
+    
+    //DDLogInfo(@"package: '%@' online version: '%@' installed version: '%@'", objectName, onlineVersion, installedVersion);
+    NSComparisonResult theResult = [minimumVersion compare:version options:NSNumericSearch];
+    
+    if ( theResult == NSOrderedDescending )
+    {
+        //DLog(@"minimum version %@ is less than installedVersion: %@", minimumVersion, version);
+        reboot = true;
+        
+    }
+    
+    return  reboot;
+    
+}
+
 //called from PBReloadHelper in tvOS 9 circumstances so we can rebuild the cache with proper entitlements
--(void)rebuildCache:(id)a
+-(void)rebuildCache:(BOOL)reboot
 {
     DLog(@"Rebuilding cache...\n");
+    LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace];
+    //[workspace _LSClearSchemaCaches]; //may or may not be necessary
+    [workspace _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:NO];
     
-    Class WSCLASS = objc_getClass("LSApplicationWorkspace");
+    BOOL forceReboot = [self forceReboot];
     
-    id workspace = nil;
-    if (WSCLASS != nil)
-    {
-        workspace = [WSCLASS defaultWorkspace];
+    if (reboot || forceReboot){
+         DLog(@"Respringing...\n");
+       /*
+        dlopen("/System/Library/PrivateFrameworks/PineBoardServices.framework/PineBoardServices", RTLD_NOW);
+        id systemService = [objc_getClass("PBSSystemService") sharedInstance];
+        DLog(@"system service: %@", systemService);
+        [systemService relaunchBackboardd];
+        */
+         NSString *killallPath = [MessageHandler returnForProcess:@"/usr/bin/which killall"];
+         NSTask *installTask = [NSTask launchedTaskWithLaunchPath:killallPath arguments:@[@"-9", @"backboardd"]];
+        
     }
     
-    [workspace _LSClearSchemaCaches]; //may or may not be necessary
-    [workspace _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:YES];
+    
     
 }
 
@@ -182,12 +289,39 @@ static void inject_dylib(const char* name, pid_t pid, const char* dylib) {
 
 @end
 
+#define OPTION_FLAGS "r"
+char *progname;
+
+static struct option longopts[] = {
+
+    { "reboot",                   no_argument, NULL,   'r' },
+    { NULL,         0,                      NULL,   0 }
+};
+
+
+
 int main(int argc, char* argv[]) {
     
     platformize_me();
-	printf("uicache for tvOS\n");
+	printf("uicache for tvOS slim edition\n");
+    bool reboot = false;
+    int flag;
+//    NSString *value = nil;
+    while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
+        switch(flag) {
+            case 'r':
+                reboot = true;
+                break;
+        }
+    }
+    
+    MessageHandler *mh = [MessageHandler new];
+    [mh rebuildCache:reboot];
+    return 0;
+    //[[LSApplicationWorkspace defaultWorkspace] _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:NO];
     
     /*
+    
     printf("based on asu_inject from AppSyncUnified\n");
 
 	printf("Creating queue...\n");
@@ -198,7 +332,7 @@ int main(int argc, char* argv[]) {
 
 	printf("Waiting for queue to come back...\n");
      
-     */
+    */
      
 	/* wait for queue to come back */