From d6a47cb6c0ca38bf69760db743160928507c41d4 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Sat, 17 Jul 2021 22:24:53 +0800 Subject: [PATCH] feat: customize the device by client. --- client/builders.go | 200 ++++++++++++++++++++--------------------- client/client.go | 29 +++--- client/decoders.go | 6 +- client/face.go | 2 +- client/global.go | 19 ++-- client/model_show.go | 4 +- client/qidian.go | 6 +- client/sync.go | 2 +- client/tlv_decoders.go | 4 +- 9 files changed, 139 insertions(+), 133 deletions(-) diff --git a/client/builders.go b/client/builders.go index fc43433d..8d6f700d 100644 --- a/client/builders.go +++ b/client/builders.go @@ -40,27 +40,27 @@ 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.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, SystemDeviceInfo.Guid, SystemDeviceInfo.TgtgtKey, 0)) + w.Write(tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress)) + w.Write(tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.deviceInfo.Guid, c.deviceInfo.TgtgtKey, 0)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) w.Write(tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap)) w.Write(tlv.T107(0)) w.Write(tlv.T142(c.version.ApkId)) w.Write(tlv.T144( - []byte(SystemDeviceInfo.IMEI), - SystemDeviceInfo.GenDeviceInfoData(), - SystemDeviceInfo.OSType, - SystemDeviceInfo.Version.Release, - SystemDeviceInfo.SimInfo, - SystemDeviceInfo.APN, + []byte(c.deviceInfo.IMEI), + c.deviceInfo.GenDeviceInfoData(), + c.deviceInfo.OSType, + c.deviceInfo.Version.Release, + c.deviceInfo.SimInfo, + c.deviceInfo.APN, false, true, false, tlv.GuidFlag(), - SystemDeviceInfo.Model, - SystemDeviceInfo.Guid, - SystemDeviceInfo.Brand, - SystemDeviceInfo.TgtgtKey, + c.deviceInfo.Model, + c.deviceInfo.Guid, + c.deviceInfo.Brand, + c.deviceInfo.TgtgtKey, )) - w.Write(tlv.T145(SystemDeviceInfo.Guid)) + w.Write(tlv.T145(c.deviceInfo.Guid)) w.Write(tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign)) /* if (miscBitMap & 0x80) != 0{ @@ -68,7 +68,7 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { } */ w.Write(tlv.T154(seq)) - w.Write(tlv.T141(SystemDeviceInfo.SimInfo, SystemDeviceInfo.APN)) + w.Write(tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN)) w.Write(tlv.T8(2052)) w.Write(tlv.T511([]string{ "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", @@ -76,23 +76,23 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) { "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "mma.qq.com", })) - w.Write(tlv.T187(SystemDeviceInfo.MacAddress)) - w.Write(tlv.T188(SystemDeviceInfo.AndroidId)) - if len(SystemDeviceInfo.IMSIMd5) != 0 { - w.Write(tlv.T194(SystemDeviceInfo.IMSIMd5)) + w.Write(tlv.T187(c.deviceInfo.MacAddress)) + w.Write(tlv.T188(c.deviceInfo.AndroidId)) + if len(c.deviceInfo.IMSIMd5) != 0 { + w.Write(tlv.T194(c.deviceInfo.IMSIMd5)) } if c.AllowSlider { w.Write(tlv.T191(0x82)) } - if len(SystemDeviceInfo.WifiBSSID) != 0 && len(SystemDeviceInfo.WifiSSID) != 0 { - w.Write(tlv.T202(SystemDeviceInfo.WifiBSSID, SystemDeviceInfo.WifiSSID)) + if len(c.deviceInfo.WifiBSSID) != 0 && len(c.deviceInfo.WifiSSID) != 0 { + w.Write(tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID)) } w.Write(tlv.T177(c.version.BuildTime, c.version.SdkVersion)) w.Write(tlv.T516()) w.Write(tlv.T521(0)) w.Write(tlv.T525(tlv.T536([]byte{0x01, 0x00}))) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -108,7 +108,7 @@ func (c *QQClient) buildDeviceLockLoginPacket() (uint16, []byte) { w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) w.Write(tlv.T401(c.g)) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -127,15 +127,15 @@ func (c *QQClient) buildQRCodeFetchRequestPacket() (uint16, []byte) { w.WriteBytesShort(EmptyBytes) w.WriteUInt16(6) - w.Write(tlv.T16(watch.SSOVersion, 16, watch.AppId, SystemDeviceInfo.Guid, []byte(watch.ApkId), []byte(watch.SortVersionName), watch.ApkSign)) + w.Write(tlv.T16(watch.SSOVersion, 16, watch.AppId, c.deviceInfo.Guid, []byte(watch.ApkId), []byte(watch.SortVersionName), watch.ApkSign)) w.Write(tlv.T1B(0, 0, 3, 4, 72, 2, 2)) w.Write(tlv.T1D(watch.MiscBitmap)) - w.Write(tlv.T1F(false, SystemDeviceInfo.OSType, []byte("7.1.2"), []byte("China Mobile GSM"), SystemDeviceInfo.APN, 2)) - w.Write(tlv.T33(SystemDeviceInfo.Guid)) + w.Write(tlv.T1F(false, c.deviceInfo.OSType, []byte("7.1.2"), []byte("China Mobile GSM"), c.deviceInfo.APN, 2)) + w.Write(tlv.T33(c.deviceInfo.Guid)) w.Write(tlv.T35(8)) })) }) - sso := packets.BuildSsoPacket(seq, watch.AppId, c.version.SubAppId, "wtlogin.trans_emp", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, watch.AppId, c.version.SubAppId, "wtlogin.trans_emp", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(0, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -158,7 +158,7 @@ func (c *QQClient) buildQRCodeResultQueryRequestPacket(sig []byte) (uint16, []by w.WriteUInt16(0) // const })) }) - sso := packets.BuildSsoPacket(seq, watch.AppId, c.version.SubAppId, "wtlogin.trans_emp", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, watch.AppId, c.version.SubAppId, "wtlogin.trans_emp", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(0, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -170,52 +170,52 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by w.WriteUInt16(24) w.Write(tlv.T18(16, uint32(c.Uin))) - w.Write(tlv.T1(uint32(c.Uin), SystemDeviceInfo.IpAddress)) + w.Write(tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress)) w.Write(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x106) w.WriteBytesShort(t106) })) - // w.Write(tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, SystemDeviceInfo.Guid, SystemDeviceInfo.TgtgtKey, 0)) + // w.Write(tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.deviceInfo.Guid, c.deviceInfo.TgtgtKey, 0)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) w.Write(tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap)) w.Write(tlv.T107(0)) w.Write(tlv.T142(c.version.ApkId)) w.Write(tlv.T144( - []byte(SystemDeviceInfo.IMEI), - SystemDeviceInfo.GenDeviceInfoData(), - SystemDeviceInfo.OSType, - SystemDeviceInfo.Version.Release, - SystemDeviceInfo.SimInfo, - SystemDeviceInfo.APN, + []byte(c.deviceInfo.IMEI), + c.deviceInfo.GenDeviceInfoData(), + c.deviceInfo.OSType, + c.deviceInfo.Version.Release, + c.deviceInfo.SimInfo, + c.deviceInfo.APN, false, true, false, tlv.GuidFlag(), - SystemDeviceInfo.Model, - SystemDeviceInfo.Guid, - SystemDeviceInfo.Brand, - SystemDeviceInfo.TgtgtKey, + c.deviceInfo.Model, + c.deviceInfo.Guid, + c.deviceInfo.Brand, + c.deviceInfo.TgtgtKey, )) - w.Write(tlv.T145(SystemDeviceInfo.Guid)) + w.Write(tlv.T145(c.deviceInfo.Guid)) w.Write(tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign)) w.Write(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x16A) w.WriteBytesShort(t16a) })) w.Write(tlv.T154(seq)) - w.Write(tlv.T141(SystemDeviceInfo.SimInfo, SystemDeviceInfo.APN)) + w.Write(tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN)) w.Write(tlv.T8(2052)) w.Write(tlv.T511([]string{ "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "qzone.qq.com", "vip.qq.com", "gamecenter.qq.com", "qun.qq.com", "game.qq.com", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "mma.qq.com", })) - w.Write(tlv.T187(SystemDeviceInfo.MacAddress)) - w.Write(tlv.T188(SystemDeviceInfo.AndroidId)) - if len(SystemDeviceInfo.IMSIMd5) != 0 { - w.Write(tlv.T194(SystemDeviceInfo.IMSIMd5)) + w.Write(tlv.T187(c.deviceInfo.MacAddress)) + w.Write(tlv.T188(c.deviceInfo.AndroidId)) + if len(c.deviceInfo.IMSIMd5) != 0 { + w.Write(tlv.T194(c.deviceInfo.IMSIMd5)) } w.Write(tlv.T191(0x00)) - if len(SystemDeviceInfo.WifiBSSID) != 0 && len(SystemDeviceInfo.WifiSSID) != 0 { - w.Write(tlv.T202(SystemDeviceInfo.WifiBSSID, SystemDeviceInfo.WifiSSID)) + if len(c.deviceInfo.WifiBSSID) != 0 && len(c.deviceInfo.WifiSSID) != 0 { + w.Write(tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID)) } w.Write(tlv.T177(c.version.BuildTime, c.version.SdkVersion)) w.Write(tlv.T516()) @@ -226,7 +226,7 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by w.WriteBytesShort(t318) })) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -242,7 +242,7 @@ func (c *QQClient) buildCaptchaPacket(result string, sign []byte) (uint16, []byt w.Write(tlv.T104(c.t104)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -260,7 +260,7 @@ func (c *QQClient) buildSMSRequestPacket() (uint16, []byte) { w.Write(tlv.T17A(9)) w.Write(tlv.T197()) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -279,7 +279,7 @@ func (c *QQClient) buildSMSCodeSubmitPacket(code string) (uint16, []byte) { w.Write(tlv.T401(c.g)) w.Write(tlv.T198()) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -295,7 +295,7 @@ func (c *QQClient) buildTicketSubmitPacket(ticket string) (uint16, []byte) { w.Write(tlv.T104(c.t104)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.login", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -307,7 +307,7 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) { w.WriteUInt16(24) w.Write(tlv.T18(16, uint32(c.Uin))) - w.Write(tlv.T1(uint32(c.Uin), SystemDeviceInfo.IpAddress)) + w.Write(tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress)) w.Write(binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x106) w.WriteBytesShort(c.sigInfo.encryptedA1) @@ -316,23 +316,23 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) { w.Write(tlv.T100(c.version.SSOVersion, 2, c.version.MainSigMap)) w.Write(tlv.T107(0)) w.Write(tlv.T144( - SystemDeviceInfo.AndroidId, - SystemDeviceInfo.GenDeviceInfoData(), - SystemDeviceInfo.OSType, - SystemDeviceInfo.Version.Release, - SystemDeviceInfo.SimInfo, - SystemDeviceInfo.APN, + c.deviceInfo.AndroidId, + c.deviceInfo.GenDeviceInfoData(), + c.deviceInfo.OSType, + c.deviceInfo.Version.Release, + c.deviceInfo.SimInfo, + c.deviceInfo.APN, false, true, false, tlv.GuidFlag(), - SystemDeviceInfo.Model, - SystemDeviceInfo.Guid, - SystemDeviceInfo.Brand, - SystemDeviceInfo.TgtgtKey, + c.deviceInfo.Model, + c.deviceInfo.Guid, + c.deviceInfo.Brand, + c.deviceInfo.TgtgtKey, )) w.Write(tlv.T142(c.version.ApkId)) - w.Write(tlv.T145(SystemDeviceInfo.Guid)) + w.Write(tlv.T145(c.deviceInfo.Guid)) w.Write(tlv.T16A(c.sigInfo.srmToken)) w.Write(tlv.T154(seq)) - w.Write(tlv.T141(SystemDeviceInfo.SimInfo, SystemDeviceInfo.APN)) + w.Write(tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN)) w.Write(tlv.T8(2052)) w.Write(tlv.T511([]string{ "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", @@ -341,11 +341,11 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) { })) w.Write(tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign)) w.Write(tlv.T177(c.version.BuildTime, c.version.SdkVersion)) - w.Write(tlv.T400(c.g, c.Uin, SystemDeviceInfo.Guid, c.dpwd, 1, 16, c.randSeed)) - w.Write(tlv.T187(SystemDeviceInfo.MacAddress)) - w.Write(tlv.T188(SystemDeviceInfo.AndroidId)) - w.Write(tlv.T194(SystemDeviceInfo.IMSIMd5)) - w.Write(tlv.T202(SystemDeviceInfo.WifiBSSID, SystemDeviceInfo.WifiSSID)) + w.Write(tlv.T400(c.g, c.Uin, c.deviceInfo.Guid, c.dpwd, 1, 16, c.randSeed)) + w.Write(tlv.T187(c.deviceInfo.MacAddress)) + w.Write(tlv.T188(c.deviceInfo.AndroidId)) + w.Write(tlv.T194(c.deviceInfo.IMSIMd5)) + w.Write(tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID)) w.Write(tlv.T516()) w.Write(tlv.T521(0)) w.Write(tlv.T525(tlv.T536([]byte{0x01, 0x00}))) @@ -363,40 +363,40 @@ func (c *QQClient) buildRequestChangeSigPacket() (uint16, []byte) { w.Write(tlv.T100(c.version.SSOVersion, 100, c.version.MainSigMap)) w.Write(tlv.T10A(c.sigInfo.tgt)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) - w.Write(tlv.T108(SystemDeviceInfo.IMEI)) + w.Write(tlv.T108(c.deviceInfo.IMEI)) h := md5.Sum(c.sigInfo.d2Key) w.Write(tlv.T144( - SystemDeviceInfo.AndroidId, - SystemDeviceInfo.GenDeviceInfoData(), - SystemDeviceInfo.OSType, - SystemDeviceInfo.Version.Release, - SystemDeviceInfo.SimInfo, - SystemDeviceInfo.APN, + c.deviceInfo.AndroidId, + c.deviceInfo.GenDeviceInfoData(), + c.deviceInfo.OSType, + c.deviceInfo.Version.Release, + c.deviceInfo.SimInfo, + c.deviceInfo.APN, false, true, false, tlv.GuidFlag(), - SystemDeviceInfo.Model, - SystemDeviceInfo.Guid, - SystemDeviceInfo.Brand, + c.deviceInfo.Model, + c.deviceInfo.Guid, + c.deviceInfo.Brand, h[:], )) w.Write(tlv.T143(c.sigInfo.d2)) w.Write(tlv.T142(c.version.ApkId)) w.Write(tlv.T154(seq)) w.Write(tlv.T18(16, uint32(c.Uin))) - w.Write(tlv.T141(SystemDeviceInfo.SimInfo, SystemDeviceInfo.APN)) + w.Write(tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN)) w.Write(tlv.T8(2052)) w.Write(tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign)) w.Write(tlv.T177(c.version.BuildTime, c.version.SdkVersion)) - w.Write(tlv.T187(SystemDeviceInfo.MacAddress)) - w.Write(tlv.T188(SystemDeviceInfo.AndroidId)) - w.Write(tlv.T194(SystemDeviceInfo.IMSIMd5)) + w.Write(tlv.T187(c.deviceInfo.MacAddress)) + w.Write(tlv.T188(c.deviceInfo.AndroidId)) + w.Write(tlv.T194(c.deviceInfo.IMSIMd5)) w.Write(tlv.T511([]string{ "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "qzone.qq.com", "vip.qq.com", "qun.qq.com", "game.qq.com", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "qzone.com", "mma.qq.com", })) - // w.Write(tlv.T202(SystemDeviceInfo.WifiBSSID, SystemDeviceInfo.WifiSSID)) + // w.Write(tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID)) }) - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.exchange_emp", SystemDeviceInfo.IMEI, c.sigInfo.tgt, c.OutGoingPacketSessionId, req, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "wtlogin.exchange_emp", c.deviceInfo.IMEI, c.sigInfo.tgt, c.OutGoingPacketSessionId, req, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{}) return seq, packet } @@ -411,23 +411,23 @@ func (c *QQClient) buildClientRegisterPacket() (uint16, []byte) { Status: 11, KickPC: 0, KickWeak: 0, - IOSVersion: int64(SystemDeviceInfo.Version.Sdk), + IOSVersion: int64(c.deviceInfo.Version.Sdk), NetType: 1, RegType: 0, - Guid: SystemDeviceInfo.Guid, + Guid: c.deviceInfo.Guid, IsSetStatus: 0, LocaleId: 2052, - DevName: string(SystemDeviceInfo.Model), - DevType: string(SystemDeviceInfo.Model), - OSVer: string(SystemDeviceInfo.Version.Release), + DevName: string(c.deviceInfo.Model), + DevType: string(c.deviceInfo.Model), + OSVer: string(c.deviceInfo.Version.Release), OpenPush: 1, LargeSeq: 1551, OldSSOIp: 0, NewSSOIp: 31806887127679168, ChannelNo: "", CPID: 0, - VendorName: string(SystemDeviceInfo.VendorName), - VendorOSName: string(SystemDeviceInfo.VendorOSName), + VendorName: string(c.deviceInfo.VendorName), + VendorOSName: string(c.deviceInfo.VendorOSName), B769: []byte{0x0A, 0x04, 0x08, 0x2E, 0x10, 0x00, 0x0A, 0x05, 0x08, 0x9B, 0x02, 0x10, 0x00}, SetMute: 0, } @@ -444,7 +444,7 @@ func (c *QQClient) buildClientRegisterPacket() (uint16, []byte) { Context: make(map[string]string), Status: make(map[string]string), } - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "StatSvc.register", SystemDeviceInfo.IMEI, c.sigInfo.tgt, c.OutGoingPacketSessionId, pkt.ToBytes(), c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "StatSvc.register", c.deviceInfo.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 } @@ -459,15 +459,15 @@ func (c *QQClient) buildStatusSetPacket(status, extStatus int32) (uint16, []byte KickPC: 0, KickWeak: 0, Timestamp: time.Now().Unix(), - IOSVersion: int64(SystemDeviceInfo.Version.Sdk), + IOSVersion: int64(c.deviceInfo.Version.Sdk), NetType: 1, RegType: 0, - Guid: SystemDeviceInfo.Guid, + Guid: c.deviceInfo.Guid, IsSetStatus: 1, LocaleId: 2052, - DevName: string(SystemDeviceInfo.Model), - DevType: string(SystemDeviceInfo.Model), - OSVer: string(SystemDeviceInfo.Version.Release), + DevName: string(c.deviceInfo.Model), + DevType: string(c.deviceInfo.Model), + OSVer: string(c.deviceInfo.Version.Release), OpenPush: 1, LargeSeq: 1551, ExtOnlineStatus: int64(extStatus), @@ -1077,7 +1077,7 @@ func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) { body := &qweb.QWebReq{ Seq: 1, Qua: "V1_AND_SQ_8.4.8_1492_YYB_D", - DeviceInfo: fmt.Sprintf("i=865166025905020&imsi=460002478794049&mac=02:00:00:00:00:00&m=%v&o=7.1.2&a=25&sc=1&sd=0&p=900*1600&f=nubia&mm=3479&cf=2407&cc=4&aid=086bbf84a7d5fbb3&qimei=865166023450458&sharpP=1&n=wifi", string(SystemDeviceInfo.Model)), + DeviceInfo: fmt.Sprintf("i=865166025905020&imsi=460002478794049&mac=02:00:00:00:00:00&m=%v&o=7.1.2&a=25&sc=1&sd=0&p=900*1600&f=nubia&mm=3479&cf=2407&cc=4&aid=086bbf84a7d5fbb3&qimei=865166023450458&sharpP=1&n=wifi", string(c.deviceInfo.Model)), BusiBuff: b, TraceId: fmt.Sprintf("%v_%v_%v", c.Uin, time.Now().Format("0102150405"), rand.Int63()), } diff --git a/client/client.go b/client/client.go index dc8fe545..84d04b4e 100644 --- a/client/client.go +++ b/client/client.go @@ -59,6 +59,7 @@ type QQClient struct { currServerIndex int retryTimes int version *versionInfo + deviceInfo *DeviceInfo dpwd []byte syncCookie []byte @@ -194,14 +195,15 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient { groupSeq: int32(rand.Intn(20000)), friendSeq: 22911, highwayApplyUpSeq: 77918, - ksid: []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", SystemDeviceInfo.IMEI)), - eventHandlers: &eventHandlers{}, - msgSvcCache: utils.NewCache(time.Second * 15), - transCache: utils.NewCache(time.Second * 15), - onlinePushCache: utils.NewCache(time.Second * 15), - version: genVersionInfo(SystemDeviceInfo.Protocol), - servers: []*net.TCPAddr{}, + // ksid: []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", SystemDeviceInfo.IMEI)), + eventHandlers: &eventHandlers{}, + msgSvcCache: utils.NewCache(time.Second * 15), + transCache: utils.NewCache(time.Second * 15), + onlinePushCache: utils.NewCache(time.Second * 15), + // version: genVersionInfo(SystemDeviceInfo.Protocol), + servers: []*net.TCPAddr{}, } + cli.UseDevice(SystemDeviceInfo) sso, err := getSSOAddress() if err == nil && len(sso) > 0 { cli.servers = append(sso, cli.servers...) @@ -255,6 +257,12 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient { return cli } +func (c *QQClient) UseDevice(info *DeviceInfo) { + c.version = genVersionInfo(info.Protocol) + c.ksid = []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", info.IMEI)) + c.deviceInfo = info +} + // Login send login request func (c *QQClient) Login() (*LoginResponse, error) { if c.Online { @@ -295,7 +303,8 @@ func (c *QQClient) TokenLogin(token []byte) error { c.sigInfo.encryptedA1 = r.ReadBytesShort() c.sigInfo.wtSessionTicketKey = r.ReadBytesShort() c.OutGoingPacketSessionId = r.ReadBytesShort() - SystemDeviceInfo.TgtgtKey = r.ReadBytesShort() + // SystemDeviceInfo.TgtgtKey = r.ReadBytesShort() + c.deviceInfo.TgtgtKey = r.ReadBytesShort() } _, err = c.sendAndWait(c.buildRequestChangeSigPacket()) if err != nil { @@ -457,7 +466,7 @@ func (c *QQClient) GenToken() []byte { w.WriteBytesShort(c.sigInfo.encryptedA1) w.WriteBytesShort(c.sigInfo.wtSessionTicketKey) w.WriteBytesShort(c.OutGoingPacketSessionId) - w.WriteBytesShort(SystemDeviceInfo.TgtgtKey) + w.WriteBytesShort(c.deviceInfo.TgtgtKey) }) } @@ -1085,7 +1094,7 @@ func (c *QQClient) doHeartbeat() { for c.Online { time.Sleep(time.Second * 30) seq := c.nextSeq() - sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "Heartbeat.Alive", SystemDeviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, []byte{}, c.ksid) + sso := packets.BuildSsoPacket(seq, c.version.AppId, c.version.SubAppId, "Heartbeat.Alive", c.deviceInfo.IMEI, []byte{}, c.OutGoingPacketSessionId, []byte{}, c.ksid) packet := packets.BuildLoginPacket(c.Uin, 0, []byte{}, sso, []byte{}) _, err := c.sendAndWait(seq, packet) if errors.Is(err, utils.ErrConnectionClosed) { diff --git a/client/decoders.go b/client/decoders.go index fe06d64c..65ba2c9d 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -41,7 +41,7 @@ func decodeLoginResponse(c *QQClient, _ *incomingPacketInfo, payload []byte) (in if m.Exists(0x402) { c.dpwd = []byte(utils.RandomString(16)) c.t402 = m[0x402] - h := md5.Sum(append(append(SystemDeviceInfo.Guid, c.dpwd...), c.t402...)) + h := md5.Sum(append(append(c.deviceInfo.Guid, c.dpwd...), c.t402...)) c.g = h[:] } if t == 0 { // login success @@ -54,7 +54,7 @@ func decodeLoginResponse(c *QQClient, _ *incomingPacketInfo, payload []byte) (in if m.Exists(0x403) { c.randSeed = m[0x403] } - c.decodeT119(m[0x119], SystemDeviceInfo.TgtgtKey) + c.decodeT119(m[0x119], c.deviceInfo.TgtgtKey) return LoginResponse{ Success: true, }, nil @@ -289,7 +289,7 @@ func decodeTransEmpResponse(c *QQClient, _ *incomingPacketInfo, payload []byte) if !m.Exists(0x18) || !m.Exists(0x1e) || !m.Exists(0x19) { return nil, errors.New("wtlogin.trans_emp sub cmd 0x12 error: tlv error") } - SystemDeviceInfo.TgtgtKey = m[0x1e] + c.deviceInfo.TgtgtKey = m[0x1e] return &QRCodeLoginResponse{State: QRCodeConfirmed, LoginInfo: &QRCodeLoginInfo{ tmpPwd: m[0x18], tmpNoPicSig: m[0x19], diff --git a/client/face.go b/client/face.go index 84e0f4c3..c11ad023 100644 --- a/client/face.go +++ b/client/face.go @@ -32,7 +32,7 @@ func (c *QQClient) buildFaceroamRequestPacket() (uint16, []byte) { payload, _ := proto.Marshal(&faceroam.FaceroamReqBody{ Comm: &faceroam.PlatInfo{ Implat: proto.Int64(109), - Osver: proto.String(string(SystemDeviceInfo.Version.Release)), + Osver: proto.String(string(c.deviceInfo.Version.Release)), Mqqver: &c.version.SortVersionName, }, Uin: proto.Uint64(uint64(c.Uin)), diff --git a/client/global.go b/client/global.go index 1a2c661c..4d476ce4 100644 --- a/client/global.go +++ b/client/global.go @@ -6,16 +6,6 @@ import ( "encoding/hex" "encoding/xml" "fmt" - "math/rand" - "net" - "sort" - "strconv" - "strings" - "time" - - "github.com/pkg/errors" - "google.golang.org/protobuf/proto" - "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary/jce" devinfo "github.com/Mrs4s/MiraiGo/client/pb" @@ -23,6 +13,14 @@ import ( "github.com/Mrs4s/MiraiGo/client/pb/oidb" "github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/utils" + "github.com/pkg/errors" + "google.golang.org/protobuf/proto" + "math/rand" + "net" + "sort" + "strconv" + "strings" + "time" ) type ( @@ -126,7 +124,6 @@ type ( requestParams map[string]interface{} ) -// default var SystemDeviceInfo = &DeviceInfo{ Display: []byte("MIRAI.123456.001"), Product: []byte("mirai"), diff --git a/client/model_show.go b/client/model_show.go index 2893fa24..898cd11d 100644 --- a/client/model_show.go +++ b/client/model_show.go @@ -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: SystemDeviceInfo.IMEI, + IMei: c.deviceInfo.IMEI, ShowInfo: true, ModelShow: "", RecoverDefault: false, @@ -98,7 +98,7 @@ func (c *QQClient) SetModelShow(modelName string, modelShow string) error { Uin: c.Uin, Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"), AppType: 0, - IMei: SystemDeviceInfo.IMEI, + IMei: c.deviceInfo.IMEI, ShowInfo: true, ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"), RecoverDefault: modelShow == "", diff --git a/client/qidian.go b/client/qidian.go index be8eef54..c5d8183e 100644 --- a/client/qidian.go +++ b/client/qidian.go @@ -78,9 +78,9 @@ func (c *QQClient) buildLoginExtraPacket() (uint16, []byte) { TerminalType: proto.Uint32(2), Status: proto.Uint32(10), LoginTime: proto.Uint32(5), - HardwareInfo: proto.String(string(SystemDeviceInfo.Model)), - SoftwareInfo: proto.String(string(SystemDeviceInfo.Version.Release)), - Guid: SystemDeviceInfo.Guid, + HardwareInfo: proto.String(string(c.deviceInfo.Model)), + SoftwareInfo: proto.String(string(c.deviceInfo.Version.Release)), + Guid: c.deviceInfo.Guid, AppName: &c.version.ApkId, SubAppId: &c.version.AppId, }, diff --git a/client/sync.go b/client/sync.go index b7197a6c..02249a0e 100644 --- a/client/sync.go +++ b/client/sync.go @@ -124,7 +124,7 @@ func (c *QQClient) MarkPrivateMessageReaded(uin, time int64) { func (c *QQClient) buildDeviceListRequestPacket() (uint16, []byte) { seq := c.nextSeq() req := &jce.SvcReqGetDevLoginInfo{ - Guid: SystemDeviceInfo.Guid, + Guid: c.deviceInfo.Guid, LoginType: 1, AppName: "com.tencent.mobileqq", RequireMax: 20, diff --git a/client/tlv_decoders.go b/client/tlv_decoders.go index 70ed6500..5cb7a2df 100644 --- a/client/tlv_decoders.go +++ b/client/tlv_decoders.go @@ -110,7 +110,7 @@ func (c *QQClient) decodeT119(data, ek []byte) { if len(decrypted) > 51+16 { dr := binary.NewReader(decrypted) dr.ReadBytes(51) - SystemDeviceInfo.TgtgtKey = dr.ReadBytes(16) + c.deviceInfo.TgtgtKey = dr.ReadBytes(16) } } c.Nickname = nick @@ -120,7 +120,7 @@ func (c *QQClient) decodeT119(data, ek []byte) { // wtlogin.exchange_emp func (c *QQClient) decodeT119R(data []byte) { - tea := binary.NewTeaCipher(SystemDeviceInfo.TgtgtKey) + tea := binary.NewTeaCipher(c.deviceInfo.TgtgtKey) reader := binary.NewReader(tea.Decrypt(data)) reader.ReadBytes(2) m := reader.ReadTlvMap(2)