ÀûÓÃiosµÄhook»úÖÆÊµÏÖadobe air ios aneÏÂappdelegateµÄ¶¯Ì¬Ìæ»»
¿ª·¢±³¾°
ÀûÓÃadobe air¿ª·¢ÍêÓÎÏ·ºó£¬ÐèÒªÕë¶Ôios»òÕßandroidƽ̨½øÐÐÖ§¸¶¡¢ÍÆË͵Äsdk½ÓÈ룬±¾ÎÄ¿ÉÒÔÓÃÀ´³¹µ×½â¾öiosƽ̨ÏÂdelegateÉúÃüÖÜÆÚ¼¸¸ö»Øµ÷º¯ÊýµÄµ÷Óã¬ÊµÏÖÔÉúµÄÍÆËÍ¡¢Ö§¸¶¹¦ÄܵĽÓÈë
hook֪ʶ±³¾°
£¨objcÀïµÄMethod Swizzling£¬±¾½ÚÄÚÈÝת×Ôhttp://blog.csdn.net/yiyaaixuexi£
ÔÚObjective-CÖе÷ÓÃÒ»¸ö·½·¨£¬ÆäʵÊÇÏòÒ»¸ö¶ÔÏó·¢ËÍÏûÏ¢£¬²éÕÒÏûÏ¢µÄΨһÒÀ¾ÝÊÇselectorµÄÃû×Ö¡£ÀûÓÃObjective-CµÄ¶¯Ì¬ÌØÐÔ£¬¿ÉÒÔʵÏÖÔÚÔËÐÐʱ͵»»selector¶ÔÓ¦µÄ·½·¨ÊµÏÖ£¬´ïµ½¸ø·½·¨¹Ò¹³µÄÄ¿µÄ¡£
ÿ¸öÀà¶¼ÓÐÒ»¸ö·½·¨ÁÐ±í£¬´æ·Å×ÅselectorµÄÃû×ֺͷ½·¨ÊµÏÖµÄÓ³Éä¹ØÏµ¡£IMPÓеãÀà似º¯ÊýÖ¸Õ룬ָÏò¾ßÌåµÄMethodʵÏÖ¡£
ÎÒÃÇ¿ÉÒÔÀûÓà method_exchangeImplementations À´½»»»2¸ö·½·¨ÖеÄIMP£¬
ÎÒÃÇ¿ÉÒÔÀûÓà class_replaceMethod À´ÐÞ¸ÄÀ࣬
ÎÒÃÇ¿ÉÒÔÀûÓà method_setImplementation À´Ö±½ÓÉèÖÃij¸ö·½·¨µÄIMP£¬
¡¡
¹é¸ù½áµ×£¬¶¼ÊÇ͵»»ÁËselectZ†·Ÿ"http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcrXESU1Qo6zI58/CzbzL+cq+o7o8YnI+CjwvcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20141111/2014111108225471.png" alt="\">
ʵÏÖ˼·
1¡¢ÔÚMDChangeDelegateHelperÀà¼ÓÔØ½×¶Î¾Í¶Ôadboe airµÄappdelegateÀà½øÐз½·¨hook£¬È·±£ÔÚadobe airµÄappdelegateÔÚ´´½¨Ç°Ìæ»»³ÉÎÒÃÇÐÂʵÏÖµÄÀà
2¡¢ÐèÒª3¸öSEL£¬
Ò»¸öAppDelegateÔSEL£ºoldSEL£¬
Ò»¸öMDChangeDelegateHelperµÄĬÈÏSEL£ºdefaultSEL£¬ÓÃÓÚΪÔappdelegateÌí¼ÓĬÈϵÄÔoldSEL
Ò»¸öMDChangeDelegateHelperµÄÄ¿±êSEL£ºnewSEL
·½·¨Ì滻˼·£º
3¡¢Ìæ»»ºó¶ÔÓ¦µÄsel¹ØÏµÎª
oldSEL -- newMethod
newSEL -- oldMethod
ËùÒÔµ±¶ÔÓ¦µÄappdelegate·½·¨±»µ÷ÓÃʱ£¬
oldSELÕÒµ½ÁËnewMethodµÄʵÏÖ£¬newMethodµÄʵÏÖÔÚMDChangeDelegateHelper.mÄÚµÄhookedxxx·½·¨
ÔÚnewMetholdÖе÷ÓÃÁËnewSEL£¬newSELÖ¸ÏòoldMethod£¬ÊµÏÖÁËÔÁ÷³ÌµÄ¼æÈÝ
´úÂëʵÏÖ
//// MDChangeDelegateHelper.m// ChangeDelegateDemo//// Created by ashqal on 14-10-31.// Copyright (c) 2014Äê moredoo. All rights reserved.//#import "MDChangeDelegateHelper.h"#import #import void hookMethod(SEL oldSEL,SEL defaultSEL, SEL newSEL){ //CTAppController Class aClass = objc_getClass("CTAppController"); if ( aClass == 0 ) { NSLog(@"!!!!!!!!!!!!!did not find adobe class!"); return; } Class bClass = [MDChangeDelegateHelper class]; //°Ñ·½·¨¼Ó¸øaClass class_addMethod(aClass, newSEL, class_getMethodImplementation(bClass, newSEL),nil); class_addMethod(aClass, oldSEL, class_getMethodImplementation(bClass, defaultSEL),nil); Method oldMethod = class_getInstanceMethod(aClass, oldSEL); assert(oldMethod); Method newMethod = class_getInstanceMethod(aClass, newSEL); assert(newMethod); method_exchangeImplementations(oldMethod, newMethod); }@implementation MDChangeDelegateHelper+ (void)load{ NSLog(@"MDChangeDelegateHelper load"); //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createStarterNotificationChecker:) //name:@"UIApplicationWillFinishLaunchingNotification" object:nil]; //[self changeDelegate]; hookMethod( @selector(application:didFinishLaunchingWithOptions:) ,@selector(defaultApplication:didFinishLaunchingWithOptions:) ,@selector(hookedApplication:didFinishLaunchingWithOptions:) ); hookMethod( @selector(application:handleOpenURL:) , @selector(defaultApplication:handleOpenURL:) , @selector(hookedApplication:handleOpenURL:) ); hookMethod(@selector(application:openURL:sourceApplication:annotation:) , @selector(defaultApplication:openURL:sourceApplication:annotation:) , @selector(hookedApplication:openURL:sourceApplication:annotation:)); hookMethod(@selector(application:supportedInterfaceOrientationsForWindow:) , @selector(defaultApplication:supportedInterfaceOrientationsForWindow:) , @selector(hookedApplication:supportedInterfaceOrientationsForWindow:) ); hookMethod(@selector(applicationDidBecomeActive:) , @selector(defaultApplicationDidBecomeActive:) , @selector(hookedApplicationDidBecomeActive:) ); hookMethod(@selector(init) , @selector(init) , @selector(hookedInit) );}-(BOOL)hookedApplication:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)dic{ NSLog(@"hooked didFinishLaunchingWithOptions"); [self hookedApplication:application didFinishLaunchingWithOptions:dic]; return YES;}-(id)hookedInit{ NSLog(@"hooked init!!!"); return [self hookedInit];}- (BOOL)hookedApplication:(UIApplication *)application handleOpenURL:(NSURL *)url { NSLog(@"hooked handleOpenURL"); [self hookedApplication:application handleOpenURL:url]; return YES;}- (BOOL)hookedApplication:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ NSLog(@"hooked openURL sourceApplication annotation"); [self hookedApplication:application openURL:url sourceApplication:sourceApplication annotation:annotation]; return YES;}- (NSUInteger) hookedApplication:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ NSLog(@"hooked supportedInterfaceOrientationsForWindow"); [self hookedApplication:application supportedInterfaceOrientationsForWindow:window ]; return 0;}- (void)hookedApplicationDidBecomeActive:(UIApplication *)application{ [self hookedApplicationDidBecomeActive:application]; NSLog(@"hooked applicationDidBecomeActive");}- (BOOL)defaultApplication:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)dic{ return YES;}- (BOOL)defaultApplication:(UIApplication *)application handleOpenURL:(NSURL *)url{return YES;}- (BOOL)defaultApplication:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{return YES;}- (NSUInteger) defaultApplication:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{return 0;}- (void)defaultApplicationDidBecomeActive:(UIApplication *)application{}- (id)init{ self = [super init]; if (self) { } return self;}@end
×¢Òâµã
a) ÔÚÔËÐÐʱnslog³öadobe airµÄappdelegateÃû×ÖΪCTAppController£¬ËùÒÔ½«´ËÀà×÷ÎªÌæ»»¶ÔÏó
b) ÔÚ¶Ôinitº¯Êý½øÐÐÌæ»»Ê±·¢ÏÖCTAppControllerûÓÐʵÏÖinitº¯Êý£¬ËùÒÔ½«Ä¬ÈϵÄinitº¯Êý×öÁË»ù´¡ÊµÏÖ£¬²»È»ÎÞ·¨´´½¨ÊµÀýÁË