diff --git a/binary/writer.go b/binary/writer.go index 02c62645..18d8a8e6 100644 --- a/binary/writer.go +++ b/binary/writer.go @@ -24,37 +24,26 @@ func OpenWriterF(f func(*Writer)) (b []byte, cl func()) { return w.Bytes(), w.put } -func (w *Writer) AllocUInt16Head() (pos int) { - pos = (*bytes.Buffer)(w).Len() +func (w *Writer) FillUInt16() (pos int) { + pos = w.Len() (*bytes.Buffer)(w).Write([]byte{0, 0}) return } -/* -func (w *Writer) WriteUInt16HeadAt(pos int) { +func (w *Writer) WriteUInt16At(pos int, v uint16) { 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())) + binary.BigEndian.PutUint16(newdata, v) } -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() +func (w *Writer) FillUInt32() (pos int) { + pos = w.Len() (*bytes.Buffer)(w).Write([]byte{0, 0, 0, 0}) return } -func (w *Writer) WriteUInt32HeadAt(pos int) { +func (w *Writer) WriteUInt32At(pos int, v uint32) { newdata := (*bytes.Buffer)(w).Bytes()[pos:] - binary.BigEndian.PutUint32(newdata, uint32(len(newdata))) + binary.BigEndian.PutUint32(newdata, v) } func (w *Writer) Write(b []byte) { @@ -111,10 +100,9 @@ func (w *Writer) EncryptAndWrite(key []byte, data []byte) { } func (w *Writer) WriteIntLvPacket(offset int, f func(*Writer)) { - data, cl := OpenWriterF(f) - w.WriteUInt32(uint32(len(data) + offset)) - w.Write(data) - cl() + w.FillUInt32() + f(w) + w.WriteUInt32At(0, uint32(w.Len()-4+offset)) } func (w *Writer) WriteBytesShort(data []byte) { @@ -130,6 +118,10 @@ func (w *Writer) WriteTlvLimitedSize(data []byte, limit int) { w.WriteBytesShort(data[:limit]) } +func (w *Writer) Len() int { + return (*bytes.Buffer)(w).Len() +} + func (w *Writer) Bytes() []byte { return (*bytes.Buffer)(w).Bytes() } diff --git a/client/builders.go b/client/builders.go index b762448d..032a4f1d 100644 --- a/client/builders.go +++ b/client/builders.go @@ -199,12 +199,10 @@ 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(bw *binary.Writer) { - bw.WriteUInt16(0x106) - bw.WriteBytesShort(t106) - }) - w.Write(wb) - cl() + + w.WriteUInt16(0x106) + w.WriteBytesShort(t106) + // w.Write(tlv.T106(uint32(c.Uin), 0, c.version.AppId, c.version.SSOVersion, c.PasswordMd5, true, c.deviceInfo.Guid, c.deviceInfo.TgtgtKey, 0)) w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) w.Write(tlv.T100(c.version.SSOVersion, c.version.SubAppId, c.version.MainSigMap)) @@ -226,12 +224,10 @@ 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(bw *binary.Writer) { - bw.WriteUInt16(0x16A) - bw.WriteBytesShort(t16a) - }) - w.Write(wb) - cl() + + w.WriteUInt16(0x16A) + w.WriteBytesShort(t16a) + w.Write(tlv.T154(seq)) w.Write(tlv.T141(c.deviceInfo.SimInfo, c.deviceInfo.APN)) w.Write(tlv.T8(2052)) @@ -253,12 +249,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(bw *binary.Writer) { - bw.WriteUInt16(0x318) - bw.WriteBytesShort(t318) - }) - w.Write(wb) - cl() + + w.WriteUInt16(0x318) + w.WriteBytesShort(t318) })) req2 := network.Request{ @@ -377,12 +370,10 @@ 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(bw *binary.Writer) { - bw.WriteUInt16(0x106) - bw.WriteBytesShort(c.sig.EncryptedA1) - }) - w.Write(wb) - cl() + + w.WriteUInt16(0x106) + w.WriteBytesShort(c.sig.EncryptedA1) + w.Write(tlv.T116(c.version.MiscBitmap, c.version.SubSigmap)) w.Write(tlv.T100(c.version.SSOVersion, 2, c.version.MainSigMap)) w.Write(tlv.T107(0)) diff --git a/client/internal/network/transport.go b/client/internal/network/transport.go index cf0b0317..839c8cc2 100644 --- a/client/internal/network/transport.go +++ b/client/internal/network/transport.go @@ -66,7 +66,7 @@ func (t *Transport) PackPacket(req *Request) []byte { } return binary.NewWriterF(func(w *binary.Writer) { - pos := w.AllocUInt32Head() + pos := w.FillUInt32() // vvv w.Write(head) vvv w.WriteUInt32(uint32(req.Type)) w.WriteByte(byte(req.EncryptType)) @@ -100,7 +100,7 @@ func (t *Transport) PackPacket(req *Request) []byte { t.packBody(req, w) } })) - w.WriteUInt32HeadAt(pos) + w.WriteUInt32At(pos, uint32(w.Len())) }) } diff --git a/internal/packets/global.go b/internal/packets/global.go index 3ef09564..8ea50ab3 100644 --- a/internal/packets/global.go +++ b/internal/packets/global.go @@ -32,7 +32,7 @@ type IncomingPacket struct { func BuildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(writer *binary.Writer)) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteByte(2) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(cmd) w.Write(make([]byte, 21)) w.WriteByte(3) @@ -42,7 +42,7 @@ func BuildCode2DRequestPacket(seq uint32, j uint64, cmd uint16, bodyFunc func(wr w.WriteUInt64(j) bodyFunc(w) w.WriteByte(3) - w.WriteUInt16HeadUsingTotalBufferLenAt(pos) + w.WriteUInt16At(pos, uint16(w.Len())) }) } diff --git a/internal/tlv/t1.go b/internal/tlv/t1.go index e2f01809..0b79129f 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() 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) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t100.go b/internal/tlv/t100.go index dc0693f2..c4d42ef0 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() 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) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t106.go b/internal/tlv/t106.go index 24090b7d..7ae6dbbb 100644 --- a/internal/tlv/t106.go +++ b/internal/tlv/t106.go @@ -12,7 +12,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() keydata, kcl := binary.OpenWriterF(func(w *binary.Writer) { w.Write(passwordMd5[:]) w.WriteUInt32(0) // []byte{0x00, 0x00, 0x00, 0x00}... @@ -56,7 +56,7 @@ func T106(uin, salt, appId, ssoVer uint32, passwordMd5 [16]byte, guidAvailable b w.WriteUInt16(0) }) w.EncryptAndWrite(key[:], body) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) cl() }) } diff --git a/internal/tlv/t107.go b/internal/tlv/t107.go index 5739c5cb..427f29f9 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(picType) w.WriteByte(0x00) w.WriteUInt16(0) w.WriteByte(0x01) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t109.go b/internal/tlv/t109.go index 638fad4f..6f86b465 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() h := md5.Sum(androidId) w.Write(h[:]) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t116.go b/internal/tlv/t116.go index 9b70bae2..09ccb4c3 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteByte(0x00) w.WriteUInt32(miscBitmap) w.WriteUInt32(subSigMap) w.WriteByte(0x01) w.WriteUInt32(1600000226) // app id list - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t124.go b/internal/tlv/t124.go index 21fe35f2..5d4f65a8 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() 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) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t128.go b/internal/tlv/t128.go index e24d023a..ed9adbfe 100644 --- a/internal/tlv/t128.go +++ b/internal/tlv/t128.go @@ -5,7 +5,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(0) w.WriteBool(isGuidFromFileNull) w.WriteBool(isGuidAvailable) @@ -14,6 +14,6 @@ func T128(isGuidFromFileNull, isGuidAvailable, isGuidChanged bool, guidFlag uint w.WriteTlvLimitedSize(buildModel, 32) w.WriteTlvLimitedSize(guid, 16) w.WriteTlvLimitedSize(buildBrand, 16) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t141.go b/internal/tlv/t141.go index 2d45ae9e..811cef25 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(1) w.WriteBytesShort(simInfo) w.WriteUInt16(2) // network type wifi w.WriteBytesShort(apn) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t142.go b/internal/tlv/t142.go index 46752be3..04a246ad 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(0) w.WriteTlvLimitedSize([]byte(apkId), 32) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t144.go b/internal/tlv/t144.go index ab014ac9..0f4f91b6 100644 --- a/internal/tlv/t144.go +++ b/internal/tlv/t144.go @@ -12,7 +12,7 @@ func T144( ) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x144) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.EncryptAndWrite(tgtgtKey, binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(5) w.Write(T109(imei)) @@ -21,6 +21,6 @@ func T144( w.Write(T128(isGuidFromFileNull, isGuidAvailable, isGuidChanged, guidFlag, buildModel, guid, buildBrand)) w.Write(T16E(buildModel)) })) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t145.go b/internal/tlv/t145.go index 9792953f..6f4caf2c 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.Write(guid) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t147.go b/internal/tlv/t147.go index 4de436ba..e5261cc4 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt32(appId) w.WriteTlvLimitedSize(apkVersionName, 32) w.WriteTlvLimitedSize(apkSignatureMd5, 32) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t154.go b/internal/tlv/t154.go index 14239670..cf75e02d 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt32(uint32(seq)) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t16.go b/internal/tlv/t16.go index 0bd5c79c..21a65012 100644 --- a/internal/tlv/t16.go +++ b/internal/tlv/t16.go @@ -5,7 +5,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt32(ssoVersion) w.WriteUInt32(appId) w.WriteUInt32(subAppId) @@ -13,6 +13,6 @@ func T16(ssoVersion, appId, subAppId uint32, guid, apkId, apkVersionName, apkSig w.WriteBytesShort(apkId) w.WriteBytesShort(apkVersionName) w.WriteBytesShort(apkSign) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t166.go b/internal/tlv/t166.go index d4e50f38..e69880e2 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteByte(imageType) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t16e.go b/internal/tlv/t16e.go index e0ea8589..d6e180da 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.Write(buildModel) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t177.go b/internal/tlv/t177.go index f93c72dd..fe1c96ee 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteByte(0x01) w.WriteUInt32(buildTime) w.WriteStringShort(sdkVersion) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t17a.go b/internal/tlv/t17a.go index 90b60bc2..5edcced2 100644 --- a/internal/tlv/t17a.go +++ b/internal/tlv/t17a.go @@ -5,8 +5,7 @@ import "github.com/Mrs4s/MiraiGo/binary" func T17A(value int32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x17a) - pos := w.AllocUInt16Head() + w.WriteUInt16(4) // len of uint32 w.WriteUInt32(uint32(value)) - w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t17c.go b/internal/tlv/t17c.go index 3dfd47f1..bd6f493a 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteStringShort(code) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t18.go b/internal/tlv/t18.go index 1b33b030..462ab507 100644 --- a/internal/tlv/t18.go +++ b/internal/tlv/t18.go @@ -5,7 +5,7 @@ import "github.com/Mrs4s/MiraiGo/binary" func T18(appId uint32, uin uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x18) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(1) w.WriteUInt32(1536) w.WriteUInt32(appId) @@ -13,6 +13,6 @@ func T18(appId uint32, uin uint32) []byte { w.WriteUInt32(uin) w.WriteUInt16(0) w.WriteUInt16(0) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t187.go b/internal/tlv/t187.go index de65fe7f..daa7147f 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() h := md5.Sum(macAddress) w.Write(h[:]) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t188.go b/internal/tlv/t188.go index 6ddb8796..44f394b7 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() h := md5.Sum(androidId) w.Write(h[:]) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t191.go b/internal/tlv/t191.go index a96aff1d..b7c980ad 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteByte(k) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t193.go b/internal/tlv/t193.go index 96ca0bcf..dd42cf87 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) - pos := w.AllocUInt16Head() - w.Write([]byte(ticket)) - w.WriteUInt16HeadExcludeSelfAt(pos) + pos := w.FillUInt16() + w.WriteString(ticket) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t194.go b/internal/tlv/t194.go index 79318eae..4d3d196c 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.Write(imsiMd5) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t1b.go b/internal/tlv/t1b.go index f6b30f70..b00f7fae 100644 --- a/internal/tlv/t1b.go +++ b/internal/tlv/t1b.go @@ -5,7 +5,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt32(micro) w.WriteUInt32(version) w.WriteUInt32(size) @@ -14,6 +14,6 @@ func T1B(micro, version, size, margin, dpi, ecLevel, hint uint32) []byte { w.WriteUInt32(ecLevel) w.WriteUInt32(hint) w.WriteUInt16(0) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t1d.go b/internal/tlv/t1d.go index 099b31e5..c123f277 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteByte(1) w.WriteUInt32(miscBitmap) w.WriteUInt32(0) w.WriteByte(0) w.WriteUInt32(0) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t1f.go b/internal/tlv/t1f.go index 4e671d84..efe79bc1 100644 --- a/internal/tlv/t1f.go +++ b/internal/tlv/t1f.go @@ -5,7 +5,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteBool(isRoot) w.WriteBytesShort(osName) w.WriteBytesShort(osVersion) @@ -13,6 +13,6 @@ func T1F(isRoot bool, osName, osVersion, simOperatorName, apn []byte, networkTyp w.WriteBytesShort(simOperatorName) w.WriteUInt16(0) // w.WriteBytesShort([]byte{}) w.WriteBytesShort(apn) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t2.go b/internal/tlv/t2.go index efa2037a..08a06877 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(0) w.WriteStringShort(result) w.WriteBytesShort(sign) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t202.go b/internal/tlv/t202.go index ec1c4f69..9b7f07a1 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteTlvLimitedSize(wifiBSSID, 16) w.WriteTlvLimitedSize(wifiSSID, 32) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t35.go b/internal/tlv/t35.go index 9903096d..1535b5b7 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt32(productType) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t400.go b/internal/tlv/t400.go index 59173f17..6319ef52 100644 --- a/internal/tlv/t400.go +++ b/internal/tlv/t400.go @@ -9,7 +9,7 @@ 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.EncryptAndWrite(g, binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(1) // version w.WriteUInt64(uint64(uin)) @@ -20,6 +20,6 @@ func T400(g []byte, uin int64, guid, dpwd []byte, j2, j3 int64, randSeed []byte) w.WriteUInt32(uint32(time.Now().Unix())) w.Write(randSeed) })) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t511.go b/internal/tlv/t511.go index 43609e75..4a4d18b7 100644 --- a/internal/tlv/t511.go +++ b/internal/tlv/t511.go @@ -26,7 +26,7 @@ func T511(domains []string) []byte { */ return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x511) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(uint16(len(nonnildomains))) for _, d := range nonnildomains { // 目前的所有调用均不会出现 () @@ -59,6 +59,6 @@ func T511(domains []string) []byte { } }*/ } - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t516.go b/internal/tlv/t516.go index fbc2119e..bfba1715 100644 --- a/internal/tlv/t516.go +++ b/internal/tlv/t516.go @@ -5,8 +5,7 @@ import "github.com/Mrs4s/MiraiGo/binary" func T516() []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x516) - pos := w.AllocUInt16Head() + w.WriteUInt16(4) // len of uint32 w.WriteUInt32(0) - w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t521.go b/internal/tlv/t521.go index 9ae32d2a..f5e021a9 100644 --- a/internal/tlv/t521.go +++ b/internal/tlv/t521.go @@ -5,9 +5,8 @@ import "github.com/Mrs4s/MiraiGo/binary" func T521(i uint32) []byte { return binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(0x521) - pos := w.AllocUInt16Head() + w.WriteUInt16(4 + 2) w.WriteUInt32(i) w.WriteUInt16(0) - w.WriteUInt16HeadExcludeSelfAt(pos) }) } diff --git a/internal/tlv/t525.go b/internal/tlv/t525.go index 0b843f0a..ef80e37c 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(1) w.Write(t536) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t52d.go b/internal/tlv/t52d.go index 16273e8f..0ad17be0 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.Write(devInfo) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t536.go b/internal/tlv/t536.go index c6f5f290..4096a83e 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.Write(loginExtraData) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) } diff --git a/internal/tlv/t8.go b/internal/tlv/t8.go index b2b79337..851f794b 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) - pos := w.AllocUInt16Head() + pos := w.FillUInt16() w.WriteUInt16(0) w.WriteUInt32(localId) w.WriteUInt16(0) - w.WriteUInt16HeadExcludeSelfAt(pos) + w.WriteUInt16At(pos, uint16(w.Len()-4)) }) }