【问题标题】:Is there any graceful way could revert the hooked method to original implementation on iOS?是否有任何优雅的方式可以将挂钩方法恢复为 iOS 上的原始实现?
【发布时间】:2015-04-11 18:53:05
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    当您交换实现时,您正在交换它们,因此通过再次交换它们,您将回到原来的状态。

    【讨论】:

    • 哦,非常感谢,真的很简单明了。方法很意外^^
    猜你喜欢
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 2022-01-23
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多