YSBlockHook icon indicating copy to clipboard operation
YSBlockHook copied to clipboard

可以hook具体的block吗?

Open LZRight123 opened this issue 6 years ago • 1 comments

[center addObserverForName:NSCurrentLocaleDidChangeNotification object:nil
    queue:mainQueue usingBlock:^(NSNotification *note) {
 
        NSLog(@"The user's locale changed to: %@", [[NSLocale currentLocale] localeIdentifier]);
    }];

比如我想直接hook这个block

^(NSNotification *note) {

    NSLog(@"The user's locale changed to: %@", [[NSLocale currentLocale] localeIdentifier]);
}

LZRight123 avatar May 27 '19 23:05 LZRight123

非常抱歉,这个是一个通用的HOOK机制,对于Hook特定的block对象可能会比较麻烦,如果确实要hook时你需要持有某个block对象,然后在那个HOOK函数中进行特定对象的判断。目前这个机制主要用于一些日志记录和监控用,不是用于特定的HOOK某个对象用。其他有一些可以HOOK特定对象的开源库您可以找找。

youngsoft avatar May 28 '19 02:05 youngsoft