Skip to content

Commit

Permalink
client: move device&version into c.transport
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvxdr1123 committed Feb 16, 2023
1 parent cfd7d92 commit ed15fbc
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 160 deletions.
233 changes: 117 additions & 116 deletions client/builders.go

Large diffs are not rendered by default.

28 changes: 13 additions & 15 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ type QQClient struct {
servers []netip.AddrPort
currServerIndex int
retryTimes int
version *auth.AppVersion
device *auth.Device
alive bool

// session info
Expand Down Expand Up @@ -199,11 +197,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
highwaySession: new(highway.Session),
}

cli.transport = &network.Transport{
Sig: cli.sig,
Version: &cli.version,
Device: &cli.device,
}
cli.transport = &network.Transport{Sig: cli.sig}
cli.oicq = oicq.NewCodec(cli.Uin)
{ // init atomic values
cli.SequenceId.Store(0x3635)
Expand All @@ -219,14 +213,18 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
return cli
}

func (c *QQClient) version() *auth.AppVersion {
return c.transport.Version
}

func (c *QQClient) Device() *DeviceInfo {
return c.device
return c.transport.Device
}

func (c *QQClient) UseDevice(info *auth.Device) {
c.version = info.Protocol.Version()
c.device = info
c.highwaySession.AppID = int32(c.version.AppId)
c.transport.Version = info.Protocol.Version()
c.transport.Device = info
c.highwaySession.AppID = int32(c.version().AppId)
c.sig.Ksid = []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", info.IMEI))
}

Expand Down Expand Up @@ -278,7 +276,7 @@ func (c *QQClient) TokenLogin(token []byte) error {
c.oicq.WtSessionTicketKey = r.ReadBytesShort()
c.sig.OutPacketSessionID = r.ReadBytesShort()
// SystemDeviceInfo.TgtgtKey = r.ReadBytesShort()
c.device.TgtgtKey = r.ReadBytesShort()
c.Device().TgtgtKey = r.ReadBytesShort()
}
_, err = c.sendAndWait(c.buildRequestChangeSigPacket(true))
if err != nil {
Expand Down Expand Up @@ -408,7 +406,7 @@ func (c *QQClient) init(tokenLogin bool) error {
go c.doHeartbeat()
}
_ = c.RefreshStatus()
if c.version.Protocol == auth.QiDian {
if c.version().Protocol == auth.QiDian {
_, _ = c.sendAndWait(c.buildLoginExtraPacket()) // 小登录
_, _ = c.sendAndWait(c.buildConnKeyRequestPacket()) // big data key 如果等待 config push 的话时间来不及
}
Expand All @@ -429,7 +427,7 @@ func (c *QQClient) GenToken() []byte {
w.WriteBytesShort(c.sig.EncryptedA1)
w.WriteBytesShort(c.oicq.WtSessionTicketKey)
w.WriteBytesShort(c.sig.OutPacketSessionID)
w.WriteBytesShort(c.device.TgtgtKey)
w.WriteBytesShort(c.Device().TgtgtKey)
})
}

Expand Down Expand Up @@ -478,7 +476,7 @@ func (c *QQClient) ReloadFriendList() error {
// 当使用普通QQ时: 请求好友列表
// 当使用企点QQ时: 请求外部联系人列表
func (c *QQClient) GetFriendList() (*FriendListResponse, error) {
if c.version.Protocol == auth.QiDian {
if c.version().Protocol == auth.QiDian {
rsp, err := c.getQiDianAddressDetailList()
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions client/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func decodeLoginResponse(c *QQClient, pkt *network.Packet) (any, error) {
if m.Exists(0x402) {
c.sig.Dpwd = []byte(utils.RandomString(16))
c.sig.T402 = m[0x402]
h := md5.Sum(append(append(c.device.Guid, c.sig.Dpwd...), c.sig.T402...))
h := md5.Sum(append(append(c.Device().Guid, c.sig.Dpwd...), c.sig.T402...))
c.sig.G = h[:]
}
if m.Exists(0x546) {
Expand All @@ -61,7 +61,7 @@ func decodeLoginResponse(c *QQClient, pkt *network.Packet) (any, error) {
if m.Exists(0x403) {
c.sig.RandSeed = m[0x403]
}
c.decodeT119(m[0x119], c.device.TgtgtKey)
c.decodeT119(m[0x119], c.Device().TgtgtKey)
return LoginResponse{
Success: true,
}, nil
Expand Down Expand Up @@ -306,7 +306,7 @@ func decodeTransEmpResponse(c *QQClient, pkt *network.Packet) (any, error) {
if !m.Exists(0x18) || !m.Exists(0x1e) || !m.Exists(0x19) {
return nil, errors.New("wtlogin.trans_emp sub cmd 0x12 error: tlv error")
}
c.device.TgtgtKey = m[0x1e]
c.Device().TgtgtKey = m[0x1e]
return &QRCodeLoginResponse{State: QRCodeConfirmed, LoginInfo: &QRCodeLoginInfo{
tmpPwd: m[0x18],
tmpNoPicSig: m[0x19],
Expand Down
4 changes: 2 additions & 2 deletions client/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (c *QQClient) buildFaceroamRequestPacket() (uint16, []byte) {
payload, _ := proto.Marshal(&faceroam.FaceroamReqBody{
Comm: &faceroam.PlatInfo{
Implat: proto.Int64(109),
Osver: proto.String(string(c.device.Version.Release)),
Mqqver: proto.Some(c.version.SortVersionName),
Osver: proto.String(string(c.Device().Version.Release)),
Mqqver: proto.Some(c.version().SortVersionName),
},
Uin: proto.Uint64(uint64(c.Uin)),
SubCmd: proto.Uint32(1),
Expand Down
8 changes: 4 additions & 4 deletions client/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ func genForwardTemplate(resID, preview, summary string, ts int64, items []*msg.P

func (c *QQClient) getWebDeviceInfo() (i string) {
qimei := strings.ToLower(utils.RandomString(36))
i += fmt.Sprintf("i=%v&imsi=&mac=%v&m=%v&o=%v&", c.device.IMEI, utils.B2S(c.device.MacAddress), utils.B2S(c.device.Device), utils.B2S(c.device.Version.Release))
i += fmt.Sprintf("a=%v&sd=0&c64=0&sc=1&p=1080*2210&aid=%v&", c.device.Version.SDK, c.device.IMEI)
i += fmt.Sprintf("f=%v&mm=%v&cf=%v&cc=%v&", c.device.Brand, 5629 /* Total Memory*/, 1725 /* CPU Frequency */, 8 /* CPU Core Count */)
i += fmt.Sprintf("i=%v&imsi=&mac=%v&m=%v&o=%v&", c.Device().IMEI, utils.B2S(c.Device().MacAddress), utils.B2S(c.Device().Device), utils.B2S(c.Device().Version.Release))
i += fmt.Sprintf("a=%v&sd=0&c64=0&sc=1&p=1080*2210&aid=%v&", c.Device().Version.SDK, c.Device().IMEI)
i += fmt.Sprintf("f=%v&mm=%v&cf=%v&cc=%v&", c.Device().Brand, 5629 /* Total Memory*/, 1725 /* CPU Frequency */, 8 /* CPU Core Count */)
i += fmt.Sprintf("qimei=%v&qimei36=%v&", qimei, qimei)
i += "sharpP=1&n=wifi&support_xsj_live=true&client_mod=default&timezone=Asia/Shanghai&material_sdk_version=2.9.0&vh265=null&refreshrate=60"
return
Expand All @@ -322,7 +322,7 @@ func (c *QQClient) packOIDBPackage(cmd, serviceType int32, body []byte) []byte {
Command: cmd,
ServiceType: serviceType,
Bodybuffer: body,
ClientVersion: "Android " + c.version.SortVersionName,
ClientVersion: "Android " + c.version().SortVersionName,
}
r, _ := proto.Marshal(pkg)
return r
Expand Down
2 changes: 1 addition & 1 deletion client/group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *QQClient) GetGroupInfo(groupCode int64) (*GroupInfo, error) {
// OidbSvc.0x88d_0
func (c *QQClient) buildGroupInfoRequestPacket(groupCode int64) (uint16, []byte) {
body := &oidb.D88DReqBody{
AppId: proto.Uint32(c.version.AppId),
AppId: proto.Uint32(c.version().AppId),
ReqGroupInfo: []*oidb.ReqGroupInfo{
{
GroupCode: proto.Uint64(uint64(groupCode)),
Expand Down
4 changes: 2 additions & 2 deletions client/internal/network/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
// Transport is a network transport.
type Transport struct {
Sig *auth.SigInfo
Version **auth.AppVersion
Device **auth.Device
Version *auth.AppVersion
Device *auth.Device

// connection
// conn *TCPClient
Expand Down
4 changes: 2 additions & 2 deletions client/model_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *QQClient) GetModelShow(modelName string) ([]*ModelVariant, error) {
Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0,
IMei: c.device.IMEI,
IMei: c.Device().IMEI,
ShowInfo: true,
ModelShow: "",
RecoverDefault: false,
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *QQClient) SetModelShow(modelName string, modelShow string) error {
Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0,
IMei: c.device.IMEI,
IMei: c.Device().IMEI,
ShowInfo: true,
ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"),
RecoverDefault: modelShow == "",
Expand Down
4 changes: 2 additions & 2 deletions client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (c *QQClient) ConnectionQualityTest() *ConnectionQualityInfo {
}

func (c *QQClient) initServers() {
if c.device == nil {
if c.Device() == nil {
// must have device. Use c.UseDevice to set it!
panic("client device is nil")
}

sso, err := getSSOAddress(c.device)
sso, err := getSSOAddress(c.Device())
if err == nil && len(sso) > 0 {
c.servers = append(sso, c.servers...)
}
Expand Down
18 changes: 9 additions & 9 deletions client/qidian.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *QQClient) getQiDianAddressDetailList() ([]*FriendInfo, error) {
SubCmd: proto.Uint32(33),
CrmCommonHead: &cmd0x6ff.C519CRMMsgHead{
KfUin: proto.Uint64(uint64(c.QiDian.MasterUin)),
VerNo: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version.SortVersionName))),
VerNo: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version().SortVersionName))),
CrmSubCmd: proto.Uint32(33),
LaborUin: proto.Uint64(uint64(c.Uin)),
},
Expand Down Expand Up @@ -68,21 +68,21 @@ func (c *QQClient) buildLoginExtraPacket() (uint16, []byte) {
SubCmd: proto.Uint32(69),
CrmCommonHead: &cmd0x3f6.C3F6CRMMsgHead{
CrmSubCmd: proto.Uint32(69),
VerNo: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version.SortVersionName))),
VerNo: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version().SortVersionName))),
Clienttype: proto.Uint32(2),
},
SubcmdLoginProcessCompleteReqBody: &cmd0x3f6.QDUserLoginProcessCompleteReqBody{
Kfext: proto.Uint64(uint64(c.Uin)),
Pubno: proto.Some(c.version.AppId),
Buildno: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version.SortVersionName))),
Pubno: proto.Some(c.version().AppId),
Buildno: proto.Uint32(uint32(utils.ConvertSubVersionToInt(c.version().SortVersionName))),
TerminalType: proto.Uint32(2),
Status: proto.Uint32(10),
LoginTime: proto.Uint32(5),
HardwareInfo: proto.String(string(c.device.Model)),
SoftwareInfo: proto.String(string(c.device.Version.Release)),
Guid: c.device.Guid,
AppName: proto.Some(c.version.ApkId),
SubAppId: proto.Some(c.version.AppId),
HardwareInfo: proto.String(string(c.Device().Model)),
SoftwareInfo: proto.String(string(c.Device().Version.Release)),
Guid: c.Device().Guid,
AppName: proto.Some(c.version().ApkId),
SubAppId: proto.Some(c.version().AppId),
},
}
payload, _ := proto.Marshal(req)
Expand Down
2 changes: 1 addition & 1 deletion client/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *QQClient) MarkPrivateMessageReaded(uin, time int64) {
// StatSvc.GetDevLoginInfo
func (c *QQClient) buildDeviceListRequestPacket() (uint16, []byte) {
req := &jce.SvcReqGetDevLoginInfo{
Guid: c.device.Guid,
Guid: c.Device().Guid,
LoginType: 1,
AppName: "com.tencent.mobileqq",
RequireMax: 20,
Expand Down
4 changes: 2 additions & 2 deletions client/tlv_decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *QQClient) decodeT119(data, ek []byte) {
if len(decrypted) > 51+16 {
dr := binary.NewReader(decrypted)
dr.ReadBytes(51)
c.device.TgtgtKey = dr.ReadBytes(16)
c.Device().TgtgtKey = dr.ReadBytes(16)
}
}
c.Nickname = nick
Expand All @@ -131,7 +131,7 @@ func (c *QQClient) decodeT119(data, ek []byte) {

// wtlogin.exchange_emp
func (c *QQClient) decodeT119R(data []byte) {
tea := binary.NewTeaCipher(c.device.TgtgtKey)
tea := binary.NewTeaCipher(c.Device().TgtgtKey)
m, _ := tlv.NewDecoder(2, 2).DecodeRecordMap(tea.Decrypt(data)[2:])
if t120, ok := m[0x120]; ok {
c.sig.SKey = t120
Expand Down
2 changes: 1 addition & 1 deletion client/upload_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *QQClient) UploadFile(target message.Source, file *LocalFile) error {
},
ClientInfo: &exciting.ExcitingClientInfo{
ClientType: proto.Int32(2),
AppId: proto.String(fmt.Sprint(c.version.AppId)),
AppId: proto.String(fmt.Sprint(c.version().AppId)),
TerminalType: proto.Int32(2),
ClientVer: proto.String("d92615c5"),
Unknown: proto.Int32(4),
Expand Down

0 comments on commit ed15fbc

Please sign in to comment.