Quantcast
Channel: 睿论坛 - 最新话题
Viewing all articles
Browse latest Browse all 5731

initialize中调用class_getInstanceMethod无法获取方法

$
0
0

@Bers wrote:

是这样,我写了一个CMessageMgr的Category,代码如下
(我是用从iOSOpenDev新建了动态库工程)

#import <objc/runtime.h>
#import "CMessageMgr+MyHook.h"
@implementation NSObject (MyHook)

 - (void)my_AsyncOnAddMsg:(NSString *)msg MsgWrap:(CMessageWrap *)wrap {
     [self my_AsyncOnAddMsg:msg MsgWrap:wrap];
     // Someting Else
 }

 static void __attribute__((constructor)) initialize(void) {
      Class class = objc_getClass("CMessageMgr");
      NSLog(@"---Exchange---");
      Method ori = class_getInstanceMethod(class, @selector(AsyncOnAddMsg:MsgWrap:));
      Method my = class_getInstanceMethod(class, @selector(my_AsyncOnAddMsg:MsgWrap:));
      NSLog(@"OriMethod: %s", method_getName(ori));
      NSLog(@"MyMethod: %s", method_getName(my));
      method_exchangeImplementations(ori, my);
 }

用scp传到/Library/MobileSubstrate/DynamicLibraries/下,然后重启SpringBoard,多次尝试,总是失败,输出如下:

……
Mar 19 00:12:52 iPhone WeChat[6514]: ---Exchange---
Mar 19 00:12:52 iPhone WeChat[6514]: OriMethod: (null)
Mar 19 00:12:52 iPhone WeChat[6514]: MyMethod: (null)
……

前面hook BaseMsgContentLogicController的方法也是如此。
但是我在initialize里头调用对应class的class_copyMethodList,然后用method_getName打印每个Method的SEL,的确是有我想要hook的方法的,然而class_getInstanceMethod就是获取不到
百思不得其解,,求教各位ORZ
(另外、、我是Google了许久仍然找不到答案才发帖问的,希望能得到帮助::>_<::)

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5731

Trending Articles