基于mach-o解析技术的包大小占比分析、Objective-C & Swift无用代码(冗余类)检测、无符号表时的日志符号化 (Based on mach-o technology, unused code (unused class) detection tool, crash log symbolization tool, and app size analysis tool.)
WBBlades is a tool set based on Mach-O
file parsing, including one-click detection for app (supports OC
and Swift
), package size analysis (supports a single static library/dynamic library), Point-to-point crash analysis (based on system logs, supports Huawei and Bugly platform crash stack analysis, supports signed and unsigned states), Class automatic extraction and Hook capability based on Mach-O file. It mainly uses __Text assembly code analysis, architecture extraction, DYSM file stripping, symbol table stripping, crash file (ips) analysis technology.Support big method/small method parsing and iOS 15 above about dyld_chained_Fixups processing. In order to facilitate users in quickly understanding the WBBlades project, we provide an intelligent Readme feature based on GPT.
Tool Name | Function Overview | Related Technologies |
---|---|---|
Intelligent Readme | Interactive Q&A format facilitates a quick understanding of the WBBlades project and related technologies. | GPT chat |
One-Click Detection for App | Swift & OC useless class detection, useless resource detection, and package downsizing optimization suggestions. | Disassembly, __Text instruction extraction, Mach-O parsing, symbol table and Swift class structure in Mach-O |
Package Size Analysis | Detecting the actual size occupied by static & dynamic libraries in .ipa file. | Architecture stripping, static library structure analysis |
Crash Analysis | Use .app or dYSM to analyze system crash logs, and support crash stack analysis on Huawei and Bugly platforms | DYSM file parsing, lightweight symbol table extraction, ips file parsing, with/without symbol table crash parsing |
Mach-O Class Hook | Automatically extract classes from any Mach-O file, and then hook them. | dyld_ chained_ Fixups, binding, rebase, and big/small method parsing |
The new version implements a comprehensive visual implementation of the toolset based on the original command-line-based operation of the above tools, and is designed for R&D efficiency improvement. In addition, in the analysis of difficult crashes, for some crashes that are not easy to reproduce and cannot be collected by general tools (the app process is directly killed by the operating system), a point-to-point crash analysis is provided.
$ git clone https://github.com/wuba/WBBlades.git
$ cd WBBlades
$ pod install
Target selects “WBBladesCrashApp”.
The WBBlades visualization tool is shown below. Click the button on the left function area, select a tool such as Useless Classes Detection,Application Size Analysis,etc., and operate according to the prompts in the tool, and the result will be output to the text box;
Detailed introduction to visualization tool: Detailed introduction to visualization tool
Target selects “WBBlades”,Compile and build to generate command line tools
Copy the generated product “blades” to /usr/local/bin,as follows:
sudo cp ${Your_BUILD_DIR}/blades /usr/local/bin
One-click detection
$ blades -diagnose xxx.app
One-click detection of useless classes, useless resources, and duplicate resources, and so on.
Unused Code Detection ObjC & Swift
$ blades -unused xxx.app -from xxx.a xxx.a ....
-from indicating that only the unused code in the following static libraries is analyzed. Without this parameter, the default is all classes in the APP.
App Size Analysis (Directly measure the size of .a or .framework after linking)
$ blades -size xxx.a xxx.framework ....
Supporting input a folder path, all static libraries under the folder will be analyzed.
Log Recovery without dSYM File (In the case of missing dSYM file, try ObjC
crash stack symbolization, Swift
is not supported)
$ blades -symbol xxx.app -logPath xxx.ips
Description | Support | Code Example |
---|---|---|
ObjC classes’s static call | ✅ | [MyClass new] |
ObjC classes’s dynamic call | ✅ | NSClassFromString(@"MyClass") |
ObjC dynamic call througn string concatenation | ❌ | NSClassFromString(@"My" + @"Class") |
ObjC load method | ✅ | +load{...} |
ObjC & Swift being inherited | ✅ | SomClass : MyClass |
ObjC & Swift being properties | ✅ | @property (strong,atomic) MyClass *obj; |
Swift class direct call | ✅ | MyClass.init() |
Swift call using runtime | ✅ | objc_getClass("Demo.MyClass") |
Swift generic parameters | ✅ | SomeClass<MyClass>.init() |
Swfit class dynamic call in ObjC | ✅ | NSClassFromString("Demo.MyClass") |
Swift type declaration in the container | ❌ | var array:[MyClass] |
Swift multiple nesting | ✅ | class SomeClass {class MyClass {...} ...} |
Supports quick detection of the linked size of a static library. No need to compile and link. For example: If you want to know how much app size will increase when an SDK is imported or updated, you can use blades -size
to estimate the size, without the need to connect the SDK to compile and link successfully to calculate.
In the case of losing the dSYM file, try to restore the log via blades -symbol
. **For example, in an app packaging, the dSYM file is cleared after a period of time, but the app file is retained. In this case, you can consider using blades for symbolization. **Before using the tool, pay attention to a few points:
If your app is a debug package or a package that does not strip the symbol table, you can use dsymutil app -o xx.dSYM
to extract the symbol table. Then use the symbol table to symbolize the log.
This tool only supports ObjC, and its principle is to determine the function of the crash by analyzing the address of the ObjC method in Mach-O. Therefore, it is not suitable for Swfit, C, and C++. In addition, tools are not omnipotent, and are only used as emergency supplementary technical means. In daily situations, it is recommended to use symbol tables for log symbolization.
We sincerely hope that developers can provide valuable comments and suggestions, and developers can provide feedback on suggestions and problems by submitting PR or Issue.
If you are interested in WBBlades, you can join the WBBlades development group and discuss technical issues together. Please add the wechat account “zqlong320” or scan the QR code below as your friend and then we will invite you to join the group.
GitHub: https://github.com/aquynh/capstone
GitHub: https://github.com/Sunnyyoung/SYFlatButton
GitHub: https://github.com/nygard/class-dump
GitHub: https://github.com/alexrozanski/PXListView
GitHub: https://github.com/steventroughtonsmith/cartool
DWARF: https://www.prevanders.net/dwarf.html#releases
WBBlades是基于Mach-O
文件解析的工具集,包括App一键体检(支持OC
和Swift
的无用类检测)、包大小分析(支持单个静态库/动态库的包大小分析)、点对点崩溃解析(基于系统日志,支持华为和Bugly平台崩溃堆栈解析,支持有符号和无符号状态)、基于Mach-O的Class自动提取和Hook能力。主要利用了__TEXT汇编代码分析、架构提取、符号表剥离、dYSM文件提取、崩溃文件(.ips)解析等技术手段实现,支持big method /small method 解析 以及 iOS 15以上关于dyld_chained_fixups的处理。并且为了便于用户更快了解WBBlades项目,我们提供了基于GPT的智能Readme功能。
工具名称 | 功能概述 | 相关技术 |
---|---|---|
智能Readme | 问答式互动,便于快速了解WBBlades项目以及相关技术 | GPT聊天 |
App一键体检 | Swift/OC无用类检测、无用资源检测、包瘦身优化建议 | 反汇编、__Text指令提取、Mach-O解析、符号表/Swift类在Mach-O中的结构 |
包大小分析 | 检测静态库/动态库在.ipa中占用的实际大小 | 架构剥离、静态库结构分析 |
崩溃解析 | 利用.app或者dYSM对系统崩溃日志解析,支持华为和Bugly平台的崩溃堆栈解析 | dYSM文件解析、轻量符号表提取、ips文件解析、有/无符号表崩溃解析 |
Mach-O类Hook | 自动提取任意Mach-O中的Class并Hook | dyld_chained_fixups 、binding、rebase、big/small method解析 |
新版本在原来基于命令行运行上述工具的基础上,对工具集进行了全面的可视化实现,开箱即用,专为研发提效而设计。另外,在疑难崩溃解析上,针对一些不易复现、且通用工具无法收集的崩溃(被操作系统直接杀死App进程场景),提供了基于系统日志的点对点崩溃解析功能。
$ git clone https://github.com/wuba/WBBlades.git
$ cd WBBlades
$ pod install
target选择:WBBladesCrashApp
WBBlades可视化工具如下图所示。点击左侧功能区按钮,点击进入无用类检测、包大小检测等工具,根据工具内的提示进行操作即可,具体的数据会输出到文本框中;
可视化工具详细介绍: 可视化工具详细介绍
target选择:WBBlades,编译运行,生成命令行工具
将生成的产物blades 拷贝至 /usr/local/bin 下,具体操作如:
sudo cp ${Your_BUILD_DIR}/blades /usr/local/bin
一键诊断
$ blades -diagnose xxx.app
一键检测无用类、无用资源、重复资源等
无用代码检测 OC
& Swift
$ blades -unused xxx.app -from xxx.a xxx.a ....
-from 标识只分析以下静态库中的无用代码,不加此参数默认为APP中全部类
包大小分析 (直接测算.a |.framework链接后的大小)
$ blades -size xxx.a xxx.framework ....
支持输入一个文件夹路径,输入后该文件下所有的静态库都会被分析
无符号表日志符号化(在丢失符号表的情况下,尝试OC
崩溃堆栈符号化,不支持Swift
)
$ blades -symbol xxx.app -logPath xxx.ips
说明 | 是否支持 | 代码示例 |
---|---|---|
OC 的类的静态调用 | ✅ | [MyClass new] |
OC 的动态调用 | ✅ | NSClassFromString(@"MyClass") |
OC 字符串拼接动态调用 | ❌ | NSClassFromString(@"My" + @"Class") |
OC load方法使用 | ✅ | +load{...} |
OC & Swift 被继承 | ✅ | SomClass : MyClass |
OC & Swift 作为属性 | ✅ | @property (strong,atomic) MyClass *obj; |
Swift 类直接调用 | ✅ | MyClass.init() |
Swift 通过runtime调用 | ✅ | objc_getClass("Demo.MyClass") |
Swift 泛型参数 | ✅ | SomeClass<MyClass>.init() |
Swfit 类在OC中动态调用 | ✅ | NSClassFromString("Demo.MyClass") |
Swift 容器中作为类型声明 | ❌ | var array:[MyClass] |
Swift 多重嵌套 | ✅ | class SomeClass {class MyClass {...} ...} |
支持快速检测一个静态库的链接后大小。无需编译链接。举例说明:如果你想知道一个接入或更新一个SDK对会增加多少包大小,可以用blades -size
来预估下大小,而无需将SDK接入编译链接成功后进行测算。
在丢失dSYM文件的情况下,尝试通过blades -symbol
恢复日志。例如某次打包,在一段时间后符号表被清除,但是保留了app文件,这种情况下可以考虑使用WBBlades进行符号化。在工具使用前应先注意几点:
dsymutil app -o xx.dSYM
来提取符号表。然后用符号表进行日志符号化。我们诚挚地希望开发者提出宝贵的意见和建议,开发者可以通过提交PR或者Issue来反馈建议和问题。
欢迎对WBBlades感兴趣的小伙伴加入WBBlades开发交流群,一起探讨技术问题,请先添加微信号"zqlong320"或者扫描下面的二维码为好友,备注"WBBlades",我们会邀请您进群。
GitHub地址:https://github.com/aquynh/capstone
GitHub地址:https://github.com/Sunnyyoung/SYFlatButton
GitHub地址:https://github.com/nygard/class-dump
GitHub地址:https://github.com/alexrozanski/PXListView
GitHub地址:https://github.com/steventroughtonsmith/cartool