main.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //#import "PBReloadHelper.h"
  2. #import <Foundation/Foundation.h>
  3. #import <objc/runtime.h>
  4. //#import "rocketbootstrap.h"
  5. //#import "AppSupport/CPDistributedMessagingCenter.h"
  6. @interface NSDistributedNotificationCenter : NSNotificationCenter
  7. + (id)defaultCenter;
  8. - (void)addObserver:(id)arg1 selector:(SEL)arg2 name:(id)arg3 object:(id)arg4;
  9. - (void)postNotificationName:(id)arg1 object:(id)arg2 userInfo:(id)arg3;
  10. @end
  11. @interface MessageHandler : NSObject
  12. -(void)runAppEnabler:(id)a;
  13. - (void)swizzleMeTimbers;
  14. @end
  15. @implementation MessageHandler
  16. - (BOOL)originalIsEnabled {
  17. NSLog(@"originalIsEnabled");
  18. return TRUE;
  19. }
  20. - (BOOL)ourIsEnabled {
  21. NSLog(@"ourIsEnabled");
  22. BOOL orig = [(id)self ourIsEnabled];
  23. if (orig) return orig;
  24. return TRUE;
  25. }
  26. - (void)swizzleMeTimbers {
  27. NSLog(@"swizzleMeTimbers2");
  28. static dispatch_once_t onceToken2;
  29. Class mutableAppState = NSClassFromString(@"PBSMutableAppState");
  30. NSLog(@"mutableAppState: %@", mutableAppState);
  31. Method sourceMutableAppState = class_getInstanceMethod(mutableAppState, @selector(isEnabled));
  32. NSLog(@"mutableAppState: %@", sourceMutableAppState);
  33. dispatch_once(&onceToken2, ^{
  34. // get the class definition responsible for populating the context menu
  35. Method ourEnabledReplacement = class_getInstanceMethod([self class], @selector(ourIsEnabled));
  36. class_addMethod(mutableAppState, @selector(originalIsEnabled), method_getImplementation(ourEnabledReplacement), method_getTypeEncoding(ourEnabledReplacement));
  37. Method sourceEnabledOriginal = class_getInstanceMethod(mutableAppState, @selector(originalIsEnabled));
  38. method_exchangeImplementations(sourceMutableAppState, sourceEnabledOriginal);
  39. });
  40. }
  41. -(void)runAppEnabler:(id)a
  42. {
  43. //NSLog(@"#### for luck!");
  44. // [PBReloadHelper reloadApplications];
  45. }
  46. @end
  47. __attribute__ ((__constructor__))
  48. void pre_func(void) {
  49. NSLog(@"pre_func22\n");
  50. MessageHandler *mh = [MessageHandler new];
  51. [mh swizzleMeTimbers];
  52. /*
  53. dispatch_async(dispatch_get_main_queue(), ^(void){
  54. NSDistributedNotificationCenter* notificationCenter = [NSDistributedNotificationCenter defaultCenter];
  55. [notificationCenter addObserver:[MessageHandler new] selector:@selector(runAppEnabler:) name:@"kjc.AppEnabler.recache" object:nil];
  56. });
  57. */
  58. }