1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-05 03:23:50 +08:00

supported: protocol switch.

This commit is contained in:
Mrs4s 2020-09-12 00:29:11 +08:00
parent 71bc19cd42
commit 19670d854d
7 changed files with 55 additions and 25 deletions

View File

@ -37,9 +37,9 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) {
w.Write(tlv.T18(16, uint32(c.Uin))) w.Write(tlv.T18(16, uint32(c.Uin)))
w.Write(tlv.T1(uint32(c.Uin), SystemDeviceInfo.IpAddress)) 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.T116(184024956, 0x10400))
w.Write(tlv.T100()) w.Write(tlv.T100(uint32(SystemDeviceInfo.Protocol)))
w.Write(tlv.T107(0)) w.Write(tlv.T107(0))
w.Write(tlv.T142("com.tencent.mobileqq")) w.Write(tlv.T142("com.tencent.mobileqq"))
w.Write(tlv.T144( w.Write(tlv.T144(
@ -86,7 +86,7 @@ func (c *QQClient) buildLoginPacket() (uint16, []byte) {
w.Write(tlv.T521()) w.Write(tlv.T521())
w.Write(tlv.T525(tlv.T536([]byte{0x01, 0x00}))) 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{}) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{})
return seq, packet 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...)) h := md5.Sum(append(append(SystemDeviceInfo.Guid, []byte("stMNokHgxZUGhsYp")...), t402...))
w.Write(tlv.T401(h[:])) 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{}) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{})
return seq, packet 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.T104(c.t104))
w.Write(tlv.T116(150470524, 66560)) 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{}) packet := packets.BuildLoginPacket(c.Uin, 2, make([]byte, 16), sso, []byte{})
return seq, packet return seq, packet
} }
@ -166,7 +166,7 @@ func (c *QQClient) buildClientRegisterPacket() (uint16, []byte) {
Context: make(map[string]string), Context: make(map[string]string),
Status: 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) packet := packets.BuildLoginPacket(c.Uin, 1, c.sigInfo.d2Key, sso, c.sigInfo.d2)
return seq, packet return seq, packet
} }
@ -569,7 +569,7 @@ func (c *QQClient) buildImageUploadPacket(data, updKey []byte, commandId int32,
} }
return c.nextGroupDataTransSeq() return c.nextGroupDataTransSeq()
}(), }(),
Appid: 537062409, Appid: int32(SystemDeviceInfo.Protocol),
Dataflag: 4096, Dataflag: 4096,
CommandId: commandId, CommandId: commandId,
LocaleId: 2052, LocaleId: 2052,

View File

@ -1045,7 +1045,7 @@ func (c *QQClient) startHeartbeat() {
func (c *QQClient) doHeartbeat() { func (c *QQClient) doHeartbeat() {
if c.Online { if c.Online {
seq := c.nextSeq() 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{}) packet := packets.BuildLoginPacket(c.Uin, 0, []byte{}, sso, []byte{})
_, _ = c.sendAndWait(seq, packet) _, _ = c.sendAndWait(seq, packet)
time.AfterFunc(30*time.Second, c.doHeartbeat) time.AfterFunc(30*time.Second, c.doHeartbeat)

View File

@ -16,6 +16,8 @@ type (
MemberPermission int MemberPermission int
ClientProtocol int
LoginResponse struct { LoginResponse struct {
Success bool Success bool
Error LoginError Error LoginError
@ -209,6 +211,10 @@ const (
Owner MemberPermission = iota Owner MemberPermission = iota
Administrator Administrator
Member Member
AndroidPhone ClientProtocol = 537062845
AndroidPad ClientProtocol = 537062409
AndroidWatch ClientProtocol = 537061176
) )
func (g *GroupInfo) UpdateName(newName string) { func (g *GroupInfo) UpdateName(newName string) {

View File

@ -38,6 +38,7 @@ type DeviceInfo struct {
APN []byte APN []byte
Guid []byte Guid []byte
TgtgtKey []byte TgtgtKey []byte
Protocol ClientProtocol
Version *Version Version *Version
} }
@ -57,6 +58,7 @@ type DeviceInfoFile struct {
FingerPrint string `json:"finger_print"` FingerPrint string `json:"finger_print"`
BootId string `json:"boot_id"` BootId string `json:"boot_id"`
ProcVersion string `json:"proc_version"` ProcVersion string `json:"proc_version"`
Protocol int `json:"protocol"` // 0: Pad 1: Phone 2: Watch
IMEI string `json:"imei"` IMEI string `json:"imei"`
} }
@ -88,6 +90,7 @@ var SystemDeviceInfo = &DeviceInfo{
IMEI: "468356291846738", IMEI: "468356291846738",
AndroidId: []byte("MIRAI.123456.001"), AndroidId: []byte("MIRAI.123456.001"),
APN: []byte("wifi"), APN: []byte("wifi"),
Protocol: AndroidPad,
Version: &Version{ Version: &Version{
Incremental: []byte("5891938"), Incremental: []byte("5891938"),
Release: []byte("10"), Release: []byte("10"),
@ -135,6 +138,17 @@ func (info *DeviceInfo) ToJson() []byte {
BootId: string(info.BootId), BootId: string(info.BootId),
ProcVersion: string(info.ProcVersion), ProcVersion: string(info.ProcVersion),
IMEI: info.IMEI, 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) d, _ := json.Marshal(f)
return d return d
@ -157,6 +171,14 @@ func (info *DeviceInfo) ReadJson(d []byte) error {
info.ProcVersion = []byte(f.ProcVersion) info.ProcVersion = []byte(f.ProcVersion)
info.IMEI = f.IMEI info.IMEI = f.IMEI
info.AndroidId = SystemDeviceInfo.Display info.AndroidId = SystemDeviceInfo.Display
switch f.Protocol {
case 1:
info.Protocol = AndroidPhone
case 2:
info.Protocol = AndroidWatch
default:
info.Protocol = AndroidPad
}
SystemDeviceInfo.GenNewGuid() SystemDeviceInfo.GenNewGuid()
SystemDeviceInfo.GenNewTgtgtKey() SystemDeviceInfo.GenNewTgtgtKey()
return nil return nil

View File

@ -52,12 +52,12 @@ func BuildOicqRequestPacket(uin int64, commandId uint16, encrypt IEncryptMethod,
return p.Bytes() 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 := binary.NewWriter()
p.WriteIntLvPacket(4, func(writer *binary.Writer) { p.WriteIntLvPacket(4, func(writer *binary.Writer) {
writer.WriteUInt32(uint32(seq)) writer.WriteUInt32(uint32(seq))
writer.WriteUInt32(537062409) // Android pad (sub app id) writer.WriteUInt32(protocol)
writer.WriteUInt32(537062409) writer.WriteUInt32(protocol)
writer.Write([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}) writer.Write([]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00})
if len(extData) == 0 || len(extData) == 4 { if len(extData) == 0 || len(extData) == 4 {
writer.WriteUInt32(0x04) writer.WriteUInt32(0x04)

View File

@ -1,15 +1,17 @@
package tlv 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) { return binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(0x100) w.WriteUInt16(0x100)
w.WriteTlv(binary.NewWriterF(func(w *binary.Writer) { w.WriteTlv(binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(1) w.WriteUInt16(1)
w.WriteUInt32(5) w.WriteUInt32(5)
w.WriteUInt32(16) w.WriteUInt32(16)
w.WriteUInt32(537062409) // Sub app id w.WriteUInt32(protocol)
w.WriteUInt32(0) // App client version w.WriteUInt32(0) // App client version
w.WriteUInt32(34869472) w.WriteUInt32(34869472)
})) }))

View File

@ -8,7 +8,7 @@ import (
"time" "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) { return binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(0x106) w.WriteUInt16(0x106)
body := binary.NewWriterF(func(w *binary.Writer) { body := binary.NewWriterF(func(w *binary.Writer) {
@ -36,7 +36,7 @@ func T106(uin, salt uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtg
} else { } else {
w.Write(guid) w.Write(guid)
} }
w.WriteUInt32(537062409) // sub app id (android pad) w.WriteUInt32(protocol)
w.WriteUInt32(1) // password login w.WriteUInt32(1) // password login
b := make([]byte, 8) b := make([]byte, 8)
binary2.BigEndian.PutUint64(b, uint64(uin)) binary2.BigEndian.PutUint64(b, uint64(uin))