Skip to content

关于 Class、 Instance hook 同一个方法,Class 的 hook 会重复执行的解决方法 #27

@YiHuaXie

Description

@YiHuaXie

同一个方法在先执行 class hook,后执行 instance hook时,hook切面会调用多次,即 _st_ffi_function 函数被调用多次。
按我的理解 hookMethod(Class hookedCls, SEL sel, 。...) 这个函数下, IMP originalImp = method_getImplementation(m); 这个 IMP 在先 class hook,后 instance hook 取到的是已经是一个 stingerIMP 了,相当于 stingerIMP -> stingerIMP -> originalIMP 所以 _st_ffi_function 调用了多次

这是我的改法

Image

st_getRealClass 函数就是把前缀去掉 获取声明类,这么改应该是最小成本的改动了吧

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions