InspectiveC终极指南iOS调试神器如何通过objc_msgSend Hook实现消息追踪【免费下载链接】InspectiveCobjc_msgSend hook for debugging/inspection purposes.项目地址: https://gitcode.com/gh_mirrors/in/InspectiveCInspectiveC是一款基于MobileSubstrate和Fishhook的iOS调试工具通过objc_msgSend Hook技术实现Objective-C消息追踪帮助开发者深入分析应用运行时行为。本文将带你快速掌握这款调试神器的核心功能与使用方法让iOS开发调试效率提升10倍 为什么选择InspectiveC进行iOS调试作为iOS开发中不可或缺的调试工具InspectiveC具备以下核心优势全架构支持完美兼容arm64和arm32架构设备精准追踪支持监控特定对象、类实例和选择器详细日志自动记录方法调用参数与层级关系灵活集成提供Cycript注入、Tweak集成等多种使用方式日志文件默认保存在**/var/mobile/Documents/InspectiveC目录沙盒应用位于/var/mobile/Containers/Data/Application/App-Hex/Documents/InspectiveC**文件命名格式为**exe/pid_tid.log**方便开发者定位问题。 核心原理深入理解objc_msgSend Hook机制InspectiveC的核心能力源于对Objective-C运行时核心函数objc_msgSend的Hook。通过替换系统默认的消息发送函数实现对所有Objective-C方法调用的拦截与记录。在InspectiveCarm64.mm中可以看到arm64架构下的Hook实现// arm64 hooking magic static void hook() { MSHookFunction(objc_msgSend, (id (*)(id, SEL, ...))replacementObjc_msgSend, orig_objc_msgSend); }当应用调用任何Objective-C方法时都会经过InspectiveC的replacementObjc_msgSend函数在此完成日志记录后再调用原始的objc_msgSend函数实现无侵入式的调试追踪。 快速开始3种安装与使用方式1️⃣ Cycript注入方式推荐这是最灵活高效的使用方式无需重新编译应用即可动态注入确保已安装Cycript可通过Cydia获取终端执行以下命令注入目标进程以SpringBoard为例cycript -p SpringBoard在Cycript环境中加载InspectiveCintFuncnew Type(v).functionWith(int);objFuncnew Type(v).functionWith(id);classFuncnew Type(v).functionWith(Class);selFuncnew Type(v).functionWith(SEL);voidFuncnew Type(v).functionWith(new Type(v));objSelFuncnew Type(v).functionWith(id,SEL);classSelFuncnew Type(v).functionWith(Class,SEL);handledlopen(/usr/lib/libinspectivec.dylib,RTLD_NOW);setMaximumRelativeLoggingDepthintFunc(dlsym(handle,InspectiveC_setMaximumRelativeLoggingDepth));watchObjectobjFunc(dlsym(handle,InspectiveC_watchObject));unwatchObjectobjFunc(dlsym(handle,InspectiveC_unwatchObject));watchSelectorOnObjectobjSelFunc(dlsym(handle,InspectiveC_watchSelectorOnObject));unwatchSelectorOnObjectobjSelFunc(dlsym(handle,InspectiveC_unwatchSelectorOnObject));watchClassclassFunc(dlsym(handle,InspectiveC_watchInstancesOfClass));unwatchClassclassFunc(dlsym(handle,InspectiveC_unwatchInstancesOfClass));watchSelectorOnClassclassSelFunc(dlsym(handle,InspectiveC_watchSelectorOnInstancesOfClass));unwatchSelectorOnClassclassSelFunc(dlsym(handle,InspectiveC_unwatchSelectorOnInstancesOfClass));watchSelectorselFunc(dlsym(handle,InspectiveC_watchSelector));unwatchSelectorselFunc(dlsym(handle,InspectiveC_unwatchSelector));enableLoggingvoidFunc(dlsym(handle,InspectiveC_enableLogging));disableLoggingvoidFunc(dlsym(handle,InspectiveC_disableLogging));enableCompleteLoggingvoidFunc(dlsym(handle,InspectiveC_enableCompleteLogging));disableCompleteLoggingvoidFunc(dlsym(handle,InspectiveC_disableCompleteLogging))2️⃣ 使用InspectiveC Wrapper适合集成到Tweak开发中通过DEBUG宏控制在Tweak文件中包含Wrapper#if INSPECTIVEC_DEBUG #include InspCWrapper.m #endif调用API开始调试// 监控特定对象 watchObject(choose(SBUIController)[0]); // 监控特定选择器 watchSelector(selector(viewDidLoad)); // 监控特定类 watchClass([UIViewController class]);3️⃣ 直接链接库文件在Makefile中添加链接配置YOUR_TWEAK_NAME_LIBRARIES inspectivec然后包含头文件使用完整API#include InspectiveC.h // 设置最大日志深度 InspectiveC_setMaximumRelativeLoggingDepth(5); // 启用完整日志 InspectiveC_enableCompleteLogging(); 实战示例解读InspectiveC日志以下是典型的InspectiveC日志输出***-|SpringBoard0x15455d320 _run|*** |NSAutoreleasePool alloc| |NSAutoreleasePool allocWithZone:| NULL -|NSAutoreleasePool0x170442a00 init| -|SpringBoard0x15455d320 _accessibilityInit| -|SpringBoard0x15455d320 performSelector:withObject:afterDelay:| selector(_accessibilitySetUpQuickSpeak) nil 1.5 |NSArray arrayWithObject:| kCFRunLoopDefaultMode -|SpringBoard0x15455d320 performSelector:withObject:afterDelay:inModes:| selector(_accessibilitySetUpQuickSpeak) nil 1.5 __NSArrayI0x174233560日志格式说明***-|...|***表示方法调用的起始点|表示类方法调用-|表示实例方法调用0x...对象内存地址缩进层级表示方法调用嵌套关系⚙️ 高级配置优化你的调试体验编译配置对于iOS 10及以上系统需使用Fishhook替代MobileSubstratemake package USE_FISHHOOK1 FOR_RELEASE1 install日志深度控制通过设置最大相对日志深度避免日志泛滥// Cycript方式 setMaximumRelativeLoggingDepth(5) // 直接API调用 InspectiveC_setMaximumRelativeLoggingDepth(5);线程日志控制灵活启用/禁用特定线程的日志记录// 启用当前线程日志 InspectiveC_enableLogging(); // 禁用当前线程日志 InspectiveC_disableLogging(); // 启用完整日志模式 InspectiveC_enableCompleteLogging(); 常见问题与解决方案Q在iOS 11上无法Hook objc_msgSendA需要使用Fishhook编译选项make package USE_FISHHOOK1Q日志文件过大怎么办A通过setMaximumRelativeLoggingDepth限制递归深度或使用disableLogging临时关闭日志Q如何只监控特定方法A使用watchSelectorOnObject或watchSelectorOnClass精确监控对象或类的特定方法 获取与安装克隆仓库git clone https://gitcode.com/gh_mirrors/in/InspectiveC编译安装cd InspectiveC make package install或直接从stable_debs目录安装预编译deb包dpkg -i stable_debs/com.golddavid.inspectivec_1.2.0_iphoneos-arm.deb 总结InspectiveC通过创新的objc_msgSend Hook技术为iOS开发者提供了强大的运行时调试能力。无论是追踪复杂的方法调用流程还是分析第三方库的内部实现InspectiveC都能成为你调试工具箱中的必备神器。立即尝试InspectiveC开启你的iOS深度调试之旅吧如有任何问题欢迎查阅项目中的README.md获取更多帮助。【免费下载链接】InspectiveCobjc_msgSend hook for debugging/inspection purposes.项目地址: https://gitcode.com/gh_mirrors/in/InspectiveC创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考