(Related article: https://everettjf.github.io/2017/10/12/appletrace-dancewith-monkeydev/ )
Background
Normally using Instruments (mainly Time Profiler) for iOS App performance analysis is sufficient, but Time Profiler merges all calling methods together, losing temporal representation. Until one day saw Android development colleagues using systrace for performance analysis, systrace generates an html file, displaying function (method) call time consumption in chronological order. Thought: if iOS had such a tool would be great. Learned this html file is generated by catapult.
One day saw iosre forum a post about hook objc_msgSend. Suddenly thought, can combine catapult to generate Objective C method performance analysis chart (let’s call it that for now). (Although there were always methods to hook objc_msgSend, but this time the ready-made delicacy finally couldn’t resist).
Said do it and started, paused a few days developing MachOExplorer. Recently been using very limited spare time to develop MachOExplorer at snail’s pace, but now seeing generating performance analysis chart is more important, recalling past hard overtime work, if could generate this performance analysis chart, wouldn’t have solved problems quickly then.
...
In book : Hacking iOS Applications
https://web.securityinnovation.com/hubfs/iOS%20Hacking%20Guide.pdf
Addition:
Since lldb supports python script, can make it more automatic through scripts.
Had this idea, but never invested time to write it.
Later, 0xbbc implemented this functionality. Link
...
This article almost copy part of the official article, but fix many bugs that may impede newbees on the way to develop a clang plugin.
Environment : macOS
Step 0 : Obtain Clang
mkdir ~/clang-llvm && cd ~/clang-llvm
git clone <http://llvm.org/git/llvm.git>
cd llvm/tools
git clone <http://llvm.org/git/clang.git>
cd clang/tools
git clone <http://llvm.org/git/clang-tools-extra.git> extra
...
The following three methods can make code execute before main function:
All +load methods
All C++ static initializers
All C/C++ attribute(constructor) functions
Problems with Code Executing Before main Function
Cannot Patch
Cannot audit time consumption
Calling UIKit related methods causes some classes to initialize early
Executes on main thread, completely blocking execution
...
First addition: static initializers in title should actually be called C++ static initializers and C/C++ __attribute__(constructor) functions.
Use MachOView to open a MachO file, in most cases will see this section __mod_init_func .
...
iOS has the following four methods to conveniently execute code in premain stage:
1. Objective C class's +load method
2. C++ static initializer
3. C/C++ __attribute__(constructor) functions
4. The above three methods in dynamic libraries
...