diff --git a/client/builders.go b/client/builders.go index 06cc5e43..a2f83a3f 100644 --- a/client/builders.go +++ b/client/builders.go @@ -37,9 +37,9 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { w.Write(tlv.T18(16, uint32(c.Uin))) w.Write(tlv.T1(uint32(c.Uin), SystemDeviceInfo.IpAddress)) - w.Write(tlv.T106(uint32(c.Uin), 0, c.PasswordMd5, true, SystemDeviceInfo.Guid, SystemDeviceInfo.TgtgtKey)) + w.Write(tlv.T106(uint32(c.Uin), 0, uint32(SystemDeviceInfo.Protocol), c.PasswordMd5, true, SystemDeviceInfo.Guid, SystemDeviceInfo.TgtgtKey)) w.Write(tlv.T116(184024956, 0x10400)) - w.Write(tlv.T100()) + w.Write(tlv.T100(uint32(SystemDeviceInfo.Protocol))) w.Write(tlv.T107(0)) w.Write(tlv.T142("com.tencent.mobileqq")) w.Write(tlv.T144( @@ -86,7 +86,7 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { w.Write(tlv.T521()) w.Write(tlv.T525(tlv.T536([]byte{0x01, 0x00}))) }) - sso := packets.BuildSsoPacket(seq, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, uint32(SystemDeviceInfo.Protocol), "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -103,7 +103,7 @@ func (c *QQClient) buildDeviceLockLoginPacket(t402 []byte) (uint16, []byte) { h := md5.Sum(append(append(SystemDeviceInfo.Guid, []byte("stMNokHgxZUGhsYp")...), t402...)) w.Write(tlv.T401(h[:])) }) - sso := packets.BuildSsoPacket(seq, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, uint32(SystemDeviceInfo.Protocol), "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -118,7 +118,7 @@ func (c *QQClient) buildCaptchaPacket(result string, sign []byte) (uint16, []byt w.Write(tlv.T104(c.t104)) w.Write(tlv.T116(150470524, 66560)) }) - sso := packets.BuildSsoPacket(seq, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, uint32(SystemDeviceInfo.Protocol), "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -166,7 +166,7 @@ func (c *QQClient) buildClientRegisterPacket() (uint16, []byte) { Context: make(map[string]string), Status: make(map[string]string), } - sso := packets.BuildSsoPacket(seq, "StatSvc.register", SystemDeviceInfo.IMEI, c.sigInfo.tgt, c.OutGoingPacketSessionId, pkt.ToBytes(), c.ksid) + sso := packets.BuildSsoPacket(seq, uint32(SystemDeviceInfo.Protocol), "StatSvc.register", SystemDeviceInfo.IMEI, c.sigInfo.tgt, c.OutGoingPacketSessionId, pkt.ToBytes(), c.ksid) packet := packets.BuildLoginPacket(c.Uin, 1, c.sigInfo.d2Key, sso, c.sigInfo.d2) return seq, packet } @@ -569,7 +569,7 @@ func (c *QQClient) buildImageUploadPacket(data, updKey []byte, commandId int32, } return c.nextGroupDataTransSeq() }(), - Appid: 537062409, + Appid: int32(SystemDeviceInfo.Protocol), Dataflag: 4096, CommandId: commandId, LocaleId: 2052, diff --git a/client/client.go b/client/client.go index b2f72983..748db0e4 100644 --- a/client/client.go +++ b/client/client.go @@ -1045,7 +1045,7 @@ func (c *QQClient) startHeartbeat() { func (c *QQClient) doHeartbeat() { if c.Online { seq := c.nextSeq() - sso := packets.BuildSsoPacket(seq, "Heartbeat.Alive", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, []byte{}, c.ksid) + sso := packets.BuildSsoPacket(seq, uint32(SystemDeviceInfo.Protocol), "Heartbeat.Alive", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, []byte{}, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 0, []byte{}, sso, []byte{}) _, _ = c.sendAndWait(seq, packet) time.AfterFunc(30*time.Second, c.doHeartbeat) diff --git a/client/entities.go b/client/entities.go index f743dc5f..68e25218 100644 --- a/client/entities.go +++ b/client/entities.go @@ -16,6 +16,8 @@ type ( MemberPermission int + ClientProtocol int + LoginResponse struct { Success bool Error LoginError @@ -209,6 +211,10 @@ const ( Owner MemberPermission = iota Administrator Member + + AndroidPhone ClientProtocol = 537062845 + AndroidPad ClientProtocol = 537062409 + AndroidWatch ClientProtocol = 537061176 ) func (g *GroupInfo) UpdateName(newName string) { diff --git a/client/global.go b/client/global.go index 80901b29..8d58060f 100644 --- a/client/global.go +++ b/client/global.go @@ -38,6 +38,7 @@ type DeviceInfo struct { APN []byte Guid []byte TgtgtKey []byte + Protocol ClientProtocol Version *Version } @@ -57,6 +58,7 @@ type DeviceInfoFile struct { FingerPrint string `json:"finger_print"` BootId string `json:"boot_id"` ProcVersion string `json:"proc_version"` + Protocol int `json:"protocol"` // 0: Pad 1: Phone 2: Watch IMEI string `json:"imei"` } @@ -88,6 +90,7 @@ var SystemDeviceInfo = &DeviceInfo{ IMEI: "468356291846738", AndroidId: []byte("MIRAI.123456.001"), APN: []byte("wifi"), + Protocol: AndroidPad, Version: &Version{ Incremental: []byte("5891938"), Release: []byte("10"), @@ -135,6 +138,17 @@ func (info *DeviceInfo) ToJson() []byte { BootId: string(info.BootId), ProcVersion: string(info.ProcVersion), IMEI: info.IMEI, + Protocol: func() int { + switch info.Protocol { + case AndroidPad: + return 0 + case AndroidPhone: + return 1 + case AndroidWatch: + return 2 + } + return 0 + }(), } d, _ := json.Marshal(f) return d @@ -157,6 +171,14 @@ func (info *DeviceInfo) ReadJson(d []byte) error { info.ProcVersion = []byte(f.ProcVersion) info.IMEI = f.IMEI info.AndroidId = SystemDeviceInfo.Display + switch f.Protocol { + case 1: + info.Protocol = AndroidPhone + case 2: + info.Protocol = AndroidWatch + default: + info.Protocol = AndroidPad + } SystemDeviceInfo.GenNewGuid() SystemDeviceInfo.GenNewTgtgtKey() return nil @@ -274,13 +296,13 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage { } var g *message.GroupMessage g = &message.GroupMessage{ - Id: m.Head.MsgSeq, - GroupCode: group.Code, - GroupName: string(m.Head.GroupInfo.GroupName), - Sender: sender, - Time: m.Head.MsgTime, - Elements: message.ParseMessageElems(m.Body.RichText.Elems), - } + Id: m.Head.MsgSeq, + GroupCode: group.Code, + GroupName: string(m.Head.GroupInfo.GroupName), + Sender: sender, + Time: m.Head.MsgTime, + Elements: message.ParseMessageElems(m.Body.RichText.Elems), + } // pre parse for _, elem := range m.Body.RichText.Elems { // is rich long msg diff --git a/protocol/packets/global.go b/protocol/packets/global.go index 1984c3a0..fb38fbf0 100644 --- a/protocol/packets/global.go +++ b/protocol/packets/global.go @@ -52,12 +52,12 @@ func BuildOicqRequestPacket(uin int64, commandId uint16, encrypt IEncryptMethod, return p.Bytes() } -func BuildSsoPacket(seq uint16, commandName, imei string, extData, outPacketSessionId, body, ksid []byte) []byte { +func BuildSsoPacket(seq uint16, protocol uint32, commandName, imei string, extData, outPacketSessionId, body, ksid []byte) []byte { p := binary.NewWriter() p.WriteIntLvPacket(4, func(writer *binary.Writer) { writer.WriteUInt32(uint32(seq)) - writer.WriteUInt32(537062409) // Android pad (sub app id) - writer.WriteUInt32(537062409) + writer.WriteUInt32(protocol) + writer.WriteUInt32(protocol) writer.Write([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}) if len(extData) == 0 || len(extData) == 4 { writer.WriteUInt32(0x04) diff --git a/protocol/tlv/t100.go b/protocol/tlv/t100.go index a525ae8c..62091119 100644 --- a/protocol/tlv/t100.go +++ b/protocol/tlv/t100.go @@ -1,16 +1,18 @@ package tlv -import "github.com/Mrs4s/MiraiGo/binary" +import ( + "github.com/Mrs4s/MiraiGo/binary" +) -func T100() []byte { +func T100(protocol uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x100) w.WriteTlv(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(1) w.WriteUInt32(5) w.WriteUInt32(16) - w.WriteUInt32(537062409) // Sub app id - w.WriteUInt32(0) // App client version + w.WriteUInt32(protocol) + w.WriteUInt32(0) // App client version w.WriteUInt32(34869472) })) }) diff --git a/protocol/tlv/t106.go b/protocol/tlv/t106.go index 17401659..2e09ef74 100644 --- a/protocol/tlv/t106.go +++ b/protocol/tlv/t106.go @@ -8,7 +8,7 @@ import ( "time" ) -func T106(uin, salt uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtgtKey []byte) []byte { +func T106(uin, salt, protocol uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtgtKey []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x106) body := binary.NewWriterF(func(w *binary.Writer) { @@ -36,8 +36,8 @@ func T106(uin, salt uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtg } else { w.Write(guid) } - w.WriteUInt32(537062409) // sub app id (android pad) - w.WriteUInt32(1) // password login + w.WriteUInt32(protocol) + w.WriteUInt32(1) // password login b := make([]byte, 8) binary2.BigEndian.PutUint64(b, uint64(uin)) w.WriteTlv(b)