iOS逆向1015-微信搶紅包案例(三)搶紅包方法_用偽代碼還原

1015-微信搶紅包案例(三)搶紅包方法_用偽代碼還原

還原此類:WCRedEnvelopesReceiveControlLogic


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

@interface NewMainFrameRightTopMenuBtn
@end

@interface MMBarButton
@end

@interface BaseMsgContentViewController : MMObject
- (_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;
@end

@interface CMessageMgr  //消息的中轉(zhuǎn)站
hook以下方法
- (void)MainThreadNotifyToExt:(id)arg1;
@end


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





//-------------------------  開始:WeChatHeader.h -------------------------
//  001--WeChatDemo11
//  Created by H on 2018/5/18.
//  Copyright ? 2018年 H. All rights reserved.
//
#ifndef WeChatHeader_h
#define WeChatHeader_h
// See http://iphonedevwiki.net/index.php/Logos
#import <UIKit/UIKit.h>
#define HKDefaults [NSUserDefaults standardUserDefaults]
#define HKSWITCHKEY @"HKSWITCHKEY"
#define HKTIMEKEY @"HKTIMEKEY"

//關(guān)于界面
@interface MMTableViewInfo
- (long long)numberOfSectionsInTableView:(id)arg1;
@end

@interface WCRedEnvelopesReceiveHomeView{
    id m_delegate;
    NSDictionary *m_dicBaseInfo;
}
@end


@interface WCPayInfoItem :NSObject
@property(retain, nonatomic) NSString *m_c2cNativeUrl;
@end


@interface CMessageWrap :NSObject
@property(retain, nonatomic) WCPayInfoItem *m_oWCPayInfoItem;
@end


@interface WCRedEnvelopesControlData :NSObject
@property(retain, nonatomic) CMessageWrap *m_oSelectedMessageWrap;
@property(retain, nonatomic) NSDictionary *m_structDicRedEnvelopesBaseInfo;
@end


@interface WCRedEnvelopesControlLogic{
    WCRedEnvelopesControlData *m_data;
}
@end


@interface WCRedEnvelopesReceiveControlLogic:WCRedEnvelopesControlLogic
@end


@interface WCBizUtil: NSObject
+ (id)dictionaryWithDecodedComponets:(id)arg1 separator:(id)arg2;
@end
#endif /* WeChatHeader_h */
//------------------------- 結(jié)束:WeChatHeader.h -------------------------





//========================= 開始:_01__WeChatDemo11Dylib.xm =========================
@interface MMServiceCenter
+(id)defaultCenter;
-(id)getService:(Class)arg1;
@end

@interface MMMsgLogicManager
-(id)GetCurrentLogicController;
@end


@interface WeixinContentLogicController
-(id)m_contact;
@end


@interface WCRedEnvelopesLogicMgr
-(void)OpenRedEnvelopesRequest:(id)dic;
@end


@interface CContactMgr
-(id)getSelfContact;
@end

@interface CBaseContact
@property(retain, nonatomic) NSString *m_nsHeadImgUrl;
@property(retain, nonatomic) NSString *m_nsUsrName;
@end


@interface CContact :CBaseContact
-(id)getContactDisplayName;

@end

@interface WCPayLogicMgr
- (void)setRealnameReportScene:(unsigned int)arg1;
- (void)checkHongbaoOpenLicense:(id)arg1 acceptCallback:(void(^)())arg2 denyCallback:(void(^)())arg3;
@end
//========================= 結(jié)束:_01__WeChatDemo11Dylib.xm =========================




/***************************************************************************
@interface WeiXinContentLogicController: BaseMsgContentViewController
@end


@interface BaseMsgContentLogicController : MMObject 
{
    BaseMsgContentViewController *m_viewController;
    CBaseContact *m_contact;

    CContactVerifyLogic *m_contactVerifyLogic;
}
@end
**************************************************************************/

%hook
- (void)OpenRedEnvelopesRequest:(id)arg1 {
    NSLOg(@"%@",arg1)
    %orgi;
}
%end

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

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



//--------------------邏輯分析  --------
// 微信應(yīng)該有一個專門管理消息的對象!
// 這個方法到底 是誰調(diào)用來的!! 看函數(shù)調(diào)用棧!!


%hook WCRedEnvelopesReceiveHomeView
- (void)OnOpenRedEnvelopes{
    %orig;
//    //拿到成員變量
//    NSDictionary * dict = c
//    //打印字典
//    NSArray * arr = [dict allKeys];
//    for(int i = 0;i < arr.count ;i++){
//        NSLog(@"%@:%@",arr[i],[dict objectForKey:arr[i]]);
//    }
//    //拿到代理
//    WeChatdelegate * delegate = MSHookIvar<WeChatdelegate *>(self,"m_delegate");
//
//    [delegate WCRedEnvelopesReceiveHomeViewOpenRedEnvelopes];
//    NSLog(@"delegateClass: %@",[delegate class]);
}
%end


%hook CMessageMgr
- (void)onNewSyncAddMessage:(id)arg1{
    NSLog(@"%@\n%@",arg1,[arg1 class]);
    //通過分析,找到紅包的消息類型是49!
    //if type == 49 {開搶!!!! }
    %orig;
}
%end


%hook WCRedEnvelopesReceiveControlLogic
-(void)WCRedEnvelopesReceiveHomeViewOpenRedEnvelopes{
    //偽代碼
    WCRedEnvelopesControlData * m_data = MSHookIvar<WCRedEnvelopesControlData *>(self,"m_data");
    CMessageWrap  * msgWrap         = [m_data  m_oSelectedMessageWrap];
    WCPayInfoItem * payInfoItem     = [msgWrap m_oWCPayInfoItem];
    NSString * c2cNativeUrl         = [payInfoItem m_c2cNativeUrl];
    NSUInteger len = [@"wxpay://c2cbizmessagehandler/hongbao/receivehongbao?" length];
    NSString * c2cNativeUrl2 = [c2cNativeUrl substringFromIndex:len];
    NSDictionary * url_dic   = [%c(WCBizUtil) dictionaryWithDecodedComponets:c2cNativeUrl2 separator:@"&"];
   
    NSMutableDictionary * mutalbe_dic = [%c(NSMutableDictionary) dictionary];
    [mutalbe_dic setObject:@"1" forKey:@"msgType"];
    [mutalbe_dic setObject:url_dic[@"sendid"] forKey:@"sendId"];
    [mutalbe_dic setObject:url_dic[@"channelid"] forKey:@"channelId"];
   
    MMServiceCenter * mmserCent = [%c(MMServiceCenter) defaultCenter];
    Class ccmgr = [%c(CContactMgr) class];
    CContactMgr * contactMgr = [mmserCent getService:ccmgr];
    CContact * selfContact = [contactMgr getSelfContact];
    // displayName --> NSTaggePointString
    id displayName = [selfContact getContactDisplayName];
    NSLog(@"---displayName= %@",[displayName class]);
    [mutalbe_dic setObject:displayName forKey:@"nickName"];
    [mutalbe_dic setObject:[selfContact m_nsHeadImgUrl] forKey:@"headImg"];
    if (msgWrap)
    {
        NSString * nativeUrl =  c2cNativeUrl;
        [mutalbe_dic setObject:nativeUrl forKey:@"nativeUrl"];
    }
    MMMsgLogicManager * redEvenlopsLogicMgr = [[%c(MMServiceCenter) defaultCenter] getService:[%c(MMMsgLogicManager) class]];
    WeixinContentLogicController * currentLogicContoller  = [redEvenlopsLogicMgr GetCurrentLogicController];
    if ( currentLogicContoller )
    {
        CBaseContact * m_contact = [currentLogicContoller m_contact];
        if ( m_contact ){
            CBaseContact * contact = [currentLogicContoller m_contact];
            NSString * nsUsrName = [contact m_nsUsrName];
            if ( nsUsrName ){
                [mutalbe_dic setObject:nsUsrName forKey:@"sessionUserName"];
            }
        }
    }
    
    NSDictionary * m_dicBaseInfo = [m_data m_structDicRedEnvelopesBaseInfo];
    NSString * timingIdentifier = m_dicBaseInfo[@"timingIdentifier"];
    if ([timingIdentifier length]){
        [mutalbe_dic setObject:timingIdentifier forKey:@"timingIdentifier"];
    }

    WCPayLogicMgr * payLogic = [[%c(MMServiceCenter) defaultCenter] getService:[%c(WCPayLogicMgr) class]];
    [payLogic setRealnameReportScene:(unsigned int)1003];
    id subScript = [m_dicBaseInfo objectForKeyedSubscript:@"agree_duty"];

    [payLogic checkHongbaoOpenLicense:subScript acceptCallback:^(){
        WCRedEnvelopesLogicMgr * redEvenlopsLogicMgr  = [[%c(MMServiceCenter) defaultCenter] getService:[%c(WCRedEnvelopesLogicMgr) class]];

        [redEvenlopsLogicMgr OpenRedEnvelopesRequest:mutalbe_dic];
        
    } denyCallback:^(){
       
    }];
    
}

%end


2.1、File --> Script file (Alt + F7) --> 顯示部分為代碼類與方法

image.png

2.2、全選,復(fù)制到 Sublime Text 中查看,并 推算出偽代碼

image.png

3、恢復(fù)block 符號表

通過開源項(xiàng)目:restore-symbol 恢復(fù)

3.1 使用ida 通過 ida_search_block.py 腳本 生成 block_symbol.json 文件,放入 restore-symbol2 項(xiàng)目中
3.2、 終端使用,goshell 直接進(jìn)入文件 恢復(fù) 符號表

$ ./restore-symbol WeChat -o WeChat_block -j block_symbol.json

WeChat: 140.6 M
WeChat_arm64:75.3 M
WeChatMachO: 84.5 M //恢復(fù)后 變大了
WeChat_block: 94M

3.3、 WeChat_block 改名為 WeChat --> 再放入WeChat.ipa 包內(nèi)

( WeChat.ipa 包內(nèi):先刪掉原來的 WeChat,即替換 )

3.4、 重新用ida 解析,搜索查看 WCRedEnvelopesReceiveControlLogic

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)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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