Tweak.x 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. @end
  46. @implementation NSObject (Additions)
  47. - (UIViewController *)topViewController {
  48. return [[[UIApplication sharedApplication] keyWindow] visibleViewController];
  49. }
  50. @end
  51. static void sendNotification(NSString *title, NSString *message, UIImage *image) {
  52. NSMutableDictionary *dict = [NSMutableDictionary new];
  53. dict[@"message"] = message;
  54. dict[@"title"] = title;
  55. dict[@"timeout"] = [NSNumber numberWithInteger:4];
  56. if (image){
  57. NSData *imageData = UIImagePNGRepresentation(image);
  58. if (imageData){
  59. dict[@"imageData"] = imageData;
  60. }
  61. }
  62. [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.nito.bulletinh4x/displayBulletin" object:nil userInfo:dict];
  63. }
  64. // The dylib constructor sets decryptedIPAPath, spawns a thread to do the app decryption, then exits.
  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. NSNumber *value = [ourDict objectForKey:bundleID];
  70. if ([value boolValue] == YES) {
  71. id prox = [%c(LSApplicationProxy) applicationProxyForIdentifier:bundleID];
  72. UIImage *icon = nil;
  73. if (prox){
  74. NSLog(@"[FLEXInjected] found prox: %@", prox);
  75. icon = [prox tv_applicationFlatIcon];
  76. } else {
  77. NSString *mcsPath = @"/System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices";
  78. [[NSBundle bundleWithPath:mcsPath] load];
  79. prox = [%c(LSApplicationProxy) applicationProxyForIdentifier:bundleID];
  80. icon = [prox tv_applicationFlatIcon];
  81. }
  82. NSString *message = [NSString stringWithFormat:@"Injected into bundle: %@", bundleID];
  83. sendNotification(@"FlexInjected", message, icon);
  84. NSLog(@"[FLEXInjected) bundle ID %@", bundleID);
  85. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  86. NSLog(@"[FLEXInjected] weouchea...");
  87. NSString *p = @"/Library/Frameworks/FLEX.framework";
  88. NSBundle *bundle = [NSBundle bundleWithPath:p];
  89. [bundle load];
  90. id flexManager = [%c(FLEXManager) sharedManager];
  91. UIViewController *tvc = [[UIApplication sharedApplication] topViewController];
  92. if([tvc respondsToSelector: @selector(tabBarController)]){
  93. UITabBarController *tabBar = [tvc tabBarController];
  94. if (tabBar) tvc = tabBar;
  95. }
  96. NSLog(@"[FLEXInjected] top view controller: %@ violated...", tvc);
  97. [flexManager _addTVOSGestureRecognizer:tvc];
  98. [flexManager showExplorer];
  99. });
  100. }
  101. }