https://github.com/codesourse...
https://github.com/zhangkn/Bi...
https://github.com/qhd/ANYMet...
前言
原理
把类及实例方法的实现都交换给了 _objc_msgForward,然后在每个类/元类都加上了forwardInvocation:方法:
`class_addMethod(hookClass, @selector(forwardInvocation:), forwardInvocationImpl, "v@:@");`
利用objc_msgSend的快速消息转发机制来实现调回原方法。
微信
[BigBang hookClass:@"WCPayLogicMgr"];
[BigBang hookClass:@"WCRedEnvelopesLogicMgr"];
[BigBang hookClass:@"ContactUpdateHelper"];
[BigBang hookClass:@"WCRedEnvelopesNetworkHelper"];
[BigBang hookClass:@"WCRedEnvelopesReceiveHomeView"]
例子
%hook MicroMessengerAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 打印某个类的所有方法的,查看所有方法的执行顺序
[KNHook hookClass:@"WCRedEnvelopesMakeRedEnvelopesViewController"];
// 清空剪切板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:@""];
NSLog(@"pasteboard:%@", pasteboard.string);
return %orig;
}
%end
观察到
Nov 2 15:30:12 iPhone WeChat[2589] <Warning>: KNHooklog :-(void)refreshViewWithData:(have 1 value)
return:(null)
value1:WCRedEnvelopesControlData--><WCRedEnvelopesControlData: 0x17d94b10>
object:<WCRedEnvelopesMakeRedEnvelopesViewController: 0x175fa800>
##########################################