[英]Theos: How to hook a method with a block argument? (CDUnknownBlockType)
[英]Hook to an instance method in iOS using theos and retrieve the argument that is being passed
-(void)setID:(long long)是方法,我想检索要传递的参数 (整数)并在警报视图中显示 。 我是新手,请帮助我。 并且,如果可能的话,如何将此参数传递给其他方法。
-(void)setSelectedID:(long long) ,如果这是我要将参数传递给的方法,我将如何在Tweaks.xm文件中执行此操作。
任何帮助,将不胜感激,谢谢。
也可以使用Cycript完成吗?
这段代码未经测试,但希望能对您有所帮助(假设setSelectedID:
是您创建的方法):
// Use parenthesis to avoid creating a duplicate definition of TheClassToHook
@interface TheClassToHook ()
// Put your new method definitions here
- (void)setSelectedID:(long long)passedID;
@end
%hook TheClassToHook
// This is the original method from TheClassToHook
- (void)setID:(long long)passedID {
// Call your new method
[self setSelectedID:passedID];
// Create an NSString from the passed id,
// it will be used to show it in the alert as a message
NSString *msg = [NSString stringWithFormat:@"%lld", passedID];
// Show an alert using UIAlertView, note that TheClassToHook should implement UIAlertViewDelegate
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The passed id is..."
message:msg
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// Optional: Make sure the memory used to allocate the alert and its message are released,
// this may be unnecessary
[alert release];
[msg release];
/* NOTE:
UIAlertView is deprecated since iOS 8,
if you don't want to target older iOS versions,
you should consider using UIAlertController instead
*/
// Call the original method with the original arguments
%orig;
}
// Use the "%new" logos directive to implement a new method
%new
- (void)setSelectedID:(long long)passedID {
// Your code
}
%end // close %hook
如果setSelectedID:
是默认存在的方法,则只需从@interface
块及其%hook
块中的实现中删除其定义即可。
另外,由于我不使用Cycript,所以不知道是否可以使用Cycript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.