eleme / Stinger

Stinger is a high-efficiency library with great compatibility, for aop in Objective-C, using libffi instead of Objective-C message forwarding. It is 20+ times faster than the Aspects, from message-sending to Aspect-oriented code ends.
MIT License
994 stars 127 forks source link

怎么样hook方法在方法执行之前修改参数 #23

Open xygkevin opened 1 year ago

xygkevin commented 1 year ago

怎么样hook方法在方法执行之前修改参数

xygkevin commented 1 year ago

比如:

typedef void(^XXURLRequestCompletionBlock)(NSData *, NSURLResponse *, NSError *);

[NSURLSession st_hookInstanceMethod:@selector(dataTaskWithRequest:completionHandler:) option:STOptionBefore usingIdentifier:@"session_before" withBlock:^(id<StingerParams> params, NSMutableURLRequest *request, XXURLRequestCompletionBlock completionHandler){
}];

我想在NSURLSession的dataTaskWithRequest:completionHandler:方法执行之前修改参数,包括request以及completionHandler的实现,以便于在completionHandler调用的时候执行其他处理;

Fxxxxxx commented 2 months ago

可以试下我这个PR的代码,https://github.com/eleme/Stinger/pull/25

xygkevin commented 4 weeks ago

可以试下我这个PR的代码,#25

完全匹配我的需求,经过一段时间的线上运行观察,一切OK