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

fix: sso frame head parse error

This commit is contained in:
Mrs4s 2021-12-08 13:47:42 +08:00
parent 2d17133a7b
commit 2caf71a0bb
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7

View File

@ -138,20 +138,22 @@ func ParseIncomingPacket(payload, d2key []byte) (*IncomingPacket, error) {
func parseSsoFrame(payload []byte, flag2 byte) (*IncomingPacket, error) { func parseSsoFrame(payload []byte, flag2 byte) (*IncomingPacket, error) {
reader := binary.NewReader(payload) reader := binary.NewReader(payload)
if reader.ReadInt32()-4 > int32(reader.Len()) { headLen := reader.ReadInt32()
if headLen-4 > int32(reader.Len()) {
return nil, errors.WithStack(ErrPacketDropped) return nil, errors.WithStack(ErrPacketDropped)
} }
seqID := reader.ReadInt32() head := binary.NewReader(reader.ReadBytes(int(headLen) - 4))
retCode := reader.ReadInt32() seqID := head.ReadInt32()
retCode := head.ReadInt32()
if retCode != 0 { if retCode != 0 {
if retCode == -10008 { if retCode == -10008 {
return nil, errors.WithStack(ErrSessionExpired) return nil, errors.WithStack(ErrSessionExpired)
} }
return nil, errors.New("return code unsuccessful: " + strconv.FormatInt(int64(retCode), 10)) return nil, errors.New("return code unsuccessful: " + strconv.FormatInt(int64(retCode), 10))
} }
reader.ReadBytes(int(reader.ReadInt32()) - 4) // extra data head.ReadBytes(int(head.ReadInt32()) - 4) // extra data
commandName := reader.ReadString() commandName := head.ReadString()
sessionID := reader.ReadBytes(int(reader.ReadInt32()) - 4) sessionID := head.ReadBytes(int(head.ReadInt32()) - 4)
if commandName == "Heartbeat.Alive" { if commandName == "Heartbeat.Alive" {
return &IncomingPacket{ return &IncomingPacket{
SequenceId: uint16(seqID), SequenceId: uint16(seqID),
@ -161,19 +163,14 @@ func parseSsoFrame(payload []byte, flag2 byte) (*IncomingPacket, error) {
Payload: []byte{}, Payload: []byte{},
}, nil }, nil
} }
compressedFlag := reader.ReadInt32() compressedFlag := head.ReadInt32()
bodyLen := reader.ReadInt32()
packet := func() []byte { packet := func() []byte {
if compressedFlag == 0 { if compressedFlag == 0 {
pktSize := uint64(reader.ReadInt32()) & 0xffffffff return reader.ReadBytes(int(bodyLen) - 4)
if pktSize == uint64(reader.Len()) || pktSize == uint64(reader.Len()+4) {
return reader.ReadAvailable()
} else {
return reader.ReadAvailable() // some logic
}
} }
if compressedFlag == 1 { if compressedFlag == 1 {
reader.ReadBytes(4) return binary.ZlibUncompress(reader.ReadBytes(int(bodyLen) - 4))
return binary.ZlibUncompress(reader.ReadAvailable()) // ?
} }
if compressedFlag == 8 { if compressedFlag == 8 {
return reader.ReadAvailable() return reader.ReadAvailable()
@ -191,7 +188,7 @@ func parseSsoFrame(payload []byte, flag2 byte) (*IncomingPacket, error) {
func (pkt *IncomingPacket) DecryptPayload(ecdhShareKey, random, sessionKey []byte) ([]byte, error) { func (pkt *IncomingPacket) DecryptPayload(ecdhShareKey, random, sessionKey []byte) ([]byte, error) {
reader := binary.NewReader(pkt.Payload) reader := binary.NewReader(pkt.Payload)
if reader.ReadByte() != 2 { if flag := reader.ReadByte(); flag != 2 {
return nil, ErrUnknownFlag return nil, ErrUnknownFlag
} }
reader.ReadBytes(2) reader.ReadBytes(2)