iOS逆向之Logos語(yǔ)法(十二)

Logos語(yǔ)法

http://iphonedevwiki.net/index.php/Logos

  • 1、新建Logos測(cè)試工程
001-LogosDemo工程.png
001-LogosDemo Screen Shot.png
  • 2、用class-dump導(dǎo)出頭文件
$class-dump -H 001-LogosDemo -o /Users/yaoqi/Desktop/LogosHeaders
class-dump 001-LogosDemo工程.png
  • 3、新建Monkey工程,將Logos測(cè)試工程重簽名
Monkey工程,重簽名001-LogosDemo工程.png

此時(shí)Monkey工程已經(jīng)將libsubstrate.dylib庫(kù)和RevealServer.framework庫(kù)注入進(jìn)去了,有了libsubstrate.dylib庫(kù)就能寫(xiě)Logos語(yǔ)法了。

002-loginHookDemo工程Framework文件夾.png
  • 4、在Monkey中的Logos文件夾的.xm文件寫(xiě)Logos語(yǔ)法
屏幕快照 2018-05-15 下午9.37.41.png
Logos語(yǔ)法 功能解釋 事例
%hook 需要hook哪個(gè)類(lèi) %hook Classname
%end 代碼塊結(jié)束標(biāo)記
%group 分組 %group Groupname
%new 添加新方法 %new(signature)
%ctor 構(gòu)造函數(shù) %ctor { … }
%dtor 析構(gòu)函數(shù) %dtor { … }
%log 輸出打印 %log; %log([(<type>)<expr>, …]);
%orig 保持原有方法 %orig;%orig(arg1, …);

_02_loginHookDemoDylib.xm

// See http://iphonedevwiki.net/index.php/Logos

#import <UIKit/UIKit.h>

@interface ViewController: UIViewController

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);
+ (void)CL_classMethod;

@end

%hook ViewController

- (void)loginBtnClicked:(id)arg1 {
    %log;
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Hook成功了!!!" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"確定" style:(UIAlertActionStyleCancel) handler:nil]];
    [self presentViewController:alertVC animated:YES completion:nil];
}

%new
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
    [self.class CL_classMethod];
}

%new
+ (void)CL_classMethod {
    NSLog(@"這是一個(gè)類(lèi)方法!!!");
}

%end

這里在ViewController中定義了一個(gè)方法presentViewController:animated:completion:,只是為了能編譯通過(guò),騙過(guò)Xcode編譯器。

5、運(yùn)行成功后,Monkey工程就能Hook到001-LogosDemo工程里面的loginBtnClicked:

Logos Hook Screen Shot.png

Monkey工程注入FLEX庫(kù)

https://github.com/Flipboard/FLEX

  • 1、在Monkey的Dylib動(dòng)態(tài)庫(kù)中注入FLEX庫(kù)

在Monkey工程的根目錄添加Podfile文件,Target為Monkey工程動(dòng)態(tài)庫(kù)的Target

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target '002-loginHookDemoDylib' do
  use_frameworks!
  pod 'FLEX'
end
  • 2、界面展示

FLEX能查看App的文件、數(shù)據(jù)庫(kù)、沙盒、界面層級(jí)。。。

Screen Shot 2018-05-15 at 下午10.53.49.png
Screen Shot 2018-05-15 at 下午10.56.05.png

Logos練習(xí)

需求:在微信首頁(yè)導(dǎo)航欄左邊添加一個(gè)?按鈕,點(diǎn)擊事件和右邊按鈕的點(diǎn)擊效果一樣。

  • 1、新建Monkey工程,重簽名微信包,并將FLEX注入進(jìn)動(dòng)態(tài)庫(kù)中

  • 2、Xcode界面調(diào)試,class-dump微信包,找到首頁(yè)界面NewMainFrameViewController控制器

屏幕快照 2018-05-15 下午11.22.50.png

3、Xcode界面調(diào)試,找到微信導(dǎo)航欄右邊按鈕的點(diǎn)擊的showRightTopMenuBtn方法

Target <NewMainFrameRightTopMenuBtn: 0x104dd99d0>
Action showRightTopMenuBtn
屏幕快照 2018-05-15 下午11.34.13.png
屏幕快照 2018-05-15 下午11.36.50.png
  • 4、在內(nèi)存中查找導(dǎo)航欄右邊按鈕視圖層次
屏幕快照 2018-05-15 下午11.53.03.png

5、寫(xiě)代碼實(shí)現(xiàn)需求

#import <UIKit/UIKit.h>

@interface NewMainFrameViewController :UIViewController
@end

@interface NewMainFrameRightTopMenuBtn: UIView
- (void)showRightTopMenuBtn;
@end

@interface MMBarButtonItem: UIBarButtonItem
@property(nonatomic,weak)NewMainFrameRightTopMenuBtn *view;
@end

%hook NewMainFrameViewController

-(UINavigationItem *)navigationItem{
    //    NSLog(@"\n\n\n-------------navigationItem-----");
    //方法交換! 調(diào)用自己!
    return %orig;
}

- (void)viewDidAppear:(_Bool)arg1{
    %orig;
    UIButton * leftBtn = [UIButton buttonWithType:(UIButtonTypeContactAdd)];
    [leftBtn addTarget:self action:@selector(CL_leftClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navigationItem setLeftBarButtonItem: [[UIBarButtonItem alloc] initWithCustomView:leftBtn]];
}

- (void)viewDidLoad{
    %orig;
    //    NSLog(@"\n\n\n-----viewDidLoad-----------");
}

%new
-(void)CL_leftClick
{
    /**
     從內(nèi)存中能查到調(diào)用該方法:[self.navigationItem.rightBarButtonItem.view showRightTopMenuBtn]
     self:代表NewMainFrameViewController控制器

     */
    MMBarButtonItem *btn = self.navigationItem.rightBarButtonItem;
    [btn.view showRightTopMenuBtn];
}

%end
Screen Shot 2018-05-16 at 上午12.00.58.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 電梯啟動(dòng)了,樓房和地面不可抗拒的向下退去,陽(yáng)光從側(cè)面的空洞照進(jìn)來(lái),我緩緩旋動(dòng)可樂(lè)瓶蓋,氣泡在黑玫瑰色的液體中產(chǎn)生于...
    楊彤宇閱讀 459評(píng)論 1 2
  • #51 雖然我是個(gè)手廢帝,但是手殘志堅(jiān),還是懷著一顆變成藝術(shù)家的夢(mèng)想的。我近期列一張我想去的美術(shù)館的清單,然后一天...
    花花騷年閱讀 307評(píng)論 1 1
  • 小北和小南都是C大的學(xué)生。C大是一個(gè)二流學(xué)院,高考成績(jī)不太理想的學(xué)生,才會(huì)來(lái)到C大。小北和小南初來(lái)大學(xué),也有點(diǎn)沮喪...
    聶明明閱讀 269評(píng)論 0 1