Skip to content

Instantly share code, notes, and snippets.

@Li-blog
Created October 28, 2016 10:31
Show Gist options
  • Save Li-blog/14c47c842192fdf190a40639a72bddab to your computer and use it in GitHub Desktop.
Save Li-blog/14c47c842192fdf190a40639a72bddab to your computer and use it in GitHub Desktop.
WeChatDiceEntry class in WeChatDice.framework
//
// WeChatDiceEntry.h
// WeChat
//
// Created by Wang Jinli on 2016/10/28.
// Copyright © 2016 Wang Jinli. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface CEmoticonWrap
@property(nonatomic) unsigned int m_extFlag; // @synthesize m_extFlag;
@property(retain, nonatomic) NSData *m_imageData; // @synthesize m_imageData;
@property(retain, nonatomic) NSString *m_nsThumbImgUrl; // @synthesize m_nsThumbImgUrl;
@property(retain, nonatomic) NSString *m_nsDesignerId; // @synthesize m_nsDesignerId;
@property(nonatomic) unsigned int m_lastUsedTime; // @synthesize m_lastUsedTime;
@property(retain, nonatomic) NSString *m_packageId; // @synthesize m_packageId;
@property(retain, nonatomic) NSString *m_nsThumbImgPath; // @synthesize m_nsThumbImgPath;
@property(retain, nonatomic) NSMutableDictionary *m_extInfo; // @synthesize m_extInfo;
@property(retain, nonatomic) NSString *m_nsAppID; // @synthesize m_nsAppID;
@property(nonatomic) unsigned int m_uiGameType; // @synthesize m_uiGameType;
@property(nonatomic) _Bool m_bCanDelete; // @synthesize m_bCanDelete;
@property(retain, nonatomic) NSString *m_nsMD5; // @synthesize m_nsMD5;
@property(nonatomic) unsigned int m_uiType; // @synthesize m_uiType;
@end
@interface CMessageWrap
@property(retain, nonatomic) NSString *m_aesKey; // @dynamic m_aesKey;
@property(nonatomic) _Bool m_bShowRewardTips; // @dynamic m_bShowRewardTips;
@property(retain, nonatomic) NSString *m_cdnUrlString; // @dynamic m_cdnUrlString;
@property(retain, nonatomic) NSString *m_encryptUrlString; // @dynamic m_encryptUrlString;
@property(retain, nonatomic) NSString *m_nsDesignerId; // @dynamic m_nsDesignerId;
@property(copy, nonatomic) NSString *m_nsEmoticonBelongToProductID; // @dynamic m_nsEmoticonBelongToProductID;
@property(retain, nonatomic) NSString *m_nsThumbImgUrl; // @dynamic m_nsThumbImgUrl;
@property(nonatomic) unsigned int m_uiEmoticonHeight; // @dynamic m_uiEmoticonHeight;
@property(nonatomic) unsigned int m_uiEmoticonType; // @dynamic m_uiEmoticonType;
@property(nonatomic) unsigned int m_uiEmoticonWidth; // @dynamic m_uiEmoticonWidth;
@property(nonatomic) unsigned int m_uiGameContent; // @dynamic m_uiGameContent;
@property(nonatomic) unsigned int m_uiGameType; // @dynamic m_uiGameType;
@end
@interface WeChatDiceEntry : NSObject
+ (void)load;
+ (id)getMD5ByGameContent_hooked:(unsigned int)arg1;
- (void)AddEmoticonMsg_hooked:(id)arg1 MsgWrap:(id)arg2;
- (void)StartUpload_hooked:(id)arg1;
@end
//
// WeChatDiceEntry.m
// WeChat
//
// Created by Wang Jinli on 2016/10/28.
// Copyright © 2016 Wang Jinli. All rights reserved.
//
#import "WeChatDiceEntry.h"
#import <objc/runtime.h>
@implementation WeChatDiceEntry
+ (void)load {
Class gCtl = NSClassFromString(@"GameController");
Class cMsgMgr = NSClassFromString(@"CMessageMgr");
Class upMgr = NSClassFromString(@"CEmoticonUploadMgr");
Method getMD5ByGameContent = class_getClassMethod(gCtl, @selector(getMD5ByGameContent:));
Method AddEmoticonMsg = class_getInstanceMethod(cMsgMgr, @selector(AddEmoticonMsg:MsgWrap:));
Method StartUpload = class_getInstanceMethod(upMgr, @selector(StartUpload:));
Method getMD5ByGameContent_hooked = class_getClassMethod(self, @selector(getMD5ByGameContent_hooked:));
Method AddEmoticonMsg_hooked = class_getInstanceMethod(self, @selector(AddEmoticonMsg_hooked:MsgWrap:));
Method StartUpload_hooked = class_getInstanceMethod(self, @selector(StartUpload_hooked:));
IMP orig1 = method_getImplementation(getMD5ByGameContent);
IMP orig2 = method_getImplementation(AddEmoticonMsg);
IMP orig3 = method_getImplementation(StartUpload);
IMP swz1 = method_getImplementation(getMD5ByGameContent_hooked);
IMP swz2 = method_getImplementation(AddEmoticonMsg_hooked);
IMP swz3 = method_getImplementation(StartUpload_hooked);
const char *origType1 = method_getTypeEncoding(getMD5ByGameContent);
const char *origType2 = method_getTypeEncoding(AddEmoticonMsg);
const char *origType3 = method_getTypeEncoding(StartUpload);
const char *swzType1 = method_getTypeEncoding(getMD5ByGameContent_hooked);
const char *swzType2 = method_getTypeEncoding(AddEmoticonMsg_hooked);
const char *swzType3 = method_getTypeEncoding(StartUpload_hooked);
Class metaClass = objc_getMetaClass(class_getName(gCtl));
class_replaceMethod(metaClass, @selector(getMD5ByGameContent_hooked:), orig1, origType1);
class_replaceMethod(metaClass, @selector(getMD5ByGameContent:), swz1, swzType1);
class_replaceMethod(cMsgMgr, @selector(AddEmoticonMsg_hooked:MsgWrap:), orig2, origType2);
class_replaceMethod(cMsgMgr, @selector(AddEmoticonMsg:MsgWrap:), swz2, swzType2);
class_replaceMethod(upMgr, @selector(StartUpload_hooked:), orig3, origType3);
class_replaceMethod(upMgr, @selector(StartUpload:), swz3, swzType3);
}
+ (id)getMD5ByGameContent_hooked:(unsigned int)arg1 {
if (arg1 > 3 && arg1 < 10) {
return [self getMD5ByGameContent_hooked:9];
} else if (arg1 > 0 && arg1 < 4) {
return [self getMD5ByGameContent_hooked:1];
} else {
return [self getMD5ByGameContent_hooked:arg1];
}
}
- (void)AddEmoticonMsg_hooked:(id)arg1 MsgWrap:(id)arg2 {
CMessageWrap *wrap = (CMessageWrap *)arg2;
if (wrap.m_uiGameType == 2) {
[self AddEmoticonMsg_hooked:arg1 MsgWrap:setDice(arg2, 6)];
} else if (wrap.m_uiGameType == 1) {
[self AddEmoticonMsg_hooked:arg1 MsgWrap:setJsb(arg2, 1)];
} else {
[self AddEmoticonMsg_hooked:arg1 MsgWrap:arg2];
}
}
- (void)StartUpload_hooked:(id)arg1 {
CMessageWrap *wrap = (CMessageWrap *)arg1;
if (wrap.m_uiGameType == 2) {
[self StartUpload_hooked:setDice(arg1, 6)];
} else if (wrap.m_uiGameType == 1) {
[self StartUpload_hooked:setJsb(arg1, 1)];
} else {
[self StartUpload_hooked:arg1];
}
}
CMessageWrap *setDice(CMessageWrap *wrap, unsigned int point) {
if (wrap.m_uiGameType == 2) {
wrap.m_uiGameContent = point + 3;
}
return wrap;
}
CMessageWrap *setJsb(CMessageWrap *wrap, unsigned int type) {
if (wrap.m_uiGameType == 1) {
wrap.m_uiGameContent = type;
}
return wrap;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment