基于汇编实现 hook objc_msgSend,统计方法耗时的方案

文章目录


简介

首先,iOS 中进行 hook 的方案有多种,这里使用的是 Facebook 的 fishhook 库:Github:fishhook

hook objc_msgsend ,货拉拉技术团队已有完善的方案:基于汇编实现objc_msgSend hook方法耗时的方案

另外,它们还开源了基于fishhook、汇编 hook objc_msgsend 并支持方法耗时可视化的项目:hll-wp-guldan-ios

接入

首先在 Podfile 中添加:

cpp 复制代码
pod 'Guldan', :git => "https://github.com/HuolalaTech/hll-wp-guldan-ios.git"

然后设置要监控的代码片段:

objectivec 复制代码
[GDNOCMethodTimeProfiler start];
// 下载图片
[self downloadImages];
[GDNOCMethodTimeProfiler stop];
[GDNOCMethodTimeProfiler handleRecordsWithComplete:^(NSArray<NSString *> * _Nonnull filePaths) {
       // file path
       for (NSString *filePath in filePaths) {
             NSLog(@"File path: %@", filePath);
         }
   }];

从控制台拿到 path:

最后将 path 的文件拖入 chrome://tracing/ :

经测试,模拟器(arm64)和真机均支持,不支持模拟器(x86_64)。

相关推荐
white-persist8 小时前
【攻防世界】reverse | re1-100 详细题解 WP
c语言·开发语言·网络·汇编·python·算法·网络安全
從南走到北14 小时前
JAVA海外短剧国际版源码支持H5+Android+IOS
android·java·ios
疯笔码良14 小时前
iOS 国际化与本地化完整指南
ios·swift
库奇噜啦呼15 小时前
【iOS】GCD学习
学习·ios·cocoa
Kathleen10016 小时前
iOS--TableView的复用机制以及性能优化(处理网络数据)
ios·性能优化·网络请求·gcd·uitableview
tobebetter952717 小时前
How to use homebrew on mac
macos·homebrew
sulikey18 小时前
如何使用 Visual Studio 代替 OllyDbg 完成汇编语言实验
汇编·ide·debug·visual studio·ollydbg
信奥胡老师1 天前
苹果电脑(mac系统)安装vscode与配置c++环境,并可以使用万能头文件全流程
c++·ide·vscode·macos·编辑器