1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

client: don't use math/rand.Read

This function has been deprecated.
This commit is contained in:
wdvxdr 2023-02-10 21:03:21 +08:00
parent f56bcbe326
commit e9f4d33002
9 changed files with 123 additions and 125 deletions

View File

@ -33,26 +33,26 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) {
Command: 9, Command: 9,
List: [][]byte{ List: [][]byte{
tlv.T18(16, uint32(c.Uin)), tlv.T18(16, uint32(c.Uin)),
tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress), tlv.T1(uint32(c.Uin), c.device.IpAddress),
tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.deviceInfo.Guid, c.deviceInfo.TgtgtKey, 0), tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.device.Guid, c.device.TgtgtKey, 0),
tlv.T116(c.version.MiscBitmap, c.version.SubSigmap), tlv.T116(c.version.MiscBitmap, c.version.SubSigmap),
tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap), tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap),
tlv.T107(0), tlv.T107(0),
tlv.T142(c.version.ApkId), tlv.T142(c.version.ApkId),
tlv.T144( tlv.T144(
[]byte(c.deviceInfo.IMEI), []byte(c.device.IMEI),
c.deviceInfo.GenDeviceInfoData(), c.device.GenDeviceInfoData(),
c.deviceInfo.OSType, c.device.OSType,
c.deviceInfo.Version.Release, c.device.Version.Release,
c.deviceInfo.SimInfo, c.device.SimInfo,
c.deviceInfo.APN, c.device.APN,
false, true, false, tlv.GuidFlag(), false, true, false, tlv.GuidFlag(),
c.deviceInfo.Model, c.device.Model,
c.deviceInfo.Guid, c.device.Guid,
c.deviceInfo.Brand, c.device.Brand,
c.deviceInfo.TgtgtKey, c.device.TgtgtKey,
), ),
tlv.T145(c.deviceInfo.Guid), tlv.T145(c.device.Guid),
tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign), tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign),
/* /*
if (miscBitMap & 0x80) != 0{ if (miscBitMap & 0x80) != 0{
@ -60,25 +60,25 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) {
} }
*/ */
tlv.T154(seq), tlv.T154(seq),
tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN), tlv.T141(c.device.SimInfo, c.device.APN),
tlv.T8(2052), tlv.T8(2052),
tlv.T511([]string{ tlv.T511([]string{
"tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "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", "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", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "mma.qq.com",
}), }),
tlv.T187(c.deviceInfo.MacAddress), tlv.T187(c.device.MacAddress),
tlv.T188(c.deviceInfo.AndroidId), tlv.T188(c.device.AndroidId),
}, },
} }
if len(c.deviceInfo.IMSIMd5) != 0 { if len(c.device.IMSIMd5) != 0 {
t.Append(tlv.T194(c.deviceInfo.IMSIMd5)) t.Append(tlv.T194(c.device.IMSIMd5))
} }
if c.AllowSlider { if c.AllowSlider {
t.Append(tlv.T191(0x82)) t.Append(tlv.T191(0x82))
} }
if len(c.deviceInfo.WifiBSSID) != 0 && len(c.deviceInfo.WifiSSID) != 0 { if len(c.device.WifiBSSID) != 0 && len(c.device.WifiSSID) != 0 {
t.Append(tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID)) t.Append(tlv.T202(c.device.WifiBSSID, c.device.WifiSSID))
} }
t.Append( t.Append(
tlv.T177(c.version.BuildTime, c.version.SdkVersion), tlv.T177(c.version.BuildTime, c.version.SdkVersion),
@ -139,11 +139,11 @@ func (c *QQClient) buildQRCodeFetchRequestPacket(size, margin, ecLevel uint32) (
w.WriteBytesShort(EmptyBytes) w.WriteBytesShort(EmptyBytes)
w.WriteUInt16(6) w.WriteUInt16(6)
w.Write(tlv.T16(watch.SSOVersion, 16, watch.AppId, c.deviceInfo.Guid, []byte(watch.ApkId), []byte(watch.SortVersionName), watch.ApkSign)) w.Write(tlv.T16(watch.SSOVersion, 16, watch.AppId, c.device.Guid, []byte(watch.ApkId), []byte(watch.SortVersionName), watch.ApkSign))
w.Write(tlv.T1B(0, 0, size, margin, 72, ecLevel, 2)) w.Write(tlv.T1B(0, 0, size, margin, 72, ecLevel, 2))
w.Write(tlv.T1D(watch.MiscBitmap)) w.Write(tlv.T1D(watch.MiscBitmap))
w.Write(tlv.T1F(false, c.deviceInfo.OSType, []byte("7.1.2"), []byte("China Mobile GSM"), c.deviceInfo.APN, 2)) w.Write(tlv.T1F(false, c.device.OSType, []byte("7.1.2"), []byte("China Mobile GSM"), c.device.APN, 2))
w.Write(tlv.T33(c.deviceInfo.Guid)) w.Write(tlv.T33(c.device.Guid))
w.Write(tlv.T35(8)) w.Write(tlv.T35(8))
})) }))
}), }),
@ -203,42 +203,42 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by
Command: 9, Command: 9,
List: [][]byte{ List: [][]byte{
tlv.T18(16, uint32(c.Uin)), tlv.T18(16, uint32(c.Uin)),
tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress), tlv.T1(uint32(c.Uin), c.device.IpAddress),
tlv.T(0x106, t106), tlv.T(0x106, t106),
// tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.deviceInfo.Guid, c.deviceInfo.TgtgtKey, 0), // tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.device.Guid, c.device.TgtgtKey, 0),
tlv.T116(c.version.MiscBitmap, c.version.SubSigmap), tlv.T116(c.version.MiscBitmap, c.version.SubSigmap),
tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap), tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap),
tlv.T107(0), tlv.T107(0),
tlv.T142(c.version.ApkId), tlv.T142(c.version.ApkId),
tlv.T144( tlv.T144(
[]byte(c.deviceInfo.IMEI), []byte(c.device.IMEI),
c.deviceInfo.GenDeviceInfoData(), c.device.GenDeviceInfoData(),
c.deviceInfo.OSType, c.device.OSType,
c.deviceInfo.Version.Release, c.device.Version.Release,
c.deviceInfo.SimInfo, c.device.SimInfo,
c.deviceInfo.APN, c.device.APN,
false, true, false, tlv.GuidFlag(), false, true, false, tlv.GuidFlag(),
c.deviceInfo.Model, c.device.Model,
c.deviceInfo.Guid, c.device.Guid,
c.deviceInfo.Brand, c.device.Brand,
c.deviceInfo.TgtgtKey, c.device.TgtgtKey,
), ),
tlv.T145(c.deviceInfo.Guid), tlv.T145(c.device.Guid),
tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign), tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign),
tlv.T(0x16a, t16a), tlv.T(0x16a, t16a),
tlv.T154(seq), tlv.T154(seq),
tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN), tlv.T141(c.device.SimInfo, c.device.APN),
tlv.T8(2052), tlv.T8(2052),
tlv.T511([]string{ tlv.T511([]string{
"tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "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", "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", "qqweb.qq.com", "office.qq.com", "ti.qq.com", "mail.qq.com", "mma.qq.com",
}), }),
tlv.T187(c.deviceInfo.MacAddress), tlv.T187(c.device.MacAddress),
tlv.T188(c.deviceInfo.AndroidId), tlv.T188(c.device.AndroidId),
tlv.T194(c.deviceInfo.IMSIMd5), tlv.T194(c.device.IMSIMd5),
tlv.T191(0x00), tlv.T191(0x00),
tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID), tlv.T202(c.device.WifiBSSID, c.device.WifiSSID),
tlv.T177(c.version.BuildTime, c.version.SdkVersion), tlv.T177(c.version.BuildTime, c.version.SdkVersion),
tlv.T516(), tlv.T516(),
tlv.T521(8), tlv.T521(8),
@ -365,30 +365,30 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) {
Command: 15, Command: 15,
List: [][]byte{ List: [][]byte{
tlv.T18(16, uint32(c.Uin)), tlv.T18(16, uint32(c.Uin)),
tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress), tlv.T1(uint32(c.Uin), c.device.IpAddress),
tlv.T(0x106, c.sig.EncryptedA1), tlv.T(0x106, c.sig.EncryptedA1),
tlv.T116(c.version.MiscBitmap, c.version.SubSigmap), tlv.T116(c.version.MiscBitmap, c.version.SubSigmap),
tlv.T100(c.version.SSOVersion, 2, c.version.MainSigMap), tlv.T100(c.version.SSOVersion, 2, c.version.MainSigMap),
tlv.T107(0), tlv.T107(0),
tlv.T108(c.sig.Ksid), tlv.T108(c.sig.Ksid),
tlv.T144( tlv.T144(
c.deviceInfo.AndroidId, c.device.AndroidId,
c.deviceInfo.GenDeviceInfoData(), c.device.GenDeviceInfoData(),
c.deviceInfo.OSType, c.device.OSType,
c.deviceInfo.Version.Release, c.device.Version.Release,
c.deviceInfo.SimInfo, c.device.SimInfo,
c.deviceInfo.APN, c.device.APN,
false, true, false, tlv.GuidFlag(), false, true, false, tlv.GuidFlag(),
c.deviceInfo.Model, c.device.Model,
c.deviceInfo.Guid, c.device.Guid,
c.deviceInfo.Brand, c.device.Brand,
c.deviceInfo.TgtgtKey, c.device.TgtgtKey,
), ),
tlv.T142(c.version.ApkId), tlv.T142(c.version.ApkId),
tlv.T145(c.deviceInfo.Guid), tlv.T145(c.device.Guid),
tlv.T16A(c.sig.SrmToken), tlv.T16A(c.sig.SrmToken),
tlv.T154(seq), tlv.T154(seq),
tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN), tlv.T141(c.device.SimInfo, c.device.APN),
tlv.T8(2052), tlv.T8(2052),
tlv.T511([]string{ tlv.T511([]string{
"tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com",
@ -397,15 +397,15 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) {
}), }),
tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign), tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign),
tlv.T177(c.version.BuildTime, c.version.SdkVersion), tlv.T177(c.version.BuildTime, c.version.SdkVersion),
tlv.T400(c.sig.G, c.Uin, c.deviceInfo.Guid, c.sig.Dpwd, 1, 16, c.sig.RandSeed), tlv.T400(c.sig.G, c.Uin, c.device.Guid, c.sig.Dpwd, 1, 16, c.sig.RandSeed),
tlv.T187(c.deviceInfo.MacAddress), tlv.T187(c.device.MacAddress),
tlv.T188(c.deviceInfo.AndroidId), tlv.T188(c.device.AndroidId),
tlv.T194(c.deviceInfo.IMSIMd5), tlv.T194(c.device.IMSIMd5),
tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID), tlv.T202(c.device.WifiBSSID, c.device.WifiSSID),
tlv.T516(), tlv.T516(),
tlv.T521(0), tlv.T521(0),
tlv.T525(tlv.T536([]byte{0x01, 0x00})), tlv.T525(tlv.T536([]byte{0x01, 0x00})),
tlv.T545([]byte(c.deviceInfo.IMEI)), tlv.T545([]byte(c.device.IMEI)),
}, },
} }
m := oicq.Message{ m := oicq.Message{
@ -448,16 +448,16 @@ func (c *QQClient) buildRequestChangeSigPacket(changeD2 bool) (uint16, []byte) {
} }
t.Append( t.Append(
tlv.T144( tlv.T144(
c.deviceInfo.AndroidId, c.device.AndroidId,
c.deviceInfo.GenDeviceInfoData(), c.device.GenDeviceInfoData(),
c.deviceInfo.OSType, c.device.OSType,
c.deviceInfo.Version.Release, c.device.Version.Release,
c.deviceInfo.SimInfo, c.device.SimInfo,
c.deviceInfo.APN, c.device.APN,
false, true, false, tlv.GuidFlag(), false, true, false, tlv.GuidFlag(),
c.deviceInfo.Model, c.device.Model,
c.deviceInfo.Guid, c.device.Guid,
c.deviceInfo.Brand, c.device.Brand,
key, key,
), ),
tlv.T112(c.Uin), tlv.T112(c.Uin),
@ -465,25 +465,25 @@ func (c *QQClient) buildRequestChangeSigPacket(changeD2 bool) (uint16, []byte) {
if changeD2 { if changeD2 {
t.Append(tlv.T143(c.sig.D2)) t.Append(tlv.T143(c.sig.D2))
} else { } else {
t.Append(tlv.T145(c.deviceInfo.Guid)) t.Append(tlv.T145(c.device.Guid))
} }
t.Append( t.Append(
tlv.T142(c.version.ApkId), tlv.T142(c.version.ApkId),
tlv.T154(seq), tlv.T154(seq),
tlv.T18(16, uint32(c.Uin)), tlv.T18(16, uint32(c.Uin)),
tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN), tlv.T141(c.device.SimInfo, c.device.APN),
tlv.T8(2052), tlv.T8(2052),
tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign), tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign),
tlv.T177(c.version.BuildTime, c.version.SdkVersion), tlv.T177(c.version.BuildTime, c.version.SdkVersion),
tlv.T187(c.deviceInfo.MacAddress), tlv.T187(c.device.MacAddress),
tlv.T188(c.deviceInfo.AndroidId), tlv.T188(c.device.AndroidId),
tlv.T194(c.deviceInfo.IMSIMd5), tlv.T194(c.device.IMSIMd5),
tlv.T511([]string{ tlv.T511([]string{
"tenpay.com", "openmobile.qq.com", "docs.qq.com", "connect.qq.com", "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", "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", "office.qq.com", "ti.qq.com", "mail.qq.com", "qzone.com", "mma.qq.com",
}), }),
tlv.T202(c.deviceInfo.WifiBSSID, c.deviceInfo.WifiSSID), tlv.T202(c.device.WifiBSSID, c.device.WifiSSID),
) )
req := c.buildOicqRequestPacket(c.Uin, 0x0810, t) req := c.buildOicqRequestPacket(c.Uin, 0x0810, t)
req2 := network.Request{ req2 := network.Request{
@ -507,23 +507,23 @@ func (c *QQClient) buildClientRegisterPacket() (uint16, []byte) {
Status: 11, Status: 11,
KickPC: 0, KickPC: 0,
KickWeak: 0, KickWeak: 0,
IOSVersion: int64(c.deviceInfo.Version.SDK), IOSVersion: int64(c.device.Version.SDK),
NetType: 1, NetType: 1,
RegType: 0, RegType: 0,
Guid: c.deviceInfo.Guid, Guid: c.device.Guid,
IsSetStatus: 0, IsSetStatus: 0,
LocaleId: 2052, LocaleId: 2052,
DevName: string(c.deviceInfo.Model), DevName: string(c.device.Model),
DevType: string(c.deviceInfo.Model), DevType: string(c.device.Model),
OSVer: string(c.deviceInfo.Version.Release), OSVer: string(c.device.Version.Release),
OpenPush: 1, OpenPush: 1,
LargeSeq: 1551, LargeSeq: 1551,
OldSSOIp: 0, OldSSOIp: 0,
NewSSOIp: 31806887127679168, NewSSOIp: 31806887127679168,
ChannelNo: "", ChannelNo: "",
CPID: 0, CPID: 0,
VendorName: string(c.deviceInfo.VendorName), VendorName: string(c.device.VendorName),
VendorOSName: string(c.deviceInfo.VendorOSName), VendorOSName: string(c.device.VendorOSName),
B769: []byte{0x0A, 0x04, 0x08, 0x2E, 0x10, 0x00, 0x0A, 0x05, 0x08, 0x9B, 0x02, 0x10, 0x00}, B769: []byte{0x0A, 0x04, 0x08, 0x2E, 0x10, 0x00, 0x0A, 0x05, 0x08, 0x9B, 0x02, 0x10, 0x00},
SetMute: 0, SetMute: 0,
} }
@ -561,15 +561,15 @@ func (c *QQClient) buildStatusSetPacket(status, extStatus int32) (uint16, []byte
KickPC: 0, KickPC: 0,
KickWeak: 0, KickWeak: 0,
Timestamp: time.Now().Unix(), Timestamp: time.Now().Unix(),
IOSVersion: int64(c.deviceInfo.Version.SDK), IOSVersion: int64(c.device.Version.SDK),
NetType: 1, NetType: 1,
RegType: 0, RegType: 0,
Guid: c.deviceInfo.Guid, Guid: c.device.Guid,
IsSetStatus: 1, IsSetStatus: 1,
LocaleId: 2052, LocaleId: 2052,
DevName: string(c.deviceInfo.Model), DevName: string(c.device.Model),
DevType: string(c.deviceInfo.Model), DevType: string(c.device.Model),
OSVer: string(c.deviceInfo.Version.Release), OSVer: string(c.device.Version.Release),
OpenPush: 1, OpenPush: 1,
LargeSeq: 1551, LargeSeq: 1551,
ExtOnlineStatus: int64(extStatus), ExtOnlineStatus: int64(extStatus),

View File

@ -67,7 +67,7 @@ type QQClient struct {
currServerIndex int currServerIndex int
retryTimes int retryTimes int
version *auth.AppVersion version *auth.AppVersion
deviceInfo *auth.Device device *auth.Device
alive bool alive bool
// session info // session info
@ -200,13 +200,13 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
highwaySession: new(highway.Session), highwaySession: new(highway.Session),
version: new(auth.AppVersion), version: new(auth.AppVersion),
deviceInfo: new(auth.Device), device: new(auth.Device),
} }
cli.transport = &network.Transport{ cli.transport = &network.Transport{
Sig: cli.sig, Sig: cli.sig,
Version: cli.version, Version: cli.version,
Device: cli.deviceInfo, Device: cli.device,
} }
cli.oicq = oicq.NewCodec(cli.Uin) cli.oicq = oicq.NewCodec(cli.Uin)
{ // init atomic values { // init atomic values
@ -273,7 +273,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
func (c *QQClient) UseDevice(info *auth.Device) { func (c *QQClient) UseDevice(info *auth.Device) {
*c.version = *info.Protocol.Version() *c.version = *info.Protocol.Version()
*c.deviceInfo = *info *c.device = *info
c.highwaySession.AppID = int32(c.version.AppId) c.highwaySession.AppID = int32(c.version.AppId)
c.sig.Ksid = []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", info.IMEI)) c.sig.Ksid = []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", info.IMEI))
} }
@ -326,7 +326,7 @@ func (c *QQClient) TokenLogin(token []byte) error {
c.oicq.WtSessionTicketKey = r.ReadBytesShort() c.oicq.WtSessionTicketKey = r.ReadBytesShort()
c.sig.OutPacketSessionID = r.ReadBytesShort() c.sig.OutPacketSessionID = r.ReadBytesShort()
// SystemDeviceInfo.TgtgtKey = r.ReadBytesShort() // SystemDeviceInfo.TgtgtKey = r.ReadBytesShort()
c.deviceInfo.TgtgtKey = r.ReadBytesShort() c.device.TgtgtKey = r.ReadBytesShort()
} }
_, err = c.sendAndWait(c.buildRequestChangeSigPacket(true)) _, err = c.sendAndWait(c.buildRequestChangeSigPacket(true))
if err != nil { if err != nil {
@ -477,7 +477,7 @@ func (c *QQClient) GenToken() []byte {
w.WriteBytesShort(c.sig.EncryptedA1) w.WriteBytesShort(c.sig.EncryptedA1)
w.WriteBytesShort(c.oicq.WtSessionTicketKey) w.WriteBytesShort(c.oicq.WtSessionTicketKey)
w.WriteBytesShort(c.sig.OutPacketSessionID) w.WriteBytesShort(c.sig.OutPacketSessionID)
w.WriteBytesShort(c.deviceInfo.TgtgtKey) w.WriteBytesShort(c.device.TgtgtKey)
}) })
} }

View File

@ -45,7 +45,7 @@ func decodeLoginResponse(c *QQClient, _ *network.IncomingPacketInfo, payload []b
if m.Exists(0x402) { if m.Exists(0x402) {
c.sig.Dpwd = []byte(utils.RandomString(16)) c.sig.Dpwd = []byte(utils.RandomString(16))
c.sig.T402 = m[0x402] c.sig.T402 = m[0x402]
h := md5.Sum(append(append(c.deviceInfo.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[:] c.sig.G = h[:]
} }
if m.Exists(0x546) { if m.Exists(0x546) {
@ -61,7 +61,7 @@ func decodeLoginResponse(c *QQClient, _ *network.IncomingPacketInfo, payload []b
if m.Exists(0x403) { if m.Exists(0x403) {
c.sig.RandSeed = m[0x403] c.sig.RandSeed = m[0x403]
} }
c.decodeT119(m[0x119], c.deviceInfo.TgtgtKey) c.decodeT119(m[0x119], c.device.TgtgtKey)
return LoginResponse{ return LoginResponse{
Success: true, Success: true,
}, nil }, nil
@ -306,7 +306,7 @@ func decodeTransEmpResponse(c *QQClient, _ *network.IncomingPacketInfo, payload
if !m.Exists(0x18) || !m.Exists(0x1e) || !m.Exists(0x19) { if !m.Exists(0x18) || !m.Exists(0x1e) || !m.Exists(0x19) {
return nil, errors.New("wtlogin.trans_emp sub cmd 0x12 error: tlv error") return nil, errors.New("wtlogin.trans_emp sub cmd 0x12 error: tlv error")
} }
c.deviceInfo.TgtgtKey = m[0x1e] c.device.TgtgtKey = m[0x1e]
return &QRCodeLoginResponse{State: QRCodeConfirmed, LoginInfo: &QRCodeLoginInfo{ return &QRCodeLoginResponse{State: QRCodeConfirmed, LoginInfo: &QRCodeLoginInfo{
tmpPwd: m[0x18], tmpPwd: m[0x18],
tmpNoPicSig: m[0x19], tmpNoPicSig: m[0x19],

View File

@ -31,7 +31,7 @@ func (c *QQClient) buildFaceroamRequestPacket() (uint16, []byte) {
payload, _ := proto.Marshal(&faceroam.FaceroamReqBody{ payload, _ := proto.Marshal(&faceroam.FaceroamReqBody{
Comm: &faceroam.PlatInfo{ Comm: &faceroam.PlatInfo{
Implat: proto.Int64(109), Implat: proto.Int64(109),
Osver: proto.String(string(c.deviceInfo.Version.Release)), Osver: proto.String(string(c.device.Version.Release)),
Mqqver: proto.Some(c.version.SortVersionName), Mqqver: proto.Some(c.version.SortVersionName),
}, },
Uin: proto.Uint64(uint64(c.Uin)), Uin: proto.Uint64(uint64(c.Uin)),

View File

@ -2,6 +2,7 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
crand "crypto/rand"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"math/rand" "math/rand"
@ -65,9 +66,8 @@ var SystemDeviceInfo = &DeviceInfo{
var EmptyBytes = make([]byte, 0) var EmptyBytes = make([]byte, 0)
func init() { func init() {
rand.Seed(time.Now().UnixNano())
r := make([]byte, 16) r := make([]byte, 16)
rand.Read(r) crand.Read(r)
t := md5.Sum(r) t := md5.Sum(r)
SystemDeviceInfo.IMSIMd5 = t[:] SystemDeviceInfo.IMSIMd5 = t[:]
SystemDeviceInfo.GenNewGuid() SystemDeviceInfo.GenNewGuid()
@ -76,18 +76,18 @@ func init() {
func GenRandomDevice() { func GenRandomDevice() {
r := make([]byte, 16) r := make([]byte, 16)
rand.Read(r) crand.Read(r)
const numberRange = "0123456789" const numberRange = "0123456789"
SystemDeviceInfo.Display = []byte("MIRAI." + utils.RandomStringRange(6, numberRange) + ".001") SystemDeviceInfo.Display = []byte("MIRAI." + utils.RandomStringRange(6, numberRange) + ".001")
SystemDeviceInfo.FingerPrint = []byte("mamoe/mirai/mirai:10/MIRAI.200122.001/" + utils.RandomStringRange(7, numberRange) + ":user/release-keys") SystemDeviceInfo.FingerPrint = []byte("mamoe/mirai/mirai:10/MIRAI.200122.001/" + utils.RandomStringRange(7, numberRange) + ":user/release-keys")
SystemDeviceInfo.BootId = binary.GenUUID(r) SystemDeviceInfo.BootId = binary.GenUUID(r)
SystemDeviceInfo.ProcVersion = []byte("Linux version 3.0.31-" + utils.RandomString(8) + " (android-build@xxx.xxx.xxx.xxx.com)") SystemDeviceInfo.ProcVersion = []byte("Linux version 3.0.31-" + utils.RandomString(8) + " (android-build@xxx.xxx.xxx.xxx.com)")
rand.Read(r) crand.Read(r)
t := md5.Sum(r) t := md5.Sum(r)
SystemDeviceInfo.IMSIMd5 = t[:] SystemDeviceInfo.IMSIMd5 = t[:]
SystemDeviceInfo.IMEI = GenIMEI() SystemDeviceInfo.IMEI = GenIMEI()
r = make([]byte, 8) r = make([]byte, 8)
rand.Read(r) crand.Read(r)
hex.Encode(SystemDeviceInfo.AndroidId, r) hex.Encode(SystemDeviceInfo.AndroidId, r)
SystemDeviceInfo.GenNewGuid() SystemDeviceInfo.GenNewGuid()
SystemDeviceInfo.GenNewTgtgtKey() SystemDeviceInfo.GenNewTgtgtKey()
@ -97,9 +97,7 @@ func GenIMEI() string {
sum := 0 // the control sum of digits sum := 0 // the control sum of digits
var final strings.Builder var final strings.Builder
randSrc := rand.NewSource(time.Now().UnixNano()) randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
randGen := rand.New(randSrc)
for i := 0; i < 14; i++ { // generating all the base digits for i := 0; i < 14; i++ { // generating all the base digits
toAdd := randGen.Intn(10) toAdd := randGen.Intn(10)
if (i+1)%2 == 0 { // special proc for every 2nd one if (i+1)%2 == 0 { // special proc for every 2nd one
@ -109,10 +107,10 @@ func GenIMEI() string {
} }
} }
sum += toAdd sum += toAdd
final.WriteString(fmt.Sprintf("%d", toAdd)) // and even printing them here! fmt.Fprintf(&final, "%d", toAdd) // and even printing them here!
} }
ctrlDigit := (sum * 9) % 10 // calculating the control digit ctrlDigit := (sum * 9) % 10 // calculating the control digit
final.WriteString(fmt.Sprintf("%d", ctrlDigit)) fmt.Fprintf(&final, "%d", ctrlDigit)
return final.String() return final.String()
} }
@ -179,17 +177,17 @@ func qualityTest(addr string) (int64, error) {
func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage { func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage {
friend := c.FindFriend(msg.Head.FromUin.Unwrap()) friend := c.FindFriend(msg.Head.FromUin.Unwrap())
var sender *message.Sender var sender *message.Sender
if friend == nil { if friend != nil {
sender = &message.Sender{
Uin: msg.Head.FromUin.Unwrap(),
Nickname: msg.Head.FromNick.Unwrap(),
}
} else {
sender = &message.Sender{ sender = &message.Sender{
Uin: friend.Uin, Uin: friend.Uin,
Nickname: friend.Nickname, Nickname: friend.Nickname,
IsFriend: true, IsFriend: true,
} }
} else {
sender = &message.Sender{
Uin: msg.Head.FromUin.Unwrap(),
Nickname: msg.Head.FromNick.Unwrap(),
}
} }
ret := &message.PrivateMessage{ ret := &message.PrivateMessage{
Id: msg.Head.MsgSeq.Unwrap(), Id: msg.Head.MsgSeq.Unwrap(),
@ -326,9 +324,9 @@ func genLongTemplate(resID, brief string, ts int64) *message.ServiceElement {
func (c *QQClient) getWebDeviceInfo() (i string) { func (c *QQClient) getWebDeviceInfo() (i string) {
qimei := strings.ToLower(utils.RandomString(36)) qimei := strings.ToLower(utils.RandomString(36))
i += fmt.Sprintf("i=%v&imsi=&mac=%v&m=%v&o=%v&", c.deviceInfo.IMEI, utils.B2S(c.deviceInfo.MacAddress), utils.B2S(c.deviceInfo.Device), utils.B2S(c.deviceInfo.Version.Release)) 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.deviceInfo.Version.SDK, c.deviceInfo.IMEI) 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.deviceInfo.Brand, 5629 /* Total Memory*/, 1725 /* CPU Frequency */, 8 /* CPU Core Count */) 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 += 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" 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 return

View File

@ -59,7 +59,7 @@ func (c *QQClient) GetModelShow(modelName string) ([]*ModelVariant, error) {
Uin: c.Uin, Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"), Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0, AppType: 0,
IMei: c.deviceInfo.IMEI, IMei: c.device.IMEI,
ShowInfo: true, ShowInfo: true,
ModelShow: "", ModelShow: "",
RecoverDefault: false, RecoverDefault: false,
@ -96,7 +96,7 @@ func (c *QQClient) SetModelShow(modelName string, modelShow string) error {
Uin: c.Uin, Uin: c.Uin,
Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"), Model: strings.ReplaceAll(url.QueryEscape(modelName), "+", "%20"),
AppType: 0, AppType: 0,
IMei: c.deviceInfo.IMEI, IMei: c.device.IMEI,
ShowInfo: true, ShowInfo: true,
ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"), ModelShow: strings.ReplaceAll(url.QueryEscape(modelShow), "+", "%20"),
RecoverDefault: modelShow == "", RecoverDefault: modelShow == "",

View File

@ -78,9 +78,9 @@ func (c *QQClient) buildLoginExtraPacket() (uint16, []byte) {
TerminalType: proto.Uint32(2), TerminalType: proto.Uint32(2),
Status: proto.Uint32(10), Status: proto.Uint32(10),
LoginTime: proto.Uint32(5), LoginTime: proto.Uint32(5),
HardwareInfo: proto.String(string(c.deviceInfo.Model)), HardwareInfo: proto.String(string(c.device.Model)),
SoftwareInfo: proto.String(string(c.deviceInfo.Version.Release)), SoftwareInfo: proto.String(string(c.device.Version.Release)),
Guid: c.deviceInfo.Guid, Guid: c.device.Guid,
AppName: proto.Some(c.version.ApkId), AppName: proto.Some(c.version.ApkId),
SubAppId: proto.Some(c.version.AppId), SubAppId: proto.Some(c.version.AppId),
}, },

View File

@ -121,7 +121,7 @@ func (c *QQClient) MarkPrivateMessageReaded(uin, time int64) {
// StatSvc.GetDevLoginInfo // StatSvc.GetDevLoginInfo
func (c *QQClient) buildDeviceListRequestPacket() (uint16, []byte) { func (c *QQClient) buildDeviceListRequestPacket() (uint16, []byte) {
req := &jce.SvcReqGetDevLoginInfo{ req := &jce.SvcReqGetDevLoginInfo{
Guid: c.deviceInfo.Guid, Guid: c.device.Guid,
LoginType: 1, LoginType: 1,
AppName: "com.tencent.mobileqq", AppName: "com.tencent.mobileqq",
RequireMax: 20, RequireMax: 20,

View File

@ -121,7 +121,7 @@ func (c *QQClient) decodeT119(data, ek []byte) {
if len(decrypted) > 51+16 { if len(decrypted) > 51+16 {
dr := binary.NewReader(decrypted) dr := binary.NewReader(decrypted)
dr.ReadBytes(51) dr.ReadBytes(51)
c.deviceInfo.TgtgtKey = dr.ReadBytes(16) c.device.TgtgtKey = dr.ReadBytes(16)
} }
} }
c.Nickname = nick c.Nickname = nick
@ -131,7 +131,7 @@ func (c *QQClient) decodeT119(data, ek []byte) {
// wtlogin.exchange_emp // wtlogin.exchange_emp
func (c *QQClient) decodeT119R(data []byte) { func (c *QQClient) decodeT119R(data []byte) {
tea := binary.NewTeaCipher(c.deviceInfo.TgtgtKey) tea := binary.NewTeaCipher(c.device.TgtgtKey)
m, _ := tlv.NewDecoder(2, 2).DecodeRecordMap(tea.Decrypt(data)[2:]) m, _ := tlv.NewDecoder(2, 2).DecodeRecordMap(tea.Decrypt(data)[2:])
if t120, ok := m[0x120]; ok { if t120, ok := m[0x120]; ok {
c.sig.SKey = t120 c.sig.SKey = t120