使用 CydiaSubstrate
我们可以很容易地钩住下面的方法,但我想知道我怎样才能卸载钩子(Hook)并将实现恢复到原来的方式?谢谢!
static IMP original_UIView_setFrame_;
void replaced_UIView_setFrame_(UIView* self, SEL _cmd, CGRect frame) { // Note the implicit self and _cmd parameters are needed explicitly here.
CGRect originalFrame = self.frame;
NSLog("Changing frame of %p from %@ to %@", self, NSStringFromCGRect(originalFrame), NSStringFromCGRect(frame));
original_UIView_setFrame_(self, _cmd, frame); // Remember to pass self and _cmd.
}
...
MSHookMessageEx([UIView class], @selector(setFrame:), (IMP)replaced_UIView_setFrame_, (IMP *)&original_UIView_setFrame_);
最佳答案
您只需要再次交换实现,即再次调用以下代码:
MSHookMessageEx([UIView class], @selector(setFrame:), (IMP)replaced_UIView_setFrame_, (IMP *)&original_UIView_setFrame_);
当你交换实现时,你就是在交换它们,所以通过再次交换它们,你会回到原来的状态。
关于ios - 有没有什么优雅的方法可以将 Hook 方法恢复到 iOS 上的原始实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28453721/