Tweak.x 5.2 KB

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