Tweak.x 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 UIWindow (Additions)
  13. - (UIViewController *)visibleViewController;
  14. @end
  15. @interface NSObject (Additions)
  16. - (UIViewController *)topViewController;
  17. @end
  18. @implementation UIWindow (Additions)
  19. - (UIViewController *)visibleViewController {
  20. UIViewController *rootViewController = self.rootViewController;
  21. return [UIWindow getVisibleViewControllerFrom:rootViewController];
  22. }
  23. + (UIViewController *) getVisibleViewControllerFrom:(UIViewController *) vc {
  24. if ([vc isKindOfClass:[UINavigationController class]]) {
  25. return [UIWindow getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
  26. } else if ([vc isKindOfClass:[UITabBarController class]]) {
  27. return [UIWindow getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
  28. } else {
  29. if (vc.presentedViewController) {
  30. return [UIWindow getVisibleViewControllerFrom:vc.presentedViewController];
  31. } else {
  32. return vc;
  33. }
  34. }
  35. }
  36. @end
  37. @implementation NSObject (Additions)
  38. - (UIViewController *)topViewController {
  39. return [[[UIApplication sharedApplication] keyWindow] visibleViewController];
  40. }
  41. @end
  42. // The dylib constructor sets decryptedIPAPath, spawns a thread to do the app decryption, then exits.
  43. __attribute__ ((constructor)) static void FLEXInjected_main() {
  44. NSBundle *bundle = [NSBundle mainBundle];
  45. NSString *bundleID = [bundle bundleIdentifier];
  46. NSDictionary *ourDict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.nito.flexinjected.plist"];
  47. NSNumber *value = [ourDict objectForKey:bundleID];
  48. NSLog(@"[FLEXInjected) bundle ID %@", bundleID);
  49. if ([value boolValue] == YES) {
  50. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  51. NSLog(@"[FLEXInjected] weouchea...");
  52. NSString *p = @"/Library/Frameworks/FLEX.framework";
  53. NSBundle *bundle = [NSBundle bundleWithPath:p];
  54. [bundle load];
  55. id flexManager = [%c(FLEXManager) sharedManager];
  56. UIViewController *tvc = [[UIApplication sharedApplication] topViewController];
  57. if([tvc respondsToSelector: @selector(tabBarController)]){
  58. UITabBarController *tabBar = [tvc tabBarController];
  59. if (tabBar) tvc = tabBar;
  60. }
  61. NSLog(@"[FLEXInjected] top view controller: %@ violated...", tvc);
  62. [flexManager _addTVOSGestureRecognizer:tvc];
  63. [flexManager showExplorer];
  64. });
  65. NSLog(@"[FLEXInjected] All done, exiting constructor.");
  66. }
  67. }