是否有任何优雅的方式可以将隐藏的方法恢复到iOS上的原始实现?

时间:2015-02-11 11:54:13

标签: ios objective-c hook jailbreak cydia-substrate

使用CydiaSubstrate我们可以轻松地挂钩方法,但我想知道如何卸载挂钩并将实现恢复为原始方法?谢谢!

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_);

1 个答案:

答案 0 :(得分:1)

您只需要再次交换实现,即只需再次调用以下内容:

MSHookMessageEx([UIView class], @selector(setFrame:), (IMP)replaced_UIView_setFrame_, (IMP *)&original_UIView_setFrame_);

当你交换实现时,你正在交换它们,所以通过再次交换它们你会回到原件。