diff --git a/.gitignore b/.gitignore index f2ecd3c0f..791e850fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea vendor/ +.DS_Store \ No newline at end of file diff --git a/binary/pool.go b/binary/pool.go index 305ae7848..16fb0e808 100644 --- a/binary/pool.go +++ b/binary/pool.go @@ -26,7 +26,7 @@ func SelectWriter() *Writer { func PutWriter(w *Writer) { // See https://golang.org/issue/23199 const maxSize = 1 << 16 - if w.Cap() < maxSize { // 对于大Buffer直接丢弃 + if (*bytes.Buffer)(w).Cap() < maxSize { // 对于大Buffer直接丢弃 w.Reset() bufferPool.Put(w) } diff --git a/binary/writer.go b/binary/writer.go index 19642c819..02c626457 100644 --- a/binary/writer.go +++ b/binary/writer.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" "encoding/hex" - - "github.com/Mrs4s/MiraiGo/utils" ) // Writer 写入 @@ -15,7 +13,7 @@ func NewWriterF(f func(writer *Writer)) []byte { w := SelectWriter() f(w) b := append([]byte(nil), w.Bytes()...) - PutWriter(w) + w.put() return b } @@ -23,7 +21,40 @@ func NewWriterF(f func(writer *Writer)) []byte { func OpenWriterF(f func(*Writer)) (b []byte, cl func()) { w := SelectWriter() f(w) - return w.Bytes(), func() { PutWriter(w) } + return w.Bytes(), w.put +} + +func (w *Writer) AllocUInt16Head() (pos int) { + pos = (*bytes.Buffer)(w).Len() + (*bytes.Buffer)(w).Write([]byte{0, 0}) + return +} + +/* +func (w *Writer) WriteUInt16HeadAt(pos int) { + newdata := (*bytes.Buffer)(w).Bytes()[pos:] + binary.BigEndian.PutUint16(newdata, uint16(len(newdata))) +} +*/ + +func (w *Writer) WriteUInt16HeadUsingTotalBufferLenAt(pos int) { + binary.BigEndian.PutUint16((*bytes.Buffer)(w).Bytes()[pos:], uint16((*bytes.Buffer)(w).Len())) +} + +func (w *Writer) WriteUInt16HeadExcludeSelfAt(pos int) { + newdata := (*bytes.Buffer)(w).Bytes()[pos:] + binary.BigEndian.PutUint16(newdata, uint16(len(newdata)-2)) +} + +func (w *Writer) AllocUInt32Head() (pos int) { + pos = (*bytes.Buffer)(w).Len() + (*bytes.Buffer)(w).Write([]byte{0, 0, 0, 0}) + return +} + +func (w *Writer) WriteUInt32HeadAt(pos int) { + newdata := (*bytes.Buffer)(w).Bytes()[pos:] + binary.BigEndian.PutUint32(newdata, uint32(len(newdata))) } func (w *Writer) Write(b []byte) { @@ -35,8 +66,8 @@ func (w *Writer) WriteHex(h string) { w.Write(b) } -func (w *Writer) WriteByte(b byte) { - (*bytes.Buffer)(w).WriteByte(b) +func (w *Writer) WriteByte(b byte) error { + return (*bytes.Buffer)(w).WriteByte(b) } func (w *Writer) WriteUInt16(v uint16) { @@ -58,13 +89,13 @@ func (w *Writer) WriteUInt64(v uint64) { } func (w *Writer) WriteString(v string) { - payload := utils.S2B(v) - w.WriteUInt32(uint32(len(payload) + 4)) - w.Write(payload) + w.WriteUInt32(uint32(len(v) + 4)) + (*bytes.Buffer)(w).WriteString(v) } func (w *Writer) WriteStringShort(v string) { - w.WriteBytesShort(utils.S2B(v)) + w.WriteUInt16(uint16(len(v))) + (*bytes.Buffer)(w).WriteString(v) } func (w *Writer) WriteBool(b bool) { @@ -86,27 +117,6 @@ func (w *Writer) WriteIntLvPacket(offset int, f func(*Writer)) { cl() } -func (w *Writer) WriteUniPacket(commandName string, sessionId, extraData, body []byte) { - w1 := SelectWriter() - { // WriteIntLvPacket - w1.WriteString(commandName) - w1.WriteUInt32(8) - w1.Write(sessionId) - if len(extraData) == 0 { - w1.WriteUInt32(0x04) - } else { - w1.WriteUInt32(uint32(len(extraData) + 4)) - w1.Write(extraData) - } - } - data := w1.Bytes() - w.WriteUInt32(uint32(len(data) + 4)) - w.Write(data) - PutWriter(w1) - w.WriteUInt32(uint32(len(body) + 4)) // WriteIntLvPacket - w.Write(body) -} - func (w *Writer) WriteBytesShort(data []byte) { w.WriteUInt16(uint16(len(data))) w.Write(data) @@ -124,10 +134,6 @@ func (w *Writer) Bytes() []byte { return (*bytes.Buffer)(w).Bytes() } -func (w *Writer) Cap() int { - return (*bytes.Buffer)(w).Cap() -} - func (w *Writer) Reset() { (*bytes.Buffer)(w).Reset() } @@ -135,3 +141,7 @@ func (w *Writer) Reset() { func (w *Writer) Grow(n int) { (*bytes.Buffer)(w).Grow(n) } + +func (w *Writer) put() { + PutWriter(w) +} diff --git a/client/builders.go b/client/builders.go index 8e08165f2..b762448d2 100644 --- a/client/builders.go +++ b/client/builders.go @@ -1097,12 +1097,7 @@ func (c *QQClient) buildGroupAdminSetPacket(groupCode, member int64, flag bool) b, cl := binary.OpenWriterF(func(w *binary.Writer) { w.WriteUInt32(uint32(groupCode)) w.WriteUInt32(uint32(member)) - w.WriteByte(func() byte { - if flag { - return 1 - } - return 0 - }()) + w.WriteBool(flag) }) payload := c.packOIDBPackage(1372, 1, b) cl() diff --git a/client/internal/network/transport.go b/client/internal/network/transport.go index e5dc468c9..cf0b0317f 100644 --- a/client/internal/network/transport.go +++ b/client/internal/network/transport.go @@ -19,9 +19,7 @@ type Transport struct { // conn *TCPListener } -func (t *Transport) packBody(req *Request) []byte { - w := binary.SelectWriter() - defer binary.PutWriter(w) +func (t *Transport) packBody(req *Request, w *binary.Writer) { w.WriteIntLvPacket(4, func(writer *binary.Writer) { if req.Type == RequestTypeLogin { writer.WriteUInt32(uint32(req.SequenceID)) @@ -58,7 +56,6 @@ func (t *Transport) packBody(req *Request) []byte { }) // w.WriteUInt32(uint32(len(req.Body) + 4)) // w.Write(req.Body) - return append([]byte(nil), w.Bytes()...) } // PackPacket packs a packet. @@ -67,16 +64,10 @@ func (t *Transport) PackPacket(req *Request) []byte { if len(t.Sig.D2) == 0 { req.EncryptType = EncryptTypeEmptyKey } - body := t.packBody(req) - // encrypt body - switch req.EncryptType { - case EncryptTypeD2Key: - body = binary.NewTeaCipher(t.Sig.D2Key).Encrypt(body) - case EncryptTypeEmptyKey: - body = binary.NewTeaCipher(emptyKey).Encrypt(body) - } - head := binary.NewWriterF(func(w *binary.Writer) { + return binary.NewWriterF(func(w *binary.Writer) { + pos := w.AllocUInt32Head() + // vvv w.Write(head) vvv w.WriteUInt32(uint32(req.Type)) w.WriteByte(byte(req.EncryptType)) switch req.Type { @@ -93,14 +84,24 @@ func (t *Transport) PackPacket(req *Request) []byte { } w.WriteByte(0x00) w.WriteString(strconv.FormatInt(req.Uin, 10)) + // ^^^ w.Write(head) ^^^ + w.Write(binary.NewWriterF(func(w *binary.Writer) { + // encrypt body + switch req.EncryptType { + case EncryptTypeD2Key: + wt, cl := binary.OpenWriterF(func(w *binary.Writer) { t.packBody(req, w) }) + w.EncryptAndWrite(t.Sig.D2Key, wt) + cl() + case EncryptTypeEmptyKey: + wt, cl := binary.OpenWriterF(func(w *binary.Writer) { t.packBody(req, w) }) + w.EncryptAndWrite(emptyKey, wt) + cl() + default: + t.packBody(req, w) + } + })) + w.WriteUInt32HeadAt(pos) }) - - w := binary.SelectWriter() - defer binary.PutWriter(w) - w.WriteUInt32(uint32(len(head)+len(body)) + 4) - w.Write(head) - w.Write(body) - return append([]byte(nil), w.Bytes()...) // copy } func (t *Transport) parse(head []byte) *Request { diff --git a/client/tlv_decoders.go b/client/tlv_decoders.go index a28bd9eb5..6337abf48 100644 --- a/client/tlv_decoders.go +++ b/client/tlv_decoders.go @@ -111,7 +111,13 @@ func (c *QQClient) decodeT119(data, ek []byte) { s.PsKeyMap = psKeyMap s.Pt4TokenMap = pt4TokenMap if len(c.PasswordMd5[:]) > 0 { - key := md5.Sum(append(append(c.PasswordMd5[:], []byte{0x00, 0x00, 0x00, 0x00}...), binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt32(uint32(c.Uin)) })...)) + data, cl := binary.OpenWriterF(func(w *binary.Writer) { + w.Write(c.PasswordMd5[:]) + w.WriteUInt32(0) // []byte{0x00, 0x00, 0x00, 0x00}... + w.WriteUInt32(uint32(c.Uin)) + }) + key := md5.Sum(data) + cl() decrypted := binary.NewTeaCipher(key[:]).Decrypt(c.sig.EncryptedA1) if len(decrypted) > 51+16 { dr := binary.NewReader(decrypted) diff --git a/internal/packets/global.go b/internal/packets/global.go index cc2abf7f2..3ef09564e 100644 --- a/internal/packets/global.go +++ b/internal/packets/global.go @@ -31,9 +31,8 @@ type IncomingPacket struct { func BuildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(writer *binary.Writer)) []byte { return binary.NewWriterF(func(w *binary.Writer) { - body := binary.NewWriterF(bodyFunc) w.WriteByte(2) - w.WriteUInt16(uint16(43 + len(body) + 1)) + pos := w.AllocUInt16Head() w.WriteUInt16(cmd) w.Write(make([]byte, 21)) w.WriteByte(3) @@ -41,8 +40,9 @@ func BuildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(wr w.WriteUInt16(50) // version w.WriteUInt32(seq) w.WriteUInt64(j) - w.Write(body) + bodyFunc(w) w.WriteByte(3) + w.WriteUInt16HeadUsingTotalBufferLenAt(pos) }) } diff --git a/internal/tlv/t1.go b/internal/tlv/t1.go index 1b5ce6b0c..e2f018099 100644 --- a/internal/tlv/t1.go +++ b/internal/tlv/t1.go @@ -13,13 +13,13 @@ func T1(uin uint32, ip []byte) []byte { } return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x01) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteUInt32(rand.Uint32()) - w.WriteUInt32(uin) - w.WriteUInt32(uint32(time.Now().UnixNano() / 1e6)) - w.Write(ip) - w.WriteUInt16(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(1) + w.WriteUInt32(rand.Uint32()) + w.WriteUInt32(uin) + w.WriteUInt32(uint32(time.Now().UnixNano() / 1e6)) + w.Write(ip) + w.WriteUInt16(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t100.go b/internal/tlv/t100.go index 68b67f063..dc0693f2a 100644 --- a/internal/tlv/t100.go +++ b/internal/tlv/t100.go @@ -7,13 +7,13 @@ import ( func T100(ssoVersion, protocol, mainSigMap uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x100) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteUInt32(ssoVersion) - w.WriteUInt32(16) - w.WriteUInt32(protocol) - w.WriteUInt32(0) // App client version - w.WriteUInt32(mainSigMap) // 34869472 - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(1) + w.WriteUInt32(ssoVersion) + w.WriteUInt32(16) + w.WriteUInt32(protocol) + w.WriteUInt32(0) // App client version + w.WriteUInt32(mainSigMap) // 34869472 + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t106.go b/internal/tlv/t106.go index ccd837a4c..24090b7d2 100644 --- a/internal/tlv/t106.go +++ b/internal/tlv/t106.go @@ -2,7 +2,6 @@ package tlv import ( "crypto/md5" - binary2 "encoding/binary" "math/rand" "strconv" "time" @@ -13,7 +12,19 @@ import ( func T106(uin, salt, appId, ssoVer uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtgtKey []byte, wtf uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x106) - body := binary.NewWriterF(func(w *binary.Writer) { + pos := w.AllocUInt16Head() + keydata, kcl := binary.OpenWriterF(func(w *binary.Writer) { + w.Write(passwordMd5[:]) + w.WriteUInt32(0) // []byte{0x00, 0x00, 0x00, 0x00}... + if salt != 0 { + w.WriteUInt32(salt) + } else { + w.WriteUInt32(uin) + } + }) + key := md5.Sum(keydata) + kcl() + body, cl := binary.OpenWriterF(func(w *binary.Writer) { w.WriteUInt16(4) w.WriteUInt32(rand.Uint32()) w.WriteUInt32(ssoVer) @@ -25,33 +36,27 @@ func T106(uin, salt, appId, ssoVer uint32, passwordMd5 [16]byte, guidAvailable b w.WriteUInt64(uint64(uin)) } w.WriteUInt32(uint32(time.Now().UnixNano() / 1e6)) - w.Write([]byte{0x00, 0x00, 0x00, 0x00}) // fake ip + w.WriteUInt32(0) // fake ip w.Write([]byte{0x00, 0x00, 0x00, 0x00}) w.WriteByte(0x01) w.Write(passwordMd5[:]) w.Write(tgtgtKey) w.WriteUInt32(wtf) w.WriteBool(guidAvailable) if len(guid) == 0 { - for i := 0; i < 4; i++ { - w.WriteUInt32(rand.Uint32()) - } + w.WriteUInt32(rand.Uint32()) + w.WriteUInt32(rand.Uint32()) + w.WriteUInt32(rand.Uint32()) + w.WriteUInt32(rand.Uint32()) } else { w.Write(guid) } w.WriteUInt32(appId) w.WriteUInt32(1) // password login - w.WriteBytesShort([]byte(strconv.FormatInt(int64(uin), 10))) + w.WriteStringShort(strconv.FormatInt(int64(uin), 10)) w.WriteUInt16(0) }) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - b := make([]byte, 4) - if salt != 0 { - binary2.BigEndian.PutUint32(b, salt) - } else { - binary2.BigEndian.PutUint32(b, uin) - } - key := md5.Sum(append(append(passwordMd5[:], []byte{0x00, 0x00, 0x00, 0x00}...), b...)) - w.EncryptAndWrite(key[:], body) - })) + w.EncryptAndWrite(key[:], body) + w.WriteUInt16HeadExcludeSelfAt(pos) + cl() }) } diff --git a/internal/tlv/t107.go b/internal/tlv/t107.go index 5650b9f0f..5739c5cb6 100644 --- a/internal/tlv/t107.go +++ b/internal/tlv/t107.go @@ -5,11 +5,11 @@ import "github.com/Mrs4s/MiraiGo/binary" func T107(picType uint16) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x107) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(picType) - w.WriteByte(0x00) - w.WriteUInt16(0) - w.WriteByte(0x01) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(picType) + w.WriteByte(0x00) + w.WriteUInt16(0) + w.WriteByte(0x01) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t109.go b/internal/tlv/t109.go index ff711851b..638fad4f2 100644 --- a/internal/tlv/t109.go +++ b/internal/tlv/t109.go @@ -9,9 +9,9 @@ import ( func T109(androidId []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x109) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - h := md5.Sum(androidId) - w.Write(h[:]) - })) + pos := w.AllocUInt16Head() + h := md5.Sum(androidId) + w.Write(h[:]) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t116.go b/internal/tlv/t116.go index 7e4629f71..9b70bae2d 100644 --- a/internal/tlv/t116.go +++ b/internal/tlv/t116.go @@ -5,12 +5,12 @@ import "github.com/Mrs4s/MiraiGo/binary" func T116(miscBitmap, subSigMap uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x116) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(0x00) - w.WriteUInt32(miscBitmap) - w.WriteUInt32(subSigMap) - w.WriteByte(0x01) - w.WriteUInt32(1600000226) // app id list - })) + pos := w.AllocUInt16Head() + w.WriteByte(0x00) + w.WriteUInt32(miscBitmap) + w.WriteUInt32(subSigMap) + w.WriteByte(0x01) + w.WriteUInt32(1600000226) // app id list + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t124.go b/internal/tlv/t124.go index 7bf5479c2..21fe35f21 100644 --- a/internal/tlv/t124.go +++ b/internal/tlv/t124.go @@ -5,13 +5,13 @@ import "github.com/Mrs4s/MiraiGo/binary" func T124(osType, osVersion, simInfo, apn []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x124) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteTlvLimitedSize(osType, 16) - w.WriteTlvLimitedSize(osVersion, 16) - w.WriteUInt16(2) // Network type wifi - w.WriteTlvLimitedSize(simInfo, 16) - w.WriteTlvLimitedSize([]byte{}, 16) - w.WriteTlvLimitedSize(apn, 16) - })) + pos := w.AllocUInt16Head() + w.WriteTlvLimitedSize(osType, 16) + w.WriteTlvLimitedSize(osVersion, 16) + w.WriteUInt16(2) // Network type wifi + w.WriteTlvLimitedSize(simInfo, 16) + w.WriteTlvLimitedSize([]byte{}, 16) + w.WriteTlvLimitedSize(apn, 16) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t128.go b/internal/tlv/t128.go index 028123030..e24d023a9 100644 --- a/internal/tlv/t128.go +++ b/internal/tlv/t128.go @@ -5,15 +5,15 @@ import "github.com/Mrs4s/MiraiGo/binary" func T128(isGuidFromFileNull, isGuidAvailable, isGuidChanged bool, guidFlag uint32, buildModel, guid, buildBrand []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x128) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(0) - w.WriteBool(isGuidFromFileNull) - w.WriteBool(isGuidAvailable) - w.WriteBool(isGuidChanged) - w.WriteUInt32(guidFlag) - w.WriteTlvLimitedSize(buildModel, 32) - w.WriteTlvLimitedSize(guid, 16) - w.WriteTlvLimitedSize(buildBrand, 16) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(0) + w.WriteBool(isGuidFromFileNull) + w.WriteBool(isGuidAvailable) + w.WriteBool(isGuidChanged) + w.WriteUInt32(guidFlag) + w.WriteTlvLimitedSize(buildModel, 32) + w.WriteTlvLimitedSize(guid, 16) + w.WriteTlvLimitedSize(buildBrand, 16) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t141.go b/internal/tlv/t141.go index 677d0add2..2d45ae9ed 100644 --- a/internal/tlv/t141.go +++ b/internal/tlv/t141.go @@ -5,11 +5,11 @@ import "github.com/Mrs4s/MiraiGo/binary" func T141(simInfo, apn []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x141) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteBytesShort(simInfo) - w.WriteUInt16(2) // network type wifi - w.WriteBytesShort(apn) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(1) + w.WriteBytesShort(simInfo) + w.WriteUInt16(2) // network type wifi + w.WriteBytesShort(apn) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t142.go b/internal/tlv/t142.go index a95f273de..46752be3b 100644 --- a/internal/tlv/t142.go +++ b/internal/tlv/t142.go @@ -5,9 +5,9 @@ import "github.com/Mrs4s/MiraiGo/binary" func T142(apkId string) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x142) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(0) - w.WriteTlvLimitedSize([]byte(apkId), 32) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(0) + w.WriteTlvLimitedSize([]byte(apkId), 32) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t144.go b/internal/tlv/t144.go index 32042402c..ab014ac93 100644 --- a/internal/tlv/t144.go +++ b/internal/tlv/t144.go @@ -12,15 +12,15 @@ func T144( ) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x144) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.EncryptAndWrite(tgtgtKey, binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(5) - w.Write(T109(imei)) - w.Write(T52D(devInfo)) - w.Write(T124(osType, osVersion, simInfo, apn)) - w.Write(T128(isGuidFromFileNull, isGuidAvailable, isGuidChanged, guidFlag, buildModel, guid, buildBrand)) - w.Write(T16E(buildModel)) - })) + pos := w.AllocUInt16Head() + w.EncryptAndWrite(tgtgtKey, binary.NewWriterF(func(w *binary.Writer) { + w.WriteUInt16(5) + w.Write(T109(imei)) + w.Write(T52D(devInfo)) + w.Write(T124(osType, osVersion, simInfo, apn)) + w.Write(T128(isGuidFromFileNull, isGuidAvailable, isGuidChanged, guidFlag, buildModel, guid, buildBrand)) + w.Write(T16E(buildModel)) })) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t145.go b/internal/tlv/t145.go index fd1c0f0b5..9792953f8 100644 --- a/internal/tlv/t145.go +++ b/internal/tlv/t145.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T145(guid []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x145) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write(guid) - })) + pos := w.AllocUInt16Head() + w.Write(guid) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t147.go b/internal/tlv/t147.go index f567a4dd3..4de436baa 100644 --- a/internal/tlv/t147.go +++ b/internal/tlv/t147.go @@ -5,10 +5,10 @@ import "github.com/Mrs4s/MiraiGo/binary" func T147(appId uint32, apkVersionName, apkSignatureMd5 []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x147) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(appId) - w.WriteTlvLimitedSize(apkVersionName, 32) - w.WriteTlvLimitedSize(apkSignatureMd5, 32) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(appId) + w.WriteTlvLimitedSize(apkVersionName, 32) + w.WriteTlvLimitedSize(apkSignatureMd5, 32) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t154.go b/internal/tlv/t154.go index b0612c32b..142396704 100644 --- a/internal/tlv/t154.go +++ b/internal/tlv/t154.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T154(seq uint16) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x154) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(uint32(seq)) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(uint32(seq)) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t16.go b/internal/tlv/t16.go index c8d94fbbc..0bd5c79cf 100644 --- a/internal/tlv/t16.go +++ b/internal/tlv/t16.go @@ -5,14 +5,14 @@ import "github.com/Mrs4s/MiraiGo/binary" func T16(ssoVersion, appId, subAppId uint32, guid, apkId, apkVersionName, apkSign []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x16) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(ssoVersion) - w.WriteUInt32(appId) - w.WriteUInt32(subAppId) - w.Write(guid) - w.WriteBytesShort(apkId) - w.WriteBytesShort(apkVersionName) - w.WriteBytesShort(apkSign) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(ssoVersion) + w.WriteUInt32(appId) + w.WriteUInt32(subAppId) + w.Write(guid) + w.WriteBytesShort(apkId) + w.WriteBytesShort(apkVersionName) + w.WriteBytesShort(apkSign) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t166.go b/internal/tlv/t166.go index e64b1ddb2..d4e50f388 100644 --- a/internal/tlv/t166.go +++ b/internal/tlv/t166.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T166(imageType byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x166) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(imageType) - })) + pos := w.AllocUInt16Head() + w.WriteByte(imageType) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t16e.go b/internal/tlv/t16e.go index 4b13175e3..e0ea85895 100644 --- a/internal/tlv/t16e.go +++ b/internal/tlv/t16e.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T16E(buildModel []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x16e) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write(buildModel) - })) + pos := w.AllocUInt16Head() + w.Write(buildModel) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t177.go b/internal/tlv/t177.go index 45be3ca12..f93c72dd9 100644 --- a/internal/tlv/t177.go +++ b/internal/tlv/t177.go @@ -5,10 +5,10 @@ import "github.com/Mrs4s/MiraiGo/binary" func T177(buildTime uint32, sdkVersion string) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x177) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(0x01) - w.WriteUInt32(buildTime) - w.WriteBytesShort([]byte(sdkVersion)) - })) + pos := w.AllocUInt16Head() + w.WriteByte(0x01) + w.WriteUInt32(buildTime) + w.WriteStringShort(sdkVersion) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t17a.go b/internal/tlv/t17a.go index eb3691f01..90b60bc2a 100644 --- a/internal/tlv/t17a.go +++ b/internal/tlv/t17a.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T17A(value int32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x17a) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(uint32(value)) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(uint32(value)) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t17c.go b/internal/tlv/t17c.go index 358c11ccc..3dfd47f12 100644 --- a/internal/tlv/t17c.go +++ b/internal/tlv/t17c.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T17C(code string) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x17c) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteStringShort(code) - })) + pos := w.AllocUInt16Head() + w.WriteStringShort(code) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t18.go b/internal/tlv/t18.go index e5b6a7cc8..1b33b0304 100644 --- a/internal/tlv/t18.go +++ b/internal/tlv/t18.go @@ -5,14 +5,14 @@ import "github.com/Mrs4s/MiraiGo/binary" func T18(appId uint32, uin uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x18) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.WriteUInt32(1536) - w.WriteUInt32(appId) - w.WriteUInt32(0) - w.WriteUInt32(uin) - w.WriteUInt16(0) - w.WriteUInt16(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(1) + w.WriteUInt32(1536) + w.WriteUInt32(appId) + w.WriteUInt32(0) + w.WriteUInt32(uin) + w.WriteUInt16(0) + w.WriteUInt16(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t187.go b/internal/tlv/t187.go index 500f619e4..de65fe7fb 100644 --- a/internal/tlv/t187.go +++ b/internal/tlv/t187.go @@ -9,9 +9,9 @@ import ( func T187(macAddress []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x187) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - h := md5.Sum(macAddress) - w.Write(h[:]) - })) + pos := w.AllocUInt16Head() + h := md5.Sum(macAddress) + w.Write(h[:]) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t188.go b/internal/tlv/t188.go index 9731ca4e9..6ddb87961 100644 --- a/internal/tlv/t188.go +++ b/internal/tlv/t188.go @@ -9,9 +9,9 @@ import ( func T188(androidId []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x188) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - h := md5.Sum(androidId) - w.Write(h[:]) - })) + pos := w.AllocUInt16Head() + h := md5.Sum(androidId) + w.Write(h[:]) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t191.go b/internal/tlv/t191.go index 2b57e79b2..a96aff1dc 100644 --- a/internal/tlv/t191.go +++ b/internal/tlv/t191.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T191(k byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x191) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(k) - })) + pos := w.AllocUInt16Head() + w.WriteByte(k) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t193.go b/internal/tlv/t193.go index e81928858..96ca0bcf1 100644 --- a/internal/tlv/t193.go +++ b/internal/tlv/t193.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T193(ticket string) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x193) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write([]byte(ticket)) - })) + pos := w.AllocUInt16Head() + w.Write([]byte(ticket)) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t194.go b/internal/tlv/t194.go index 3fb4f3337..79318eaeb 100644 --- a/internal/tlv/t194.go +++ b/internal/tlv/t194.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T194(imsiMd5 []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x194) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write(imsiMd5) - })) + pos := w.AllocUInt16Head() + w.Write(imsiMd5) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t197.go b/internal/tlv/t197.go index 6af17954c..6a8b402f1 100644 --- a/internal/tlv/t197.go +++ b/internal/tlv/t197.go @@ -5,6 +5,6 @@ import "github.com/Mrs4s/MiraiGo/binary" func T197() []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x197) - w.WriteBytesShort([]byte{0}) + w.Write([]byte{0, 1, 0}) // w.WriteBytesShort([]byte{0}) }) } diff --git a/internal/tlv/t198.go b/internal/tlv/t198.go index 3317be6d5..6dcc9b48d 100644 --- a/internal/tlv/t198.go +++ b/internal/tlv/t198.go @@ -5,6 +5,6 @@ import "github.com/Mrs4s/MiraiGo/binary" func T198() []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x198) - w.WriteBytesShort([]byte{0}) + w.Write([]byte{0, 1, 0}) // w.WriteBytesShort([]byte{0}) }) } diff --git a/internal/tlv/t1b.go b/internal/tlv/t1b.go index fad8c159f..f6b30f70c 100644 --- a/internal/tlv/t1b.go +++ b/internal/tlv/t1b.go @@ -5,15 +5,15 @@ import "github.com/Mrs4s/MiraiGo/binary" func T1B(micro, version, size, margin, dpi, ecLevel, hint uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x1B) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(micro) - w.WriteUInt32(version) - w.WriteUInt32(size) - w.WriteUInt32(margin) - w.WriteUInt32(dpi) - w.WriteUInt32(ecLevel) - w.WriteUInt32(hint) - w.WriteUInt16(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(micro) + w.WriteUInt32(version) + w.WriteUInt32(size) + w.WriteUInt32(margin) + w.WriteUInt32(dpi) + w.WriteUInt32(ecLevel) + w.WriteUInt32(hint) + w.WriteUInt16(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t1d.go b/internal/tlv/t1d.go index 58996978c..099b31e52 100644 --- a/internal/tlv/t1d.go +++ b/internal/tlv/t1d.go @@ -5,12 +5,12 @@ import "github.com/Mrs4s/MiraiGo/binary" func T1D(miscBitmap uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x1D) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(1) - w.WriteUInt32(miscBitmap) - w.WriteUInt32(0) - w.WriteByte(0) - w.WriteUInt32(0) - })) + pos := w.AllocUInt16Head() + w.WriteByte(1) + w.WriteUInt32(miscBitmap) + w.WriteUInt32(0) + w.WriteByte(0) + w.WriteUInt32(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t1f.go b/internal/tlv/t1f.go index 2d7b83654..4e671d84a 100644 --- a/internal/tlv/t1f.go +++ b/internal/tlv/t1f.go @@ -5,20 +5,14 @@ import "github.com/Mrs4s/MiraiGo/binary" func T1F(isRoot bool, osName, osVersion, simOperatorName, apn []byte, networkType uint16) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x1F) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteByte(func() byte { - if isRoot { - return 1 - } else { - return 0 - } - }()) - w.WriteBytesShort(osName) - w.WriteBytesShort(osVersion) - w.WriteUInt16(networkType) - w.WriteBytesShort(simOperatorName) - w.WriteBytesShort([]byte{}) - w.WriteBytesShort(apn) - })) + pos := w.AllocUInt16Head() + w.WriteBool(isRoot) + w.WriteBytesShort(osName) + w.WriteBytesShort(osVersion) + w.WriteUInt16(networkType) + w.WriteBytesShort(simOperatorName) + w.WriteUInt16(0) // w.WriteBytesShort([]byte{}) + w.WriteBytesShort(apn) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t2.go b/internal/tlv/t2.go index 2f0656c4b..efa2037a4 100644 --- a/internal/tlv/t2.go +++ b/internal/tlv/t2.go @@ -5,10 +5,10 @@ import "github.com/Mrs4s/MiraiGo/binary" func T2(result string, sign []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x02) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(0) - w.WriteStringShort(result) - w.WriteBytesShort(sign) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(0) + w.WriteStringShort(result) + w.WriteBytesShort(sign) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t202.go b/internal/tlv/t202.go index e694547ce..ec1c4f69d 100644 --- a/internal/tlv/t202.go +++ b/internal/tlv/t202.go @@ -5,9 +5,9 @@ import "github.com/Mrs4s/MiraiGo/binary" func T202(wifiBSSID, wifiSSID []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x202) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteTlvLimitedSize(wifiBSSID, 16) - w.WriteTlvLimitedSize(wifiSSID, 32) - })) + pos := w.AllocUInt16Head() + w.WriteTlvLimitedSize(wifiBSSID, 16) + w.WriteTlvLimitedSize(wifiSSID, 32) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t35.go b/internal/tlv/t35.go index 4fc008513..9903096df 100644 --- a/internal/tlv/t35.go +++ b/internal/tlv/t35.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T35(productType uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x35) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(productType) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(productType) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t400.go b/internal/tlv/t400.go index 9a22344e6..59173f17a 100644 --- a/internal/tlv/t400.go +++ b/internal/tlv/t400.go @@ -9,17 +9,17 @@ import ( func T400(g []byte, uin int64, guid, dpwd []byte, j2, j3 int64, randSeed []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x400) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.EncryptAndWrite(g, binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) // version - w.WriteUInt64(uint64(uin)) - w.Write(guid) - w.Write(dpwd) - w.WriteUInt32(uint32(j2)) - w.WriteUInt32(uint32(j3)) - w.WriteUInt32(uint32(time.Now().Unix())) - w.Write(randSeed) - })) + pos := w.AllocUInt16Head() + w.EncryptAndWrite(g, binary.NewWriterF(func(w *binary.Writer) { + w.WriteUInt16(1) // version + w.WriteUInt64(uint64(uin)) + w.Write(guid) + w.Write(dpwd) + w.WriteUInt32(uint32(j2)) + w.WriteUInt32(uint32(j3)) + w.WriteUInt32(uint32(time.Now().Unix())) + w.Write(randSeed) })) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t511.go b/internal/tlv/t511.go index 72af0999b..43609e75e 100644 --- a/internal/tlv/t511.go +++ b/internal/tlv/t511.go @@ -1,53 +1,64 @@ package tlv import ( - "strconv" - "strings" - "github.com/Mrs4s/MiraiGo/binary" ) func T511(domains []string) []byte { - var arr2 []string - for _, d := range domains { - if d != "" { - arr2 = append(arr2, d) + nonnildomains := domains + // 目前的所有调用均无 "" + /* + hasnil := false + for _, d := range domains { + if d == "" { + hasnil = true + break + } + } + if hasnil { + nonnildomains = nonnildomains[:0] + for _, d := range domains { + if d != "" { + nonnildomains = append(nonnildomains, d) + } + } } - } + */ return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x511) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(uint16(len(arr2))) - for _, d := range arr2 { - indexOf := strings.Index(d, "(") - indexOf2 := strings.Index(d, ")") - if indexOf != 0 || indexOf2 <= 0 { - w.WriteByte(0x01) - w.WriteBytesShort([]byte(d)) - } else { - var b byte - var z bool - i, err := strconv.Atoi(d[indexOf+1 : indexOf2]) - if err == nil { - z2 := (1048576 & i) > 0 - if (i & 134217728) > 0 { - z = true - } else { - z = false - } - if z2 { - b = 1 - } else { - b = 0 - } - if z { - b |= 2 - } - w.WriteByte(b) - w.WriteBytesShort([]byte(d[indexOf2+1:])) + pos := w.AllocUInt16Head() + w.WriteUInt16(uint16(len(nonnildomains))) + for _, d := range nonnildomains { + // 目前的所有调用均不会出现 () + // indexOf := strings.Index(d, "(") + // indexOf2 := strings.Index(d, ")") + // if indexOf != 0 || indexOf2 <= 0 { + w.WriteByte(0x01) + w.WriteStringShort(d) + /* } else { + var b byte + var z bool + i, err := strconv.Atoi(d[indexOf+1 : indexOf2]) + if err == nil { + z2 := (1048576 & i) > 0 + if (i & 134217728) > 0 { + z = true + } else { + z = false } + if z2 { + b = 1 + } else { + b = 0 + } + if z { + b |= 2 + } + w.WriteByte(b) + w.WriteBytesShort([]byte(d[indexOf2+1:])) } - } - })) + }*/ + } + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t516.go b/internal/tlv/t516.go index 6a64c95e7..fbc2119e3 100644 --- a/internal/tlv/t516.go +++ b/internal/tlv/t516.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T516() []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x516) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t521.go b/internal/tlv/t521.go index 11ead58e7..9ae32d2af 100644 --- a/internal/tlv/t521.go +++ b/internal/tlv/t521.go @@ -5,9 +5,9 @@ import "github.com/Mrs4s/MiraiGo/binary" func T521(i uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x521) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt32(i) - w.WriteUInt16(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt32(i) + w.WriteUInt16(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t525.go b/internal/tlv/t525.go index fe89877ad..0b843f0a3 100644 --- a/internal/tlv/t525.go +++ b/internal/tlv/t525.go @@ -5,9 +5,9 @@ import "github.com/Mrs4s/MiraiGo/binary" func T525(t536 []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x525) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(1) - w.Write(t536) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(1) + w.Write(t536) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t52d.go b/internal/tlv/t52d.go index a98f79948..16273e8f1 100644 --- a/internal/tlv/t52d.go +++ b/internal/tlv/t52d.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T52D(devInfo []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x52d) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write(devInfo) - })) + pos := w.AllocUInt16Head() + w.Write(devInfo) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t536.go b/internal/tlv/t536.go index 9e23059ea..c6f5f2908 100644 --- a/internal/tlv/t536.go +++ b/internal/tlv/t536.go @@ -5,8 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T536(loginExtraData []byte) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x536) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.Write(loginExtraData) - })) + pos := w.AllocUInt16Head() + w.Write(loginExtraData) + w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t8.go b/internal/tlv/t8.go index 8a7ba34aa..b2b793377 100644 --- a/internal/tlv/t8.go +++ b/internal/tlv/t8.go @@ -5,10 +5,10 @@ import "github.com/Mrs4s/MiraiGo/binary" func T8(localId uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x8) - w.WriteBytesShort(binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(0) - w.WriteUInt32(localId) - w.WriteUInt16(0) - })) + pos := w.AllocUInt16Head() + w.WriteUInt16(0) + w.WriteUInt32(localId) + w.WriteUInt16(0) + w.WriteUInt16HeadExcludeSelfAt(pos) }) }