Tweak.x 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. #include <TargetConditionals.h>
  4. @interface NSObject (topViewController)
  5. - (id)topViewController;
  6. @end
  7. @interface FLEXManager: NSObject
  8. +(id)sharedManager;
  9. -(void)showExplorer;
  10. -(void)showHintsIfNecessary;
  11. -(void)_addTVOSGestureRecognizer:(UIViewController *)explorer;
  12. @end
  13. @interface NSDistributedNotificationCenter : NSNotificationCenter
  14. + (id)defaultCenter;
  15. - (void)addObserver:(id)arg1 selector:(SEL)arg2 name:(id)arg3 object:(id)arg4;
  16. - (void)postNotificationName:(id)arg1 object:(id)arg2 userInfo:(id)arg3;
  17. @end
  18. @interface UIWindow (Additions)
  19. - (UIViewController *)visibleViewController;
  20. @end
  21. @interface NSObject (Additions)
  22. - (UIViewController *)topViewController;
  23. @end
  24. @implementation UIWindow (Additions)
  25. - (UIViewController *)visibleViewController {
  26. UIViewController *rootViewController = self.rootViewController;
  27. return [UIWindow getVisibleViewControllerFrom:rootViewController];
  28. }
  29. + (UIViewController *) getVisibleViewControllerFrom:(UIViewController *) vc {
  30. if ([vc isKindOfClass:[UINavigationController class]]) {
  31. return [UIWindow getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
  32. } else if ([vc isKindOfClass:[UITabBarController class]]) {
  33. return [UIWindow getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
  34. } else {
  35. if (vc.presentedViewController) {
  36. return [UIWindow getVisibleViewControllerFrom:vc.presentedViewController];
  37. } else {
  38. return vc;
  39. }
  40. }
  41. }
  42. @end
  43. @interface LSApplicationProxy: NSObject
  44. +(id)applicationProxyForIdentifier:(id)sender;
  45. +(id)tv_applicationFlatIcon;
  46. -(BOOL)isContainerized;
  47. @end
  48. @implementation NSObject (Additions)
  49. - (UIViewController *)topViewController {
  50. return [[[UIApplication sharedApplication] keyWindow] visibleViewController];
  51. }
  52. @end
  53. static void sendNotification(NSString *title, NSString *message, UIImage *image) {
  54. NSMutableDictionary *dict = [NSMutableDictionary new];
  55. dict[@"message"] = message;
  56. dict[@"title"] = title;
  57. dict[@"timeout"] = [NSNumber numberWithInteger:4];
  58. if (image){
  59. NSData *imageData = UIImagePNGRepresentation(image);
  60. if (imageData){
  61. dict[@"imageData"] = imageData;
  62. }
  63. }
  64. [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.nito.bulletinh4x/displayBulletin" object:nil userInfo:dict];
  65. }
  66. __attribute__ ((constructor)) static void FLEXInjected_main() {
  67. NSBundle *bundle = [NSBundle mainBundle];
  68. NSString *bundleID = [bundle bundleIdentifier];
  69. NSDictionary *ourDict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.flexinjected.plist"];
  70. NSArray *iconBlacklist = @[@"com.apple.PineBoard", @"com.apple.HeadBoard"];
  71. NSNumber *value = [ourDict objectForKey:bundleID];
  72. if ([value boolValue] == YES) {
  73. BOOL sendAlert = true;
  74. id prox = [%c(LSApplicationProxy) applicationProxyForIdentifier:bundleID];
  75. UIImage *icon = nil;
  76. if (prox){
  77. NSLog(@"[FLEXInjected] found prox: %@", prox);
  78. if ([prox isContainerized]){
  79. icon = nil;
  80. } else {
  81. if ([prox respondsToSelector:@selector(tv_applicationFlatIcon)] && ![iconBlacklist containsObject:bundleID]){
  82. icon = [prox tv_applicationFlatIcon];
  83. }
  84. }
  85. } else { //no prox found
  86. NSString *mcsPath = @"/System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices";
  87. [[NSBundle bundleWithPath:mcsPath] load];
  88. prox = [%c(LSApplicationProxy) applicationProxyForIdentifier:bundleID];
  89. if ([prox isContainerized]){
  90. icon = nil;
  91. } else {
  92. if ([prox respondsToSelector:@selector(tv_applicationFlatIcon)] && ![iconBlacklist containsObject:bundleID]){
  93. icon = [prox tv_applicationFlatIcon];
  94. }
  95. }
  96. }
  97. NSLog(@"[FLEXInjected] found icon: %@", icon);
  98. if (sendAlert){
  99. NSString *message = [NSString stringWithFormat:@"Injected into bundle: %@", bundleID];
  100. sendNotification(@"FLEXInjected", message, icon);
  101. NSLog(@"[FLEXInjected) bundle ID %@", bundleID);
  102. }
  103. NSLog(@"[FLEXInjected] post send alert");
  104. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  105. NSLog(@"[FLEXInjected] weouchea...");
  106. NSString *p = @"/Library/Frameworks/FLEX.framework";
  107. NSBundle *bundle = [NSBundle bundleWithPath:p];
  108. [bundle load];
  109. id flexManager = [%c(FLEXManager) sharedManager];
  110. UIViewController *tvc = [[UIApplication sharedApplication] topViewController];
  111. if([tvc respondsToSelector: @selector(tabBarController)]){
  112. UITabBarController *tabBar = [tvc tabBarController];
  113. if (tabBar) tvc = tabBar;
  114. }
  115. NSLog(@"[FLEXInjected] top view controller: %@ violated...", tvc);
  116. [flexManager _addTVOSGestureRecognizer:tvc];
  117. [flexManager showExplorer];
  118. if ([flexManager respondsToSelector:@selector(showHintsIfNecessary)]){
  119. [flexManager showHintsIfNecessary];
  120. }
  121. });
  122. }
  123. }