【问题标题】:Find methods that have been swizzled查找已调配的方法
【发布时间】:2020-08-24 06:32:17
【问题描述】:

如果我正在使用 lldb 调试 Mach-O 二进制文件,我可以检查内存中的哪些数据结构以确定是否有任何方法被混用?我可以遵循什么步骤?

另外,有没有办法以编程方式确定是否有任何方法被调配?

【问题讨论】:

标签: objective-c lldb


【解决方案1】:

既然你提到了lldb,你可以设置符号断点:

b method_exchangeImplementation
b method_setImplementation
b class_replaceMethod

当您遇到以下断点时:
method_exchangeImplementations(Method _Nonnull m1, Method _Nonnull m2)
您可以像这样检查 m1 m2 args 选择器名称:

po (SEL)method_getName($arg1)
po (SEL)method_getName($arg2)

对于method_setImplementation(Method _Nonnull m, IMP _Nonnull imp)

po (SEL)method_getName($arg1)

对于class_replaceMethod(Class cls, SEL name, IMP imp, const char *types)

po $arg1
po (SEL)method_getName($arg2)

那些Method 可能会通过之前的调用产生:

class_getInstanceMethod(Class _Nullable cls, SEL _Nonnull name)
class_getClassMethod(Class _Nullable cls, SEL _Nonnull name)

之后:

b class_getInstanceMethod
b class_getClassMethod

并点击相应的断点,检查类:

po $arg1 

检查选择器:

po (SEL)method_getName($arg2)

设置这些符号断点的最佳位置是这里:

__attribute__((constructor))
static void premain() {
int i = 0;
i++; // put xcode breakpoint here and when hit prep your lldb symbolic bps
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多