From fd83d24f6794cfa72854417cdde2e56ea22a8ae6 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Sat, 18 Mar 2023 00:28:54 +0800 Subject: [PATCH] improve t544 implementation --- client/builders.go | 28 ++++++++++++++++++---------- internal/tlv/t544.go | 19 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/client/builders.go b/client/builders.go index 17f0a8d6..562d7ccd 100644 --- a/client/builders.go +++ b/client/builders.go @@ -103,16 +103,7 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { tlv.T525(tlv.T536([]byte{0x01, 0x00})), ) if wrapper.DandelionEnergy != nil { - salt := binary.NewWriterF(func(w *binary.Writer) { - // util.int64_to_buf(bArr42, 0, (int) uin2); - // util.int16_to_buf(bArr42, 4, u.guid.length); // 故意的还是不小心的 - w.Write(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt64(uint64(c.Uin)) })[:4]) - w.WriteBytesShort(c.Device().Guid) - w.WriteBytesShort([]byte(c.version().SdkVersion)) - w.WriteUInt32(9) // sub command - w.WriteUInt32(0) // 被演了 - }) - if t544 := tlv.T544Custom(uint64(c.Uin), "810_9", salt, wrapper.DandelionEnergy); t544 != nil { + if t544 := tlv.T544v2(uint64(c.Uin), "810_9", 9, c.version().SdkVersion, c.Device().Guid, wrapper.DandelionEnergy); t544 != nil { t.Append(t544) } } @@ -317,6 +308,11 @@ func (c *QQClient) buildCaptchaPacket(result string, sign []byte) (uint16, []byt if c.sig.T547 != nil { t.Append(tlv.T(0x547, c.sig.T547)) } + if wrapper.DandelionEnergy != nil { + if t544 := tlv.T544(uint64(c.Uin), "810_2", 2, c.version().SdkVersion, c.Device().Guid, wrapper.DandelionEnergy); t544 != nil { + t.Append(t544) + } + } req := c.buildOicqRequestPacket(c.Uin, 0x0810, t) r := network.Request{ Type: network.RequestTypeLogin, @@ -463,6 +459,13 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) { tlv.T525(tlv.T536([]byte{0x01, 0x00})), }, } + + if wrapper.DandelionEnergy != nil { + if t544 := tlv.T544v2(uint64(c.Uin), "810_f", 15, c.version().SdkVersion, c.Device().Guid, wrapper.DandelionEnergy); t544 != nil { + t.Append(t544) + } + } + if c.Device().QImei16 != "" { t.Append(tlv.T545([]byte(c.Device().QImei16))) } else { @@ -545,6 +548,11 @@ func (c *QQClient) buildRequestChangeSigPacket(changeD2 bool) (uint16, []byte) { }), tlv.T202(c.Device().WifiBSSID, c.Device().WifiSSID), ) + if wrapper.DandelionEnergy != nil && t.Command == 10 { + if t544 := tlv.T544v2(uint64(c.Uin), "810_a", 10, c.version().SdkVersion, c.Device().Guid, wrapper.DandelionEnergy); t544 != nil { + t.Append(t544) + } + } req := c.buildOicqRequestPacket(c.Uin, 0x0810, t) req2 := network.Request{ Type: network.RequestTypeLogin, diff --git a/internal/tlv/t544.go b/internal/tlv/t544.go index fd71f6f8..8e3e3221 100644 --- a/internal/tlv/t544.go +++ b/internal/tlv/t544.go @@ -11,14 +11,19 @@ func T544(userId uint64, moduleId string, subCmd uint32, sdkVersion string, guid w.WriteBytesShort([]byte(sdkVersion)) w.WriteUInt32(subCmd) }) - sign, err := signer(userId, moduleId, salt) - if err != nil { - return nil - } - return binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(0x544) - w.WriteBytesShort(sign) + return T544Custom(userId, moduleId, salt, signer) +} + +func T544v2(userId uint64, moduleId string, subCmd uint32, sdkVersion string, guid []byte, signer func(uint64, string, []byte) ([]byte, error)) []byte { + salt := binary.NewWriterF(func(w *binary.Writer) { + // w.Write(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt64(userId) })[:4]) + w.WriteUInt32(0) + w.WriteBytesShort(guid) + w.WriteBytesShort([]byte(sdkVersion)) + w.WriteUInt32(subCmd) + w.WriteUInt32(0) }) + return T544Custom(userId, moduleId, salt, signer) } func T544Custom(userId uint64, moduleId string, salt []byte, signer func(uint64, string, []byte) ([]byte, error)) []byte {