diff --git a/binary/jce/reader.go b/binary/jce/reader.go index eff8e1dc..9fd750d1 100644 --- a/binary/jce/reader.go +++ b/binary/jce/reader.go @@ -46,7 +46,6 @@ func (r *JceReader) skipHead() { l = 2 } r.off += l - return } func (r *JceReader) skip(l int) { diff --git a/binary/jce/structs.go b/binary/jce/structs.go index 65ecc6e9..1cb644e2 100644 --- a/binary/jce/structs.go +++ b/binary/jce/structs.go @@ -546,9 +546,6 @@ func (pkt *RequestPacket) ToBytes() []byte { } func (pkt *RequestPacket) ReadFrom(r *JceReader) { - pkt.SBuffer = []byte{} - pkt.Context = make(map[string]string) - pkt.Status = make(map[string]string) pkt.IVersion = r.ReadInt16(1) pkt.CPacketType = r.ReadByte(2) pkt.IMessageType = r.ReadInt32(3) @@ -596,9 +593,9 @@ func (pkt *FileStoragePushFSSvcList) ReadFrom(r *JceReader) { pkt.QZoneProxyServiceList = r.ReadFileStorageServerInfos(3) pkt.UrlEncodeServiceList = r.ReadFileStorageServerInfos(4) pkt.BigDataChannel = &BigDataChannel{} - pkt.VipEmotionList = r.ReadFileStorageServerInfos(5) - pkt.C2CPicDownList = r.ReadFileStorageServerInfos(7) r.ReadJceStruct(pkt.BigDataChannel, 5) + pkt.VipEmotionList = r.ReadFileStorageServerInfos(6) + pkt.C2CPicDownList = r.ReadFileStorageServerInfos(7) pkt.PttList = r.ReadBytes(10) } diff --git a/binary/tea.go b/binary/tea.go index a0bdff4c..455933f2 100644 --- a/binary/tea.go +++ b/binary/tea.go @@ -7,9 +7,9 @@ import ( type TEA [4]uint32 -// Uint32 returns a lock free uint32 value. -//go:linkname Uint32 runtime.fastrand -func Uint32() uint32 +// randuint32 returns a lock free uint32 value. +//go:linkname randuint32 runtime.fastrand +func randuint32() uint32 // Encrypt tea 加密 // http://bbs.chinaunix.net/thread-583468-1-1.html @@ -18,9 +18,9 @@ func (t TEA) Encrypt(src []byte) (dst []byte) { lens := len(src) fill := 10 - (lens+1)%8 dst = make([]byte, fill+lens+7) - binary.LittleEndian.PutUint32(dst, Uint32()) - binary.LittleEndian.PutUint32(dst[4:], Uint32()) - binary.LittleEndian.PutUint32(dst[8:], Uint32()) + binary.LittleEndian.PutUint32(dst, randuint32()) + binary.LittleEndian.PutUint32(dst[4:], randuint32()) + binary.LittleEndian.PutUint32(dst[8:], randuint32()) dst[0] = byte(fill-3) | 0xF8 // 存储pad长度 copy(dst[fill:], src) diff --git a/binary/writer.go b/binary/writer.go index de7d55f5..19642c81 100644 --- a/binary/writer.go +++ b/binary/writer.go @@ -19,10 +19,9 @@ func NewWriterF(f func(writer *Writer)) []byte { return b } -// OpenWriterF must call func close -func OpenWriterF(f func(writer *Writer)) (b []byte, close func()) { +// OpenWriterF must call func cl to close +func OpenWriterF(f func(*Writer)) (b []byte, cl func()) { w := SelectWriter() - w.WriteByte(0) f(w) return w.Bytes(), func() { PutWriter(w) } } @@ -80,11 +79,11 @@ func (w *Writer) EncryptAndWrite(key []byte, data []byte) { w.Write(NewTeaCipher(key).Encrypt(data)) } -func (w *Writer) WriteIntLvPacket(offset int, f func(writer *Writer)) { - data, close := OpenWriterF(f) +func (w *Writer) WriteIntLvPacket(offset int, f func(*Writer)) { + data, cl := OpenWriterF(f) w.WriteUInt32(uint32(len(data) + offset)) w.Write(data) - close() + cl() } func (w *Writer) WriteUniPacket(commandName string, sessionId, extraData, body []byte) { diff --git a/client/builders.go b/client/builders.go index a1c8b1ad..739dcfdc 100644 --- a/client/builders.go +++ b/client/builders.go @@ -169,9 +169,9 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by w.Write(tlv.T18(16, uint32(c.Uin))) w.Write(tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress)) - wb, cl := binary.OpenWriterF(func(w *binary.Writer) { - w.WriteUInt16(0x106) - w.WriteBytesShort(t106) + wb, cl := binary.OpenWriterF(func(bw *binary.Writer) { + bw.WriteUInt16(0x106) + bw.WriteBytesShort(t106) }) w.Write(wb) cl() @@ -196,9 +196,9 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by w.Write(tlv.T145(c.deviceInfo.Guid)) w.Write(tlv.T147(16, []byte(c.version.SortVersionName), c.version.ApkSign)) - wb, cl = binary.OpenWriterF(func(w *binary.Writer) { - w.WriteUInt16(0x16A) - w.WriteBytesShort(t16a) + wb, cl = binary.OpenWriterF(func(bw *binary.Writer) { + bw.WriteUInt16(0x16A) + bw.WriteBytesShort(t16a) }) w.Write(wb) cl() @@ -223,9 +223,9 @@ func (c *QQClient) buildQRCodeLoginPacket(t106, t16a, t318 []byte) (uint16, []by w.Write(tlv.T516()) w.Write(tlv.T521(8)) // w.Write(tlv.T525(tlv.T536([]byte{0x01, 0x00}))) - wb, cl = binary.OpenWriterF(func(w *binary.Writer) { - w.WriteUInt16(0x318) - w.WriteBytesShort(t318) + wb, cl = binary.OpenWriterF(func(bw *binary.Writer) { + bw.WriteUInt16(0x318) + bw.WriteBytesShort(t318) }) w.Write(wb) cl() @@ -312,9 +312,9 @@ func (c *QQClient) buildRequestTgtgtNopicsigPacket() (uint16, []byte) { w.Write(tlv.T18(16, uint32(c.Uin))) w.Write(tlv.T1(uint32(c.Uin), c.deviceInfo.IpAddress)) - wb, cl := binary.OpenWriterF(func(w *binary.Writer) { - w.WriteUInt16(0x106) - w.WriteBytesShort(c.sigInfo.encryptedA1) + wb, cl := binary.OpenWriterF(func(bw *binary.Writer) { + bw.WriteUInt16(0x106) + bw.WriteBytesShort(c.sigInfo.encryptedA1) }) w.Write(wb) cl()