objective-c - 查找已调配的方法
问题描述
如果我正在使用 lldb 调试 Mach-O 二进制文件,我可以检查内存中的哪些数据结构以确定是否有任何方法被混合?我可以遵循任何步骤吗?
另外,有没有办法以编程方式确定是否有任何方法被混合?
解决方案
既然你提到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
}
推荐阅读
- reactjs - 如何在反应项目中执行节点脚本?
- c++ - 无法为小于 max_size 的大小创建大于 max_size() 的 std::vector
- node.js - 我如何从冒号之间剥离一些东西并检索它的最后一个
- css - 是否可以在同一行上使 css 网格溢出
- css - 在 10 月 CMS 中编译 Sass 文件时出现意外结果
- swagger - OpenAPI 能否以有用的方式集成 HATEOAS?
- java - Forge 1.12.2 mod 中的项目名称无法正确呈现
- java - 如何关闭特定玩家的聊天?
- javascript - 收集并总计时间间隔
- list - 如何随机混合两个 PyTorch 张量