標籤:分組 mst set 代碼 逆向 執行 iphone toms dylib
Logos文法
http://iphonedevwiki.net/index.php/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文法