This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_push.go
244 lines (221 loc) · 8.25 KB
/
config_push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package client
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"path"
"github.com/elap5e/go-mobileqq-api/encoding/jce"
"github.com/elap5e/go-mobileqq-api/encoding/uni"
"github.com/elap5e/go-mobileqq-api/log"
"github.com/elap5e/go-mobileqq-api/mobileqq/codec"
)
type ConfigPushRequest struct {
Type uint32 `jce:",1" json:"type,omitempty"`
Seq uint64 `jce:",3" json:"seq,omitempty"`
Buffer []byte `jce:",2" json:"buffer,omitempty"`
}
type ConfigPushResponse struct {
Type uint32 `jce:",1" json:"type,omitempty"`
Seq uint64 `jce:",2" json:"seq,omitempty"`
Buffer []byte `jce:",3" json:"buffer,omitempty"`
}
type SSOServerConfig struct {
TGTGList []SSOServerInfo `jce:",1" json:"2g3g_list,omitempty"`
WiFiList []SSOServerInfo `jce:",3" json:"wifi_list,omitempty"`
Reconnect uint32 `jce:",4" json:"reconnect,omitempty"`
TestSpeed bool `jce:",5" json:"test_speed,omitempty"`
UseNewList bool `jce:",6" json:"use_new_list,omitempty"`
MultiConn uint32 `jce:",7" json:"multi_conn,omitempty"`
HTTP2G3GList []SSOServerInfo `jce:",8" json:"http_2g3g_list,omitempty"`
HTTPWiFiList []SSOServerInfo `jce:",9" json:"http_wifi_list,omitempty"`
Unknown12 []uint64 `jce:",12" json:"unknown12,omitempty"`
Unknown13 []uint64 `jce:",13" json:"unknown13,omitempty"`
Unknown14 uint64 `jce:",14" json:"unknown14,omitempty"`
Unknown15 uint64 `jce:",15" json:"unknown15,omitempty"`
Unknown16 string `jce:",16" json:"unknown16,omitempty"`
} // SsoServerList
type SSOServerInfo struct {
IP string `jce:",1" json:"ip,omitempty"`
Port uint32 `jce:",2" json:"port,omitempty"`
LinkType bool `jce:",3" json:"link_type,omitempty"`
Proxy bool `jce:",4" json:"proxy,omitempty"`
ProtocolType bool `jce:",5" json:"protocol_type,omitempty"`
Timeout uint32 `jce:",6" json:"timeout,omitempty"`
Location string `jce:",8" json:"location,omitempty"`
} // SsoServerListInfo
type FileStorageServerConfig struct {
UpLoadList []FileStorageServerInfo `jce:",0" json:"upload_list,omitempty"`
PictureDownLoadList []FileStorageServerInfo `jce:",1" json:"picture_downLoad_list,omitempty"`
GroupPictureDownLoadList []FileStorageServerInfo `jce:",2" json:"group_picture_downLoad_list,omitempty"`
QZoneProxyServerList []FileStorageServerInfo `jce:",3" json:"qzone_proxy_server_list,omitempty"`
URLEncodeServerList []FileStorageServerInfo `jce:",4" json:"url_encode_server_list,omitempty"`
BigDataIPChannel *BigDataIPChannel `jce:",5" json:"big_data_ip_channel,omitempty"`
VIPEmotionList []FileStorageServerInfo `jce:",6" json:"vip_emotion_list,omitempty"`
C2CPictureDownLoadList []FileStorageServerInfo `jce:",7" json:"c2c_picture_downLoad_list,omitempty"`
FormatIPInfo *FormatIPInfo `jce:",8" json:"format_ip_info,omitempty"`
DomainIPChannel *DomainIPChannel `jce:",9" json:"domain_ip_channel,omitempty"`
PTTList []byte `jce:",10" json:"ptt_list,omitempty"`
}
type FileStorageServerInfo struct {
IP string `jce:",1" json:"ip,omitempty"`
Port uint32 `jce:",2" json:"port,omitempty"`
}
type FormatIPInfo struct {
IP string `jce:",0" json:"ip,omitempty"`
Operator uint64 `jce:",1" json:"operator,omitempty"`
}
type BigDataIPChannel struct {
BigDataIPList []BigDataIP `jce:",0" json:"big_data_ip_list,omitempty"`
Sig []byte `jce:",1" json:"sig,omitempty"`
Key []byte `jce:",2" json:"key,omitempty"`
Uin uint64 `jce:",3" json:"uin,omitempty"`
Flag uint32 `jce:",4" json:"flag,omitempty"`
Buffer []byte `jce:",5" json:"buffer,omitempty"`
}
type BigDataIP struct {
Type uint64 `jce:",0" json:"type,omitempty"`
IPList []BigDataIPInfo `jce:",1" json:"ip_list,omitempty"`
ConfigList []NetSegConfig `jce:",2" json:"config_list,omitempty"`
Size uint64 `jce:",3" json:"size,omitempty"`
}
type BigDataIPInfo struct {
Type uint64 `jce:",0" json:"type,omitempty"`
IP string `jce:",1" json:"ip,omitempty"`
Port uint64 `jce:",2" json:"port,omitempty"`
}
type NetSegConfig struct {
NetType uint64 `jce:",0" json:"net_type,omitempty"`
SegSize uint64 `jce:",1" json:"seg_size,omitempty"`
SegNumber uint64 `jce:",2" json:"seg_number,omitempty"`
CurrentConnNumber uint64 `jce:",3" json:"current_conn_number,omitempty"`
}
type DomainIPChannel struct {
DomainIPList []DomainIP `jce:",0" json:"domain_ip_list,omitempty"`
}
type DomainIP struct {
Type uint32 `jce:",0" json:"type,omitempty"`
IPList []DomainIPInfo `jce:",1" json:"ip_list,omitempty"`
}
type DomainIPInfo struct {
IP uint32 `jce:",1" json:"ip,omitempty"`
Port uint32 `jce:",2" json:"port,omitempty"`
}
type ClientLogConfig struct {
Type uint32 `jce:",1" json:"type,omitempty"`
TimeStart *Timestamp `jce:",2" json:"time_start,omitempty"`
TimeFinish *Timestamp `jce:",3" json:"time_finish,omitempty"`
LogLevel uint8 `jce:",4" json:"log_level,omitempty"`
Cookie uint32 `jce:",5" json:"cookie,omitempty"`
Seq uint64 `jce:",6" json:"seq,omitempty"`
}
type Timestamp struct {
Year uint32 `jce:",1" json:"year,omitempty"`
Month uint8 `jce:",2" json:"month,omitempty"`
Day uint8 `jce:",3" json:"day,omitempty"`
Hour uint8 `jce:",4" json:"hour,omitempty"`
}
type ProxyIPChannel struct {
ProxyIPList []ProxyIP `jce:",0" json:"proxy_ip_list,omitempty"`
Reconnect uint32 `jce:",1" json:"reconnect,omitempty"`
}
type ProxyIP struct {
Type uint64 `jce:",0" json:"type,omitempty"`
IPlist []ProxyIPInfo `jce:",1" json:"ip_list,omitempty"`
}
type ProxyIPInfo struct {
Type uint32 `jce:",0" json:"type,omitempty"`
IP uint32 `jce:",1" json:"ip,omitempty"`
Port uint32 `jce:",2" json:"port,omitempty"`
}
func (c *Client) handleConfigPushRequest(
ctx context.Context,
s2c *codec.ServerToClientMessage,
) (*codec.ClientToServerMessage, error) {
msg := uni.Message{}
req := ConfigPushRequest{}
if err := uni.Unmarshal(ctx, s2c.Buffer, &msg, map[string]interface{}{
"PushReq": &req,
}); err != nil {
return nil, err
}
switch req.Type {
case 0x01:
data := SSOServerConfig{}
if err := jce.Unmarshal(req.Buffer, &data, true); err != nil {
return nil, err
}
tdata, err := json.MarshalIndent(&data, "", " ")
if err != nil {
return nil, err
}
if err := ioutil.WriteFile(path.Join(
c.GetCacheByUsernameDir(s2c.Username), "sso-server-config.json",
), append(tdata, '\n'), 0600); err != nil {
return nil, err
}
go func() {
list := []string{}
for _, info := range data.WiFiList {
list = append(list, fmt.Sprintf("socket://%s:%d#00000:0:1", info.IP, info.Port))
}
c.rpc.SetServers(list)
}()
case 0x02:
data := FileStorageServerConfig{}
if err := jce.Unmarshal(req.Buffer, &data, true); err != nil {
return nil, err
}
tdata, err := json.MarshalIndent(&data, "", " ")
if err != nil {
return nil, err
}
if err := ioutil.WriteFile(path.Join(
c.GetCacheByUsernameDir(s2c.Username), "file-storage-server-config.json",
), append(tdata, '\n'), 0600); err != nil {
return nil, err
}
case 0x03:
data := ClientLogConfig{}
if err := jce.Unmarshal(req.Buffer, &data, true); err != nil {
return nil, err
}
log.Debug().Msg(">>> [dump] req.Buffer 0x03:\n" + hex.Dump(req.Buffer))
case 0x04:
data := ProxyIPChannel{}
if err := jce.Unmarshal(req.Buffer, &data, true); err != nil {
return nil, err
}
log.Debug().Msg(">>> [dump] req.Buffer 0x04:\n" + hex.Dump(req.Buffer))
}
resp := &ConfigPushResponse{
Type: req.Type,
Seq: req.Seq,
Buffer: req.Buffer,
}
buf, err := uni.Marshal(ctx, &uni.Message{
Version: 0x0003,
PacketType: 0x00,
MessageType: 0x00000000,
RequestID: 0x00000000,
ServantName: "QQService.ConfigPushSvc.MainServant",
FuncName: "PushResp",
Buffer: []byte{},
Timeout: 0x00000000,
Context: map[string]string{},
Status: map[string]string{},
}, map[string]interface{}{
"PushResp": resp,
})
if err != nil {
return nil, err
}
return &codec.ClientToServerMessage{
Username: s2c.Username,
Seq: s2c.Seq,
ServiceMethod: ServiceMethodConfigPushResponse,
Buffer: buf,
Simple: true,
}, nil
}