下载最新版的Dobby
macOS Ventura 13.0.1
Xcode 14.1
git clone https://github.com/jmpews/Dobby.git --depth=1
直接执行脚本编译
python3 scripts/platform_builder.py --platform=iphoneos --arch=all
查看生成的 DobbyX.framework 里面没有可执行文件和头文件
第二种方式编译framework
cd Dobby && mkdir build_for_ios_arm64 && cd build_for_ios_arm64
cmake .. -G Xcode \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DPLATFORM=OS64 -DARCHS="arm64" -DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DENABLE_BITCODE=0 -DENABLE_ARC=0 -DENABLE_VISIBILITY=1 -DDEPLOYMENT_TARGET=9.3 \
-DDynamicBinaryInstrument=ON -DNearBranch=ON -DPlugin.SymbolResolver=ON -DPlugin.Darwin.HideLibrary=ON -DPlugin.Darwin.ObjectiveC=ON
执行代码
#import <DobbyX/dobby.h>
@interface ViewController ()
@end
@implementation ViewController
int sum(int a, int b) {
return a + b;
}
static int (*sum_p)(int a, int b);
int mySum(int a, int b) {
NSLog(@"sum: %d 🍺", sum_p(a, b));
return a - b;
}
- (void)viewDidLoad {
[super viewDidLoad];
DobbyHook(sum, mySum, (void *)&sum_p);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"Sum: %d", sum(10, 20));
}
@end
报错