九点 . 罐注

iOS逆向1014-微信抢红包案例(二)逻辑分析

2018-06-05  本文已影响24人  lukyy

1014-微信抢红包案例(二)逻辑分析

cy# UIApp.keyWindow.recursiveDescription.toString()  //遍历打印 -->MMUILable 时间的地址:地址1
cy# #地址1.text= @"15:66"     // 改变 label 的内容
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    // 发现
    @interface MoreViewController           // 更多

 @interface NewMainFrameRightTopMenuBtn
 @interface MMBarButton

// 1、新建一个命令行 ZM_CommandLineToo
// 2、cy# 的toSring 放入 ZM_CommandLineToo
command + 运行:换行对齐,代码架构整齐

image.png

安装 MonkeyApp 依赖 theos
// opt --> theos --> bin --> logify.pl
logify.pl:只要有目标文件(class-dump导出的头文件),都能生成xm文件,钩住这个类的所有方法

1、只用终端,创建 hookHeader.xm

image.png image.png

$ ls
$ logify.pl 头文件路径/BaseMsgContentViewController.h > ./hookHeader.xm
创建生成:hookHeader.xm 拖入项目的Logos 文件夹内
编译生成:hookHeader.mm 拖入项目的Logos 文件夹内

2、打入需要的头文件

#import <UIKit/UIKit.h>

@interface BaseMsgContentViewController : UIViewController
@end

WeChatHeardes 导入项目, 在把 BaseMsgContentViewController.h 需要的所有头文件导入

Configfig --> MethodTraceConfig.plist

image.png

BaseMsgContentViewController
CMessageMgr

//---------------------------逻辑分析---------------------------
// 微信应该有一个专门管理消息的对象! 多播代理,找到对应的代理进行消息分发
// 这个方法到底 是谁调用来的!! 看函数调用栈!!找到原调用者,找源头:使用符号表

-- (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 // 会生成一个可执行文件
3.2、放入WeChat可执行文件 到

$ lipo -info WeChat //查看架构
$ lipo WeChat -thin arm64 -output WeChat_arm64 //拆分出arm64架构
$ ./restore-symbol WeChat_arm64 -o WeChatMachO //恢复符号表: 输出 WeiChatMachO

// 恢复符号表 使用单一架构
lipo release-可执行文件 -thin arm64 -output macho_arm64
WeChat: 140.6 M
WeChat_arm64:75.3 M
WeChatMachO: 84.5 M //恢复后 变大了

3.3、 WeChatMachO 改名为 WeChat --> 再放入WeChat.ipa 包内
( WeChat.ipa 包内:先删掉原来的 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;

发一条新消息,函数调用栈改变了 CMessageMgr
@interface CMessageMgr //消息的中转站
hook以下方法

//断点此方法:发一条消息
lldb po arg1
lldb c
lldb po arg1
lldb

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

image.png
方法执行顺序
  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;
分析源码,静态分析,通过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

发个红包,到下面👇

image.png image.png image.png image.png image.png image.png image.png
上一篇下一篇

猜你喜欢

热点阅读