使用theos挂钩到iOS中的实例方法,并检索要传递的参数 [英] Hook to an instance method in iOS using theos and retrieve the argument that is being passed
问题描述
-(void)setID:(long long) 是方法,我想检索正在传递的 argument (整数),在<警告>视图中显示它.我是新来的,请帮助我.以及如果可能的话,如何将此参数传递给其他方法.
-(void)setSelectedID:(long long) ,如果这是我要将参数传递给的方法,我将如何在 Tweaks中进行操作. xm 文件.
任何帮助将不胜感激,谢谢.
也可以使用Cycript完成此操作吗?
-(void)setID:(long long) is the method and I want retrieve the argument (the integer) being passed and show it in an alert view. 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.
Any help would be appreciated, thanks.
Can this also be done using Cycript?
推荐答案
此代码未经测试,但希望对您有所帮助(假设setSelectedID:
是您创建的方法):
this code is untested but I hope it can help (assuming that setSelectedID:
is a method that you made) :
// 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
块中删除其实现即可.
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.
而且,由于我不使用Cycript,所以不知道是否可以使用Cycript.
Also, since I don't use Cycript, I don't know if it can be done using it, sorry.
这篇关于使用theos挂钩到iOS中的实例方法,并检索要传递的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!