iOS逆向之Logos文法

來源:互聯網
上載者:User

標籤:分組   mst   set   代碼   逆向   執行   iphone   toms   dylib   

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

  • 建立Monkey工程時,MonkeyDev已經將libsubstrate.dylib庫和RevealServer.framework庫注入進去了,有了libsubstrate.dylib庫就能寫Logos文法

  • Logos文法:

Logos文法 功能解釋 案例
%hook 需要hook哪個類 %hook Classname
%end 代碼塊結束標記
%group 分組 %group Groupname
%new 添加新方法 %new(signature)
%ctor 建構函式 %ctor { … }
%dtor 解構函式 %dtor { … }
%log 輸出列印 %log; %log([(
%orig 保持原有方法 %orig;%orig(arg1, …);
%c %c([+/-]Class);
1.%hook %end

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

// hook SpringBoard類裡面的_menuButtonDown函數,先列印一句話,再之子那個函數原始的操作%hook SpringBorad- (void)_menuButtonDown:(id)down{    NSLog(@"111111");   %orig; // 調用原始的_menuButtonDown函數}%end
2.%group

該指令用於將%hook分組,便於代碼管理及按條件初始化分組,必須以%end結尾。
一個%group可以包含多個%hook,所有不屬於某個自訂group的%hook會被隱式歸類到%group_ungrouped中。

/*在%group iOS7Hook中鉤住iOS7Class的iOS7Method,在%group iOS8Class中鉤住iOS8Method函數,然後在%group _ungroup中鉤住SpringBoard類的powerDown函數.*/%group iOS7Hook%hook iOS7Class- (id)ios7Method{    id result = %orig;    NSLog(@"這個方法只有iOS7適用");    return result;}%end%end // iOS7Method%group iOS8Hook%hook iOS8Class- (id)ios8Method{    id result = %orig;    NSLog(@"這個方法只有iOS7適用");    return result;}%end%end // iOS8Method%hook SpringBoard- (void)powerDown{     %orig;}%end
3.%new

在%hook內部使用,給一個現有class添加新函數,功能與class_addMethod相同.
註:
Objective-C的category與class_addMethod的區別:
前者是靜態而後者是動態。使用%new添加,而不需要向.h檔案中添加函式宣告,如果使用category,可能與遇到這樣那樣的錯誤.

%hook SpringBoard%new- (void)addNewMethod{    NSLog(@"動態添加一個方法到SpringBoard");}%end
4.%ctor

tweak的constructor,完成初始化工作;如果不顯示定義,Theos會自動產生一個%ctor,並在其中調用%init(_ungrouped)。%ctor一般可以用來初始化%group,以及進行MSHookFunction等操作,如下:

#ifndef KCFCoreFoundationVersionNumber_iOS_8_0#define KCFCoreFoundationVersionNumber_iOS_8_0      1140.10#endif%ctor{    %init;    if (KCFCoreFoundationVersionNumber >= KCFCoreFoundationVersionNumber_iOS_7_0 && KCFCoreFoundationVersionNumber > KCFCoreFoundationVersionNumber_iOS_8_0)    %init(iOS7Hook); if (KCFCoreFoundationVersionNumber >= KCFCoreFoundationVersionNumber_iOS_8_0)    %init(iOS8Hook);MSHookFunction((void *)&AudioServicesPlaySystemSound,(void *)&replaced_AudioServerPlaySystemSound,(void **)&orginal_AudioServicesPlaySystemSound);}
5.%dtor

Generate an anonymous deconstructor (of default priority).

%dtor { … }
6.%log

該指令在%hook內部使用,將函數的類名、參數等資訊寫入syslog,可以%log([(),…..])的格式追加其他列印資訊。

%hook SpringBorad- (void)_menuButtonDown:(id)down{    %log((NSString *)@"iosre",(NSString *)@"Debug");    %orig; // 調用原始的_menuButtonDown方法}%end
6.%orig

該指令在%hook內部使用,執行被hook的函數的原始代碼;也可以用%orig更改原始函數的參數。

%hook SpringBorad- (void)setCustomSubtitleText:(id)arg1 withColor:   (id)arg2{    %orig(@"change arg2",arg2);// 將arg2的參數修 改為"change arg2"}%end
7.%init

該指令用於初始化某個%group,必須在%hook或%ctor內調用;如果帶參數,則初始化指定的group,如果不帶參數,則初始化_ungrouped.
註: 切記,只有調用了%init,對應的%group才能起作用!

8.%c

該指令的作用等同於objc_getClass或NSClassFromString,即動態擷取一個類的定義,在%hook或%ctor內使用 。

iOS逆向之Logos文法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.