日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Logos讲解--逆向开发

發布時間:2023/12/31 综合教程 35 生活家
生活随笔 收集整理的這篇文章主要介紹了 Logos讲解--逆向开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

Logos是CydiaSubstruct框架中提供的一組宏定義。利于開發者使用宏進行Hook操作,其語法簡單,功能是非常強大且穩定。

詳細內容logos語法為http://iphonedevwiki.net/index.php/Logos

語法

1. 全局

Logos語法分為三大類:

Block level:這類型的指令會開辟一個代碼塊,以%end結束。%group、%hook、%subclass、%end
Top level:TopLevel指令不放在BlockLevel中。%config、%hookf、%ctor、%dtor
Function level:這塊指令放在方法中。%init、%class、%c、%orig、%log

2. 詳解

2.1 %hook

指定需要hook住的class,必須要以%end結尾

%hook SpringBoard
- (void)_menuButtonDown:(id)down {
    NSLog(@"你好");
    %orig; // call the original __menuButtonDown
}
%end

意思是勾住(Hook)SpringBoard類中的_menuButtonDown,先打印下,再執行函數原本的操作。

2.2 %log

指令再%hook內部去使用,將函數的類名和參數等信息寫入syslog。

%hoot SpringBoard
- (void)_menubuttonDown:(id)down
{
    %log((NSString *)@"iOSRE",(NSString *)@"Debug");
    %orig;//call the original _menuButtonDown;
}
%end

2.3 %orig

指令在%hook內部中使用,執行被hook住的函數原始代碼

%hook SpringBoard
- (void)_menuButtonDown:(id)down
{
    NSLog(@"你好");
    %orig; // 
}
%end

如果去掉了%orig,原始函數就不會被執行

hook SpringBoard
- (void)_menuButtonDown:(id)down
{
    NSLog(@"你好");
}
%end

還可以利用%orig更改原始行數的參數。

%hook SBLockScreenDateViewController
- (void)setCustomSubtitleText:(id)arg1 withColor:(id)arg2
{
    %orig(@"Red",arg2);
}
%end

2.4 %group

指令用于%hook分組,便于代碼管理以及按條件初始化分組,也是必須要以%end結尾;%group中可以包含很多個%hook,所有不屬于某一個自定義group中的%hook也將會被歸類到%group_ungroupes中。

%group iOS11Hook
%hook iOS12Class 
- (id)iOS11Method {
     id result = %orig; 
     NSLog(@"This class & method only exist in iOS 11."); 
     return result;
 } %end 
%end // iOS11Hook

%group iOS12Hook 
%hook iOS12Class 
- (id)iOS8Method {
   id result = %orig; 
   NSLog(@"This class & method only exist in iOS 12."); return result;
 }
%end
%end // iOS12Hook

2.5 %init

指令用于初始化某個%group,必須在%hook或者%ctor內調用;如果需要帶參數,則初始化指定的group,如果不帶參數時,就會初始化_ungrouped。只有調用了%init,其對應的%group才能夠起到作用。

#ifndef kCFCoreFoundationVersionNumber_iOS_11_0 
#define kCFCoreFoundationVersionNumber_iOS_11_0 1140.10 #endif
%hook SpringBoard 
- (void)applicationDidFinishLaunching:(id)application {
    %orig; 
    %init; // Equals to %init(_ungrouped)
    if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_12_0 && kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iOS_11_0)
      %init(iOS12Hook);
    if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_11_0)
      %init(iOS11Hook);
}
%end

2.6 %ctor

該指令完成初始化工作,如果不顯示其定義,theos自動會生成%ctor,也會調用%init

%hook SpringBoard 
- (void)reboot {
    NSLog(@"If rebooting doesn't work then I'm screwed.");
    %orig;
}
%end

成功生效,Theos隱式調用了內容如下

%ctor
{
    %init(_ungrouped);
}

%hook SpringBoard
- (void)reboot{
     NSLog(@"If rebooting doesn't work then I'm screwed.");
     %orig;
}
%end

%ctor
{
    // Need to call %init explicitly!
}

其中的%hook無法生效,因顯示定義了%ctor,卻沒有定義%ctor,不需要以%end結尾。一般用于初始化%group。

2.7 %new

在%hook內部中使用,給現有class增新函數,功能與class_addMethod意義相同。

%hook SpringBoard 
%new 
- (void)namespaceNewMethod {
     NSLog(@"We've added a new method to SpringBoard."); 
}
%end

%c

指令和objc_getClass或者NSClassFromString,動態獲取一個類的定義。用于%hook和%ctor中使用。

總結如下

Demo

3.1 新建Logos工程

3.2 用class-dump來導出頭文件

$class-dump -H 001-LogosDemo -o /Users/yaoqi/Desktop/LogosHeaders

3.3 新建MonkeyDev工程,將LogosDemo重簽名

此時MonkeyDev工程將libsubstrate.dylib和RevealServer.framework注入了工程,里面有libsubstrate.dylib就可以利用logos語法了。

3.4 MonkeyDev中logos文件夾中的.xm寫入Logos語法

_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(@"這是一個類方法!!!");
}

%end

3.5 運行,MonkeyDev工程能Hook到LogosDemo的loginBtnClicked

FLEX庫

4.1 在MonkeyDev的Dylib動態庫注入Flex庫

在MonkeyDev根目錄添加Podfile文件,Target為Monkey動態庫的Target

platform :ios, '9.0'

target '002-loginHookDemoDylib' do
  use_frameworks!
  pod 'FLEX'
end

4.2 界面展示

FlEX可以查看App的文件、數據庫、界面層級以及沙盒

實例練習

要求:微信首頁加個“+”按鈕,左邊按鈕和右邊的效果一樣。

5.1 新建MonkeyDev工程,重簽名韋小寶,將FLEX加入到動態庫

5.2 Xcode界面調試,Class-dump,找到界面NewMainFrameViewController控制器

5.3 Xcode界面調試,找到右邊按鈕的showRightTopMenuBtn方法

Target <NewMainFrameRightTopMenuBtn: 0x104dd99d0>
Action showRightTopMenuBtn

5.4 內存中查找導航欄右邊按鈕的視圖

5.5 代碼實現需求

#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(@"


-------------navigationItem-----");
    //方法交換! 調用自己!
    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(@"


-----viewDidLoad-----------");
}

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

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

%end

5.6 實現結果

總結

上面就是Logos語法及講解,如果對大家有所幫助,希望大家關注,也可以點個喜歡,下一篇我們將講解越獄的相關知識,請大家準備好越獄手機和PP助手!!!

總結

以上是生活随笔為你收集整理的Logos讲解--逆向开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。