iOS逆向1014-微信搶紅包案例(二)邏輯分析

1014-微信搶紅包案例(二)邏輯分析

cy# UIApp.keyWindow.recursiveDescription.toString()  //遍歷打印 -->MMUILable 時間的地址:地址1
cy# #地址1.text= @"15:66"     // 改變 label 的內(nèi)容
cy# [#地址1 nextResponder]    //--> 地址2:ChatTimeCellView 
cy# [#地址2 nextResponder]    //--> 地址3:UITableViewCellContentView
cy# [#地址3 nextResponder]    //--> 地址4:ChatTableViewCell
cy# [#地址4 nextResponder]    //--> 地址5:YYTableView
cy# [#地址5 nextResponder]    //--> 地址6:UIView
cy# [#地址6 nextResponder]    //--> 地址7:BaseMsgContentViewController
cy# [UIApp.keyWindow.rootViewController _printHierachy].toSring //--> 打印所有測控制器

@interface NMMUINavigationViewController
    @interface NewMainFrameViewController   // 
    @interface BaseMsgContentViewController // 消息
    @interface ContactsContentViewController    // 通訊錄
    @interface FindFriendEntryViewController    // 發(fā)現(xiàn)
    @interface MoreViewController           // 更多

 @interface NewMainFrameRightTopMenuBtn
 @interface MMBarButton


// 1、新建一個命令行 ZM_CommandLineToo
// 2、cy# 的toSring 放入 ZM_CommandLineToo
command + 運行:換行對齊,代碼架構(gòu)整齊

image.png

安裝 MonkeyApp 依賴 theos
// opt --> theos --> bin --> logify.pl
logify.pl:只要有目標文件(class-dump導出的頭文件),都能生成xm文件,鉤住這個類的所有方法

1、只用終端,創(chuàng)建 hookHeader.xm

image.png
image.png

$ ls
$ logify.pl 頭文件路徑/BaseMsgContentViewController.h > ./hookHeader.xm
創(chuàng)建生成:hookHeader.xm 拖入項目的Logos 文件夾內(nèi)
編譯生成:hookHeader.mm 拖入項目的Logos 文件夾內(nèi)

2、打入需要的頭文件

#import <UIKit/UIKit.h>

@interface BaseMsgContentViewController : UIViewController
@end

  • // 方式一

WeChatHeardes 導入項目, 在把 BaseMsgContentViewController.h 需要的所有頭文件導入

  • // 方式二

Configfig --> MethodTraceConfig.plist

image.png

BaseMsgContentViewController
CMessageMgr

//---------------------------邏輯分析---------------------------
// 微信應該有一個專門管理消息的對象! 多播代理,找到對應的代理進行消息分發(fā)
// 這個方法到底 是誰調(diào)用來的!! 看函數(shù)調(diào)用棧!!找到原調(diào)用者,找源頭:使用符號表

-- (void)addMessageNode:(id)arg1 layout:(_Bool)arg2 addMoreMsg:(_Bool)arg3 { %log; %orig; }
addMessageNode:layout: addMoreMsg

-- (void)addMessageNode:(id)arg1 layout:(_Bool)arg2 addMoreMsg:(_Bool)arg3 { 
%log; 
%orig;
 }
lldb po arg1 
lldb c
lldb po arg1
lldb c 
lldb po arg1

3、恢復 符號表
通過開源項目:restore-symbol 恢復

image.png

image.png

終端使用,goshell 直接進入文件
3.1、$ make restore-symbol // 會生成一個可執(zhí)行文件
3.2、放入WeChat可執(zhí)行文件 到

$ lipo -info WeChat //查看架構(gòu)
$ lipo WeChat -thin arm64 -output WeChat_arm64 //拆分出arm64架構(gòu)
$ ./restore-symbol WeChat_arm64 -o WeChatMachO //恢復符號表: 輸出 WeiChatMachO

// 恢復符號表 使用單一架構(gòu)
lipo release-可執(zhí)行文件 -thin arm64 -output macho_arm64
WeChat: 140.6 M
WeChat_arm64:75.3 M
WeChatMachO: 84.5 M //恢復后 變大了

3.3、 WeChatMachO 改名為 WeChat --> 再放入WeChat.ipa 包內(nèi)
( WeChat.ipa 包內(nèi):先刪掉原來的 WeChat,即替換 )

3.4、運行 MokeyApp_WeChat ,點擊進入聊天界面,hook BaseMsgContentViewController

@interface BaseMsgContentLogicController
- (_Bool)onLoadDownMoreMessage;
- (void)AddLocationMessageWithLocation:(id)arg1;
- (void)OnModMsg:(id)arg1 MsgWrap:(id)arg2;
- (void)AddMsg:(id)arg1 MsgWrap:(id)arg2;
hook以下方法
- (void)OnAddMsg:(id)arg1 MsgWrap:(id)arg2;
- (void)DidAddMsg:(id)arg1;

發(fā)一條新消息,函數(shù)調(diào)用棧改變了 CMessageMgr
@interface CMessageMgr //消息的中轉(zhuǎn)站
hook以下方法

  • (void)MainThreadNotifyToExt:(id)arg1;

//斷點此方法:發(fā)一條消息
lldb po arg1
lldb c
lldb po arg1
lldb

查看鉤住的所有方法
Configfig --> MethodTraceConfig.plist --> CMessageMgr

image.png
方法執(zhí)行順序
  1. CheckMessageStatus
  2. onNewSyncAddMessage
  3. AsyncOnPreAddMsg
  4. AsyncOnAddMsg

上圖??hook所有的方法 改為no
hook:CMessageMgr--> onNewSyncAddMessage
消息類型 type:
1、文字
2、圖片
34、語言
49、紅包

來到紅包界面
UITextEffectsWindow
WCPayMainWindow

image.png
$ sh login.sh
cy#  UIApp.keyWindow.recursiveDescription.toString()  //-->名稱的 地址1 address1
cy#  #addr1.text = 'zhangMeng'
cy#  #addr1.nextResponder   //-->UIImageView addr2
cy#  #addr2.subviews        //btn1、btn2 addr3
cy#  #addr3.enable= NO      //開:不能點擊了
cy#  #addr3.enable= YES     //開:能點擊了
cy#  #addr3.allTargets      //--> WCRedEnvelopesReceiveHomeView  addr4
cy#  [#addr4 OnOpenRedEnvelopes]
cy#  choose(WCRedEnvelopesReceiveHomeView) //--> addr5、addr6
cy#  [#addr6 OnOpenRedEnvelopes]
cy#  
cy#  
cy#  
@interface WCRedEnvelopesReceiveHomeView

@interface WCRedEnvelopesReceiveHomeView : MMUIView
- (void)OnOpenRedEnvelopes;
分析源碼,靜態(tài)分析,通過IDA。匯編 
    - 真正的搶紅包方法


@interface WCRedEnvelopesReceiveControlLogic
- (void)WCRedEnvelopesReceiveHomeViewOpenRedEnvelopes;
@interface WCRedEnvelopesControlData
@interface CMessageWrap
@interface WCPayInfoItem

WCRedEnvelopesControlData  *m_data = self.m_data;
CMessageWrap  *msgWrap          = [m_data m_oSelectedMessageWrap];
WCPayInfoItem  *item                 = [msgWrap m_o WCPayInfoItem];
NSString *url                   = [item m_c2cNativeUrl];

//合并方法:拿到紅包的url
NSString *url = [[[self.m_data m_oSelectedMessageWrap] 
                                m_o WCPayInfoItem]
                                m_c2cNativeUrl];

3.4圖

image.png

3.2圖

image.png
image.png

到下面??

image.png

發(fā)個紅包,到下面??

image.png
image.png
image.png
image.png
image.png
image.png
image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容