iOS逆向之旅(進階篇) — HOOK(Logos)

Logos官方文檔php

簡介

Logos本是Theos的一個組件,Monkey將裏面libsubstrate.dylib移植出來,因此在Monkey工程下也能夠使用Logos進行Hook代碼bash

經常使用到的一些語法

  • HOOK 某個類裏面的某個方法
%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

  • 首先新建一個Monkey工程

image.png

  • 把App放到TargetApp目錄下

image.png

  • 打開_6_HOOK_LogosDylib.xm文件,在文件上面進行開發

先刪除掉運行的內容,開始寫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

1371540288125_.pic.jpg
相關文章
相關標籤/搜索