这里我们准备HookViewController
的actionA
a. 将编译出的app文件放进TargetApp目录下
#import <UIKit/UIKit.h>
%hook ViewController
- (void)actionA:(id)sender {
NSLog(@"action-A-(Hooked!)");
}
%end
2021-05-16 23:10:24.635341+0800 AntiHook[3859:1526960] ⚠️检测到了Hook!
2021-05-16 23:10:24.635477+0800 AntiHook[3859:1526960] ⚠️检测到了Hook!
2021-05-16 23:10:24.635519+0800 AntiHook[3859:1526960] [AntiAntiDebug Init]
🎉!!!congratulations!!!🎉
👍----------------insert dylib success----------------👍
[MethodTrace]
📚--------------------OCMethodTrace(Usage)-------------------📚
https://github.com/omxcodec/OCMethodTrace/blob/master/README.md
📚--------------------OCMethodTrace(Usage)-------------------📚
[MethodTrace] logLevel: 0: logWhen: 0 traceFlag: 2 traceObject: 0(未指定类)
[MethodTrace] Method Trace is disabled
Download cycript(https://cydia.saurik.com/api/latest/3) then run: ./cycript -r 192.168.0.102:6666
2021-05-16 23:10:24.915464+0800 AntiHook[3859:1526960] result: <UIApplication: 0x1017100d0>
2021-05-16 23:10:24.996174+0800 AntiHook[3859:1526960] INFO: Reveal Server started (Protocol Version 43).
2021-05-16 23:10:33.341774+0800 AntiHook[3859:1526960] action-A-(Hooked!)
+ (void)load {
struct rebinding exchange;
exchange.name = "method_exchangeImplementations";
exchange.replacement = my_exchange;
exchange.replaced = (void *)&sysExchangePoint;
struct rebinding get;
get.name = "method_getImplementation";
get.replacement = my_get;
get.replaced = (void *)&sysExchangePoint;
struct rebinding set;
set.name = "method_setImplementation";
set.replacement = my_set;
set.replaced = (void *)&sysExchangePoint;
struct rebinding bds[] = { exchange, get, set };
rebind_symbols(bds, 3);
}
// 保存原函数的指针,这个可以暴露给自己使用
void (*sysExchangePoint)(Method _Nonnull methA, Method _Nonnull methB);
void my_exchange(Method _Nonnull methA, Method _Nonnull methB) {
NSLog(@"⚠️检测到了Hook!-method_exchangeImplementations");
}
void my_get(Method _Nonnull methA, Method _Nonnull methB) {
NSLog(@"⚠️检测到了Hook!-method_getImplementation");
}
void my_set(Method _Nonnull methA, Method _Nonnull methB) {
NSLog(@"⚠️检测到了Hook!-method_setImplementation");
}
2021-05-17 23:25:17.892661+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_getImplementation
2021-05-17 23:25:17.892798+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_exchangeImplementations
2021-05-17 23:25:17.892840+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_getImplementation
2021-05-17 23:25:17.892874+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_exchangeImplementations
2021-05-17 23:25:17.892912+0800 AntiHook[3999:1630972] [AntiAntiDebug Init]
🎉!!!congratulations!!!🎉
👍----------------insert dylib success----------------👍
2021-05-17 23:25:17.914757+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_getImplementation
2021-05-17 23:25:17.914913+0800 AntiHook[3999:1630972] ⚠️检测到了Hook!-method_setImplementation
[MethodTrace]
...
2021-05-17 23:25:26.987849+0800 AntiHook[3999:1630972] action-A
2021-05-17 23:25:27.952512+0800 AntiHook[3999:1630972] action-A
2021-05-17 23:25:28.803100+0800 AntiHook[3999:1630972] action-B
2021-05-17 23:25:29.170666+0800 AntiHook[3999:1630972] action-B