Joh*_*ith 8 reverse-engineering objective-c iphone-privateapi ios
我知道有很多关于方法调配的资源.但是,是否可以从私有API中调用方法?问题是没有头文件.我想在PrivateFramework中调用私有类中的方法,例如(随机示例)Message.framework方法
这是个人测试,我知道它会被Apple拒绝遗忘.
您可以使用NSClassFromString获取Class和使用运行时库来执行方法调配.无需头文件.您只需要知道类名和方法签名.
sel_getUid当@selector(somePrivateMethod)你的错误提供somePrivateMethod无效的选择器时可以使用(因为标头不可用)
从我的Xcode插件中获取的代码
SEL sel = sel_getUid("codeDiagnosticsAtLocation:withCurrentFileContentDictionary:forIndex:");
Class IDEIndexClangQueryProviderClass = NSClassFromString(@"IDEIndexClangQueryProvider");
Method method = class_getInstanceMethod(IDEIndexClangQueryProviderClass, sel);
IMP originalImp = method_getImplementation(method);
IMP imp = imp_implementationWithBlock(^id(id me, id loc, id dict, IDEIndex *idx) {
id ret = ((id (*)(id,SEL,id,id,id))originalImp)(me, sel, loc, dict, idx);
// do work
return ret;
});
method_setImplementation(method, imp);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2500 次 |
| 最近记录: |