[iOS Reverse]logify日誌追蹤,鎖定注入口-控制台查看

來源:互聯網
上載者:User

標籤:search   origin   bool   b2c   contain   select   keyword   mac   cpp   

前言

logify是theos的一個組件,路徑是:

/opt/theos/bin/logify.pl

我們還是以紅包為例子,根據[iOS Hacking]運行時分析cycript得到的入口檔案:

BaseMsgContentViewController.h
ssh串連手機

在Mac上開啟終端,用ssh串連手機:

ssh [email protected]xx.xx.xx.xx

輸入密碼:

alpine

關於如何串連手機,請參考我之前的[iOS HACKING入門]注入。

擷取BaseMsgContentViewController.h``中發訊息方法的入參

在Mac上建立一個終端視窗,進入終端,按command+N,在新的終端視窗中,cd到案頭或者某個確定的檔案夾:

cd  ~/Desktop

建立一個Tweak.xm檔案,輸入命令:

touch Tweak.xm

logify

/opt/theos/bin/logify ~/Desktop/Hacking/WeChat/Headers/BaseMsgContentViewController.h >  ~/Desktop/Tweak.xm

前面路徑是你用class-dumpdump出的標頭檔中目標檔案的地址,關於class-dump有問題的話,可以參考我的部落格:
[iOS Hacking]用class-dump擷取標頭檔

開啟產生的剛剛建立的Tweak.xm檔案,可以看到剛剛的命令 hook到了這個類所有的方法,
並且在方法中注入了 log,列印了方法的入參和傳回值。下面是Tweak.xm的一部分代碼:

%hook BaseMsgContentViewController- (void)setM_badRoomLogicController:(BadRoomLogicController *)m_badRoomLogicController { %log; %orig; }- (BadRoomLogicController *)m_badRoomLogicController { %log; BadRoomLogicController * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setM_bIsInMainFrame:(_Bool )m_bIsInMainFrame { %log; %orig; }- (_Bool )m_bIsInMainFrame { %log; _Bool  r = %orig; HBLogDebug(@" = %d", r); return r; }- (void)setM_searchScene:(int )m_searchScene { %log; %orig; }- (int )m_searchScene { %log; int  r = %orig; HBLogDebug(@" = %d", r); return r; }- (void)setM_shareContacts:(NSMutableArray *)m_shareContacts { %log; %orig; }- (NSMutableArray *)m_shareContacts { %log; NSMutableArray * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setM_msgReceivingTipsView:(UIView *)m_msgReceivingTipsView { %log; %orig; }- (UIView *)m_msgReceivingTipsView { %log; UIView * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setGesture:(WXGesture *)gesture { %log; %orig; }- (WXGesture *)gesture { %log; WXGesture * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setM_LockerTimer:(MMTimer *)m_LockerTimer { %log; %orig; }- (MMTimer *)m_LockerTimer { %log; MMTimer * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setToolView:(MMInputToolView *)toolView { %log; %orig; }- (MMInputToolView *)toolView { %log; MMInputToolView * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setM_updateTimeLabelTimer:(MMTimer *)m_updateTimeLabelTimer { %log; %orig; }- (MMTimer *)m_updateTimeLabelTimer { %log; MMTimer * r = %orig; HBLogDebug(@" = %@", r); return r; }- (void)setM_backgroundThreadDelegate:(__weak id <BaseMsgContentInBackgroundThreadDelgate> )m_backgroundThreadDelegate { %log; %orig; }- (__weak id <BaseMsgContentInBackgroundThreadDelgate> )m_backgroundThreadDelegate { %log; __weak id <BaseMsgContentInBackgroundThreadDelgate>  r = %orig; HBLogDebug(@" = 0x%x", (unsigned int)r); return r; }- (void)setM_delegate:(__weak id <BaseMsgContentDelgate> )m_delegate { %log; %orig; }- (__weak id <BaseMsgContentDelgate> )m_delegate { %log; __weak id <BaseMsgContentDelgate>  r = %orig; HBLogDebug(@" = 0x%x", (unsigned int)r); return r; }

具體來分析一句:

- (_Bool )m_bIsInMainFrame { %log; _Bool r = %orig; HBLogDebug(@" = %d", r); return r; }

其中%log; _Bool r = %orig;表示列印函數的傳回值;
r=%orig; 表示r=執行原來的代碼得到的傳回值。

將hook到的 Tweak.xm打包成 .deb檔案安裝到手機

在Mac終端中建立一個deb項目,將hook到的這個Tweak.xm檔案,替換這個新deb項目中的Tweak.xm檔案。
然後用theos打包並安裝到手機中。
關於,如何用thoes打包並安裝到手機,請參考我的部落格:[iOS HACKING入門]注入

注意在打包的時候,可能會出現找不到某個類的提示,這個時候,只需要把這個類從dump出來目標題檔案中刪除即可,然後重建Tweak.xm檔案:

~/Desktop/Hacking/WeChat/Headers/BaseMsgContentViewController.h > ~/Desktop/Tweak.x
查看手機日誌

安裝上一步的deb項目後,手機連Mac,開啟Xcode,然後查看裝置控制台:

Xcode->Window->Devices
  

進入裝置介面,選擇剛剛安裝了上一步deb包的裝置:

  

點擊左下個的那個箭頭,開啟日誌控制台:

  

開啟控制台:

  

開啟,進入群聊介面,用另一個手機在這個群裡發送一條訊息,再次向群裡發訊息觀察手機控制台輸出。
可以看到列印了很多東西,這就是剛剛hook出的標頭檔,在裡面注入了NSLog,列印了方法的入參以及傳回值:

  分析日誌:

將上一步控制台的日誌,全選,粘貼在文字編輯器中,便於分析。
分析發現,有一個方法接收訊息的方法被調用了:

addMessageNode: layout: addMoreMsg:

並且就連方法的入參也一起被列印出來了:

  

分析一下參數:
addMessageNode對應的參數是一些索引值對:

{    m_uiMesLocalID=26,    m_ui64MesSvrID=3286135181021621546,    [email protected],    m_nsToUsr=av*or~6,    m_uiStatus=4,    type=1,    msgSource="<msgsource>     <silence>0</silence>     <membercount>3</membercount>    </msgsource>"}

其中type是訊息類型,我們用別的手機在這個群裡發一個紅包,查看控制到日誌,找到紅包訊息的type是:49

  

 

layout:對應的參數是BOOL類型,值為YES
addMoreMsg:對應的參數也是BOOL類型,值為NO
至此,我們已經鎖定了注入入口函數:

addMessageNode: layout: addMoreMsg:

但是,這個不是我們真正要hook的函數!
因為,如果在群聊介面BaseMsgContentViewController中hook這個接收訊息的函數,會存在很大的局限性:

只有進入到群聊介面才能搶紅包

為了在聊天列表介面也能搶到紅包,接下來再做更加深入的探究。
請關注我的[iOS Hacking]系列文章,將會不定期更新!



CGPointZero
連結:https://www.jianshu.com/p/582edd6e4805
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。

[iOS Reverse]logify日誌追蹤,鎖定注入口-控制台查看

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.