[英]Hook to an instance method in iOS using theos and retrieve the argument that is being passed
-(void)setID:(long long) is the method and I want retrieve the argument (the integer) being passed and show it in an alert view . -(void)setID:(long long)是方法,我想检索要传递的参数 (整数)并在警报视图中显示 。 I am new to this please help me.
我是新手,请帮助我。 And also if possible, how to pass this argument to a different method.
并且,如果可能的话,如何将此参数传递给其他方法。
-(void)setSelectedID:(long long) , if this is the method I want to pass the arguments to, how would I do it in the Tweaks.xm file. -(void)setSelectedID:(long long) ,如果这是我要将参数传递给的方法,我将如何在Tweaks.xm文件中执行此操作。
Any help would be appreciated, thanks. 任何帮助,将不胜感激,谢谢。
Can this also be done using Cycript? 也可以使用Cycript完成吗?
this code is untested but I hope it can help (assuming that setSelectedID:
is a method that you made) : 这段代码未经测试,但希望能对您有所帮助(假设
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
If setSelectedID:
is a method that is present by default, you can just remove its definition from the @interface
block and its implementation in the %hook
block. 如果
setSelectedID:
是默认存在的方法,则只需从@interface
块及其%hook
块中的实现中删除其定义即可。
Also, since I don't use Cycript, I don't know if it can be done using it, sorry. 另外,由于我不使用Cycript,所以不知道是否可以使用Cycript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.