From 2289b05764c095e1f5f136b79262661e32ef0898 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Wed, 8 Jul 2020 13:17:41 +0800 Subject: [PATCH] supported device lock login. --- client/builders.go | 21 +++++++++++++++++---- client/decoders.go | 13 ++++++++----- client/entities.go | 7 ++++++- protocol/tlv/t401.go | 10 ++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 protocol/tlv/t401.go diff --git a/client/builders.go b/client/builders.go index 612317a1..38eeadc5 100644 --- a/client/builders.go +++ b/client/builders.go @@ -78,6 +78,23 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { return seq, packet } +func (c *QQClient) buildDeviceLockLoginPacket(t402 []byte) (uint16, []byte) { + seq := c.nextSeq() + req := packets.BuildOicqRequestPacket(c.Uin, 0x0810, crypto.ECDH, c.RandomKey, func(w *binary.Writer) { + w.WriteUInt16(20) + w.WriteUInt16(4) + + w.Write(tlv.T8(2052)) + w.Write(tlv.T104(c.t104)) + w.Write(tlv.T116(150470524, 66560)) + 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) + packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) + return seq, packet +} + func (c *QQClient) buildCaptchaPacket(result string, sign []byte) (uint16, []byte) { seq := c.nextSeq() req := packets.BuildOicqRequestPacket(c.Uin, 0x810, crypto.ECDH, c.RandomKey, func(w *binary.Writer) { @@ -163,10 +180,6 @@ func (c *QQClient) buildConfPushRespPacket(t int32, pktSeq int64, jceBuf []byte) return seq, packet } -func (c *QQClient) buildOnlinePushRespPacket() { - -} - func (c *QQClient) buildFriendGroupListRequestPacket(friendStartIndex, friendListCount, groupStartIndex, groupListCount int16) (uint16, []byte) { seq := c.nextSeq() d50, _ := proto.Marshal(&pb.D50ReqBody{ diff --git a/client/decoders.go b/client/decoders.go index 737a611f..de0d54c3 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -56,14 +56,17 @@ func decodeLoginResponse(c *QQClient, seq uint16, payload []byte) (interface{}, } // need captcha if t == 160 { - + return LoginResponse{ + Success: false, + Error: UnsafeDeviceError, + VerifyUrl: string(m[0x204]), + ErrorMessage: "", + }, nil } if t == 204 { - return LoginResponse{ - Success: false, - Error: DeviceLockError, - }, nil + c.t104 = m[0x104] + return c.sendAndWait(c.buildDeviceLockLoginPacket(m[0x402])) } // drive lock if t149, ok := m[0x149]; ok { diff --git a/client/entities.go b/client/entities.go index c8f11e2e..f050d95b 100644 --- a/client/entities.go +++ b/client/entities.go @@ -7,7 +7,8 @@ var ( ) type ( - LoginError int + LoginError int + LoginResponse struct { Success bool Error LoginError @@ -16,6 +17,9 @@ type ( CaptchaImage []byte CaptchaSign []byte + // Unsafe device + VerifyUrl string + // other error ErrorMessage string } @@ -91,5 +95,6 @@ const ( NeedCaptcha LoginError = 1 DeviceLockError = 2 OtherLoginError = 3 + UnsafeDeviceError = 4 UnknownLoginError = -1 ) diff --git a/protocol/tlv/t401.go b/protocol/tlv/t401.go new file mode 100644 index 00000000..27ad8eb0 --- /dev/null +++ b/protocol/tlv/t401.go @@ -0,0 +1,10 @@ +package tlv + +import "github.com/Mrs4s/MiraiGo/binary" + +func T401(d []byte) []byte { + return binary.NewWriterF(func(w *binary.Writer) { + w.WriteUInt16(0x401) + w.WriteTlv(d) + }) +}