Logos官方文檔php
Logos本是Theos的一個組件,Monkey將裏面libsubstrate.dylib移植出來,因此在Monkey工程下也能夠使用Logos進行Hook代碼bash
%hook 類名
- (void)方法名:(id)arg1 ....
{
}
%end
複製代碼
%hook class_name
// 添加一個響應事件
%new
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
// 添加一個類方法
%new
+(void) new_func_name {
NSLog(@"這是一個類方法!");
}
%end
複製代碼
%ctor 構造函數
%dtor 析構函數
複製代碼
%group group1
%hook class_name
- (void)func_name:(id)arg1 ....
{
//修改替換成的內容
}
%end
%end
%group group2
%hook class_name
- (void)func_name:(id)arg1 ....
{
//修改替換成的內容
}
%end
%end
// 定義了組就必須對其初始化
%ctor{
NSString * version = [UIDevice currentDevice].systemVersion;
if(version.doubleValue >= 10){// 當iOS版本大於10則使用組2的Logos代碼,不然使用組1的
%init(group2)
}else{
%init(group1)
}
}
複製代碼
%log 打印原始方法的全部參數信息
%orig 執行原始的方法
[%c(ViewController) click]; %c獲取類
複製代碼
本案例在Monkey工廠下,利用Logos語法實現與 iOS逆向之旅(進階篇) — HOOK(Method Swizzling)中案例如出一轍的功能。iphone
先刪除掉運行的內容,開始寫Logos語法進行HOOK函數
%hook WCAccountLoginControlLogic
- (void) onFirstViewLogin {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"你想登陸??" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertVC addAction:[UIAlertAction actionWithTitle:@"肯定" style:UIAlertActionStyleCancel handler:nil]];
[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:alertVC animated:true completion:nil];
}
%end
複製代碼
經過這段簡單的代碼,就完成咱們以前一系列複雜的HOOK,Logos是否是很強大呢? 來看看效果ui