Skip to content

Commit 154bfa4

Browse files
committed
for wechat 6.5.5
参考了buginux的核心改动,节省调试工作。不过差异越来越大了。 to be tested...
1 parent 37c0b82 commit 154bfa4

File tree

7 files changed

+263
-20
lines changed

7 files changed

+263
-20
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ _THEOS_PLATFORM_DPKG_DEB_COMPRESSION=gzip
77
include theos/makefiles/common.mk
88

99
TWEAK_NAME = WeChatRedEnvelop
10-
WeChatRedEnvelop_FILES = Tweak.xm Debug.mm info.cpp
10+
WeChatRedEnvelop_FILES = Tweak.xm Debug.mm info.cpp xpruntime.c
1111
WeChatRedEnvelop_FRAMEWORKS = UIKit AudioToolbox
12+
WeChatRedEnvelop_CPPFLAGS=-std=c++11
13+
#CCFLAGS=-std=c++11
1214

1315
include $(THEOS_MAKE_PATH)/tweak.mk
1416

Tweak.xm

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55

66
#define PL_PATH "/private/var/mobile/Library/Preferences/com.tencent.wcreopt.plist"
77

8+
9+
static void * oc_rq = 0;
10+
11+
static void ocrq_set(NSString* skey, NSObject* svalue)
12+
{
13+
CFTypeRef cobj = (__bridge CFTypeRef)svalue;
14+
if (cobj) CFRetain(cobj);
15+
if (!oc_rq) oc_rq = rq_create();
16+
rq_set(oc_rq, [skey UTF8String], (void*)cobj);
17+
}
18+
19+
static Boolean ocrq_get(NSString* skey, NSObject** svalue)
20+
{
21+
void * cobj = 0;
22+
if (!skey || !svalue || !oc_rq) return FALSE;
23+
rq_get(oc_rq, [skey UTF8String], &cobj);
24+
if (!cobj) return FALSE;
25+
*svalue = (__bridge NSObject*)cobj;
26+
return TRUE;
27+
}
28+
829
NSMutableDictionary * loadSettings()
930
{
1031
static int64_t timeid = -1;
@@ -22,6 +43,42 @@ NSMutableDictionary * loadSettings()
2243
return oldinfo;
2344
}
2445

46+
47+
%hook WCRedEnvelopesLogicMgr
48+
- (void)OnWCToHongbaoCommonResponse:(HongBaoRes *)arg1 Request:(HongBaoReq *)arg2
49+
{
50+
%orig;
51+
52+
// 非参数查询请求
53+
if (arg1.cgiCmdid != 3) return;
54+
55+
NSString *string = [[NSString alloc] initWithData:arg1.retText.buffer encoding:NSUTF8StringEncoding];
56+
NSDictionary *dictionary = [string JSONDictionary];
57+
58+
// 自己已经抢过
59+
if ([dictionary[@"receiveStatus"] integerValue] == 2)
60+
return;
61+
62+
// 红包被抢完
63+
if ([dictionary[@"hbStatus"] integerValue] == 4)
64+
return;
65+
66+
// 没有这个字段会被判定为使用外挂
67+
if (!dictionary[@"timingIdentifier"])
68+
return;
69+
70+
NSString* xxkey = @"";
71+
NSMutableDictionary * par_open = 0;
72+
ocrq_get(xxkey, &par_open);
73+
if (par_open)
74+
{
75+
par_open[@"timingIdentifier"] = dictionary[@"timingIdentifier"];
76+
WCRedEnvelopesLogicMgr *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]];
77+
[logicMgr OpenRedEnvelopesRequest:par_open];
78+
}
79+
}
80+
%end
81+
2582
%hook CMessageMgr
2683
- (void)AsyncOnAddMsg:(NSString *)msg MsgWrap:(CMessageWrap *)wrap {
2784
%orig;
@@ -35,16 +92,11 @@ NSMutableDictionary * loadSettings()
3592
CContact *selfContact = [contactManager getSelfContact];
3693

3794
if (msgType != 49) return;
38-
BOOL isMesasgeFromMe = NO;
95+
3996
if ([wrap.m_nsFromUsr isEqualToString:selfContact.m_nsUsrName]) {
40-
isMesasgeFromMe = YES;
41-
}
42-
if (isMesasgeFromMe)
43-
{
4497
// 自己发的红包,就不需要机器人来抢了吧??
4598
return;
4699
}
47-
48100
if ([wrap.m_nsContent rangeOfString:@"wxpay://"].location == NSNotFound)
49101
return; //不是红包??
50102
if ([wrap.m_nsFromUsr rangeOfString:@"@chatroom"].location == NSNotFound)
@@ -114,21 +166,31 @@ NSMutableDictionary * loadSettings()
114166
NSString *nativeUrl = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl];
115167
nativeUrl = [nativeUrl substringFromIndex:[@"wxpay://c2cbizmessagehandler/hongbao/receivehongbao?" length]];
116168
NSDictionary *nativeUrlDict = [%c(WCBizUtil) dictionaryWithDecodedComponets:nativeUrl separator:@"&"];
117-
118-
/** 构造参数 */
119-
NSMutableDictionary *params = [@{} mutableCopy];
120-
params[@"msgType"] = nativeUrlDict[@"msgtype"] ?: @"1";
121-
params[@"sendId"] = nativeUrlDict[@"sendid"] ?: @"";
169+
WCRedEnvelopesLogicMgr *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]];
170+
sl_printf("%s 打开红包!延时%lf", ssig, (double) delayTime);
171+
172+
CContactMgr *contactManager = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("CContactMgr") class]];
173+
CContact *selfContact = [contactManager getSelfContact];
174+
NSMutableDictionary *par_open = [[NSMutableDictionary alloc] init];
175+
par_open[@"msgType"] = nativeUrlDict[@"msgtype"] ?: @"1";
176+
par_open[@"sendId"] = nativeUrlDict[@"sendid"] ?: @"";
177+
par_open[@"channelId"] = nativeUrlDict[@"channelid"] ?: @"1";
178+
par_open[@"nickName"] = [selfContact getContactDisplayName] ?: @"小锅";
179+
par_open[@"headImg"] = [selfContact m_nsHeadImgUrl] ?: @"";
180+
par_open[@"nativeUrl"] = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl] ?: @"";
181+
par_open[@"sessionUserName"] = wrap.m_nsFromUsr ?: @"";
182+
183+
NSString* xxkey = @"";
184+
ocrq_set(xxkey, par_open);
185+
186+
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
187+
params[@"agreeDuty"] = @"0";
122188
params[@"channelId"] = nativeUrlDict[@"channelid"] ?: @"1";
123-
params[@"nickName"] = [selfContact getContactDisplayName] ?: @"小锅";
124-
params[@"headImg"] = [selfContact m_nsHeadImgUrl] ?: @"";
189+
params[@"inWay"] = @"0";
190+
params[@"msgType"] = nativeUrlDict[@"msgtype"] ?: @"1";
125191
params[@"nativeUrl"] = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl] ?: @"";
126-
params[@"sessionUserName"] = wrap.m_nsFromUsr ?: @"";
127-
128-
MMServiceCenter * center = (MMServiceCenter*)[objc_getClass("MMServiceCenter") defaultCenter];
129-
WCRedEnvelopesLogicMgr *logicMgr = [center getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]];
130-
sl_printf("%s 打开红包!!延时%lf", ssig, (double) delayTime);
131-
[logicMgr OpenRedEnvelopesRequest:params];
192+
params[@"sendId"] = nativeUrlDict[@"sendid"] ?: @"";
193+
[logicMgr ReceiverQueryRedEnvelopesRequest:params];
132194
});
133195
}
134196
%end

WeChatRedEnvelop.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ struct set_;
2020

2121
typedef void (^CDUnknownBlockType)(void); // return type and parameters are unknown
2222

23+
@interface NSString (NSString_SBJSON)
24+
- (id)JSONDictionary;
25+
- (id)JSONArray;
26+
- (id)JSONValue;
27+
@end
2328

2429
@interface NSError (SimpleConstructor)
2530
+ (_Bool)clearError:(id *)arg1;

info.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
#include <mach-o/dyld.h>
1010
#include <string>
11+
#include <set>
12+
using std::set;
1113

1214
#include "info.h"
1315
#include "Debug.h"
16+
#include "xpruntime.h"
1417

1518
using std::string;
1619

@@ -67,3 +70,107 @@ int dont_open(const char * content, const char * kwds)
6770
}
6871
return 0;
6972
}
73+
74+
class CRecentQueue
75+
{
76+
enum {TIMEOUT=60000};
77+
struct RQV{
78+
string skey;
79+
void * obj;
80+
int64_t tick;
81+
int64_t seq;
82+
RQV(const char * key):skey(key){}
83+
};
84+
set<RQV*> bkey, bid;
85+
long m_seqidx;
86+
protected:
87+
RQV* _find(set<RQV*> & which, const char * key)
88+
{
89+
RQV val(key);
90+
auto it = which.find(&val);
91+
return (it == which.end()) ? 0 : *it;
92+
}
93+
void clear_to()
94+
{
95+
int32_t tick = GetTickCount64b();
96+
for (auto it = bid.begin(); it != bid.end(); )
97+
{
98+
RQV * w = *it;
99+
if (w->tick + TIMEOUT < tick)
100+
{
101+
bkey.erase(w);
102+
it = bid.erase(it++);
103+
}
104+
else
105+
break;
106+
}
107+
}
108+
109+
public:
110+
CRecentQueue()
111+
{
112+
}
113+
~CRecentQueue(){}
114+
public:
115+
void get(const char * key, void ** v)
116+
{
117+
clear_to();
118+
RQV * r1 = _find(bkey, key);
119+
*v = r1 ? r1->obj : 0;
120+
}
121+
void set(const char * key, void * v)
122+
{
123+
clear_to();
124+
RQV * r1 = _find(bkey, key);
125+
if (r1)
126+
{
127+
if (v)
128+
{
129+
bid.erase(r1);
130+
r1->obj = v;
131+
r1->seq = ++m_seqidx;
132+
r1->tick = GetTickCount64b();
133+
bid.insert(r1);
134+
}
135+
else
136+
{
137+
bid.erase(r1);
138+
bkey.erase(r1);
139+
delete r1;
140+
}
141+
}
142+
else if (v)
143+
{
144+
//new add.
145+
RQV * prqv = new RQV(key);
146+
prqv->obj = v;
147+
prqv->seq = ++m_seqidx;
148+
prqv->tick = GetTickCount64b();
149+
bid.insert(prqv);
150+
bkey.insert(prqv);
151+
}
152+
}
153+
};
154+
155+
void * rq_create()
156+
{
157+
return new CRecentQueue();
158+
}
159+
160+
void rq_set(void * rq, const char * key, void * obj)
161+
{
162+
CRecentQueue * rq_ = (CRecentQueue*)rq;
163+
return rq_->set(key, obj);
164+
}
165+
166+
void rq_get(void * rq, const char * key, void ** pobj)
167+
{
168+
CRecentQueue * rq_ = (CRecentQueue*)rq;
169+
return rq_->get(key, pobj);
170+
}
171+
172+
void rq_delete(void * rq)
173+
{
174+
CRecentQueue * rq_ = (CRecentQueue*)rq;
175+
delete rq_;
176+
}

info.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ extern "C"{
1010
// 特定文字是否抢红包
1111
int dont_open(const char * content, const char * kwds);
1212

13+
void * rq_create();
14+
void rq_set(void * rq, const char * key, void * obj);
15+
void rq_get(void * rq, const char * key, void ** pobj);
16+
void rq_delete(void * rq);
17+
1318
#ifdef __cplusplus
1419
}
1520
#endif

xpruntime.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "xpruntime.h"
2+
#include <unistd.h>
3+
#include <assert.h>
4+
#include <sys/sysctl.h>
5+
#include <mach/clock.h>
6+
#include <mach/clock_types.h>
7+
#include <mach/mach_host.h>
8+
#include <mach/mach.h>
9+
#include <sys/socket.h>
10+
#include <arpa/inet.h>
11+
#include <netinet/in.h>
12+
#include <stdio.h>
13+
#include <sys/types.h>
14+
#include <netdb.h>
15+
#include <stdlib.h>
16+
17+
static int get_clock_ref()
18+
{
19+
clock_serv_t clock_ref = 0;
20+
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_ref);
21+
return clock_ref;
22+
}
23+
24+
static int darwin_clock_gettime_MONOTONIC(struct timespec *tp)
25+
{
26+
static int clockinit = 0;
27+
static clock_serv_t clock_ref = 0;
28+
mach_timespec_t mach_tp = {0};
29+
30+
if (clockinit == 0)
31+
{
32+
clockinit = 1;
33+
clock_ref = get_clock_ref();
34+
}
35+
36+
kern_return_t ret = clock_get_time(clock_ref, &mach_tp);
37+
if (ret != KERN_SUCCESS) return -1;
38+
39+
tp->tv_sec = mach_tp.tv_sec;
40+
tp->tv_nsec = mach_tp.tv_nsec;
41+
return 0;
42+
}
43+
44+
int64_t GetTickCount64b()
45+
{
46+
struct timespec ts = {0};
47+
int r = darwin_clock_gettime_MONOTONIC(&ts);
48+
if (r<0) return 1;
49+
int64_t a = (int64_t)ts.tv_sec * 1000 + ts.tv_nsec/1000000;
50+
return a;
51+
}
52+

xpruntime.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include <stdint.h>
3+
4+
#ifdef __cplusplus
5+
#define extc extern "C"
6+
#else
7+
#define extc
8+
#endif
9+
10+
extc int64_t GetTickCount64b();

0 commit comments

Comments
 (0)