Skip to content

Commit

Permalink
fix(binary): tlv call
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 6, 2024
1 parent d073503 commit 135f3a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *QQClient) FecthQrcode() ([]byte, string, error) {
WriteU16(0).
WriteU64(0).
WriteU8(0).
WriteTlv([][]byte{
WritePacketTlv(
tlv.T16(c.appInfo.AppID, c.appInfo.SubAppID,
utils.MustParseHexStr(c.deviceInfo.Guid), c.appInfo.PTVersion, c.appInfo.PackageName),
tlv.T1b(),
Expand All @@ -95,7 +95,7 @@ func (c *QQClient) FecthQrcode() ([]byte, string, error) {
tlv.T35(c.appInfo.PTOSVersion),
tlv.T66(c.appInfo.PTOSVersion),
tlv.Td1(c.appInfo.OS, c.deviceInfo.DeviceName),
}).WriteU8(3).Pack(binary.PackTypeNone)
).WriteU8(3).Pack(binary.PackTypeNone)

packet := wtlogin.BuildCode2dPacket(c.Uin, 0x31, c.appInfo, body)
response, err := c.SendUniPacketAndAwait("wtlogin.trans_emp", packet)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (c *QQClient) QrcodeLogin(refreshInterval int) (bool, error) {
device := c.deviceInfo
body := binary2.NewBuilder(nil).
WriteU16(0x09).
WriteTlv([][]byte{
WritePacketTlv(
binary2.NewBuilder(nil).WritePacketBytes(c.t106, "", true).Pack(0x106),
tlv.T144(c.sig.Tgtgt, app, device),
tlv.T116(app.SubSigmap),
Expand All @@ -245,7 +245,7 @@ func (c *QQClient) QrcodeLogin(refreshInterval int) (bool, error) {
binary2.NewBuilder(nil).WritePacketBytes(c.t16a, "", true).Pack(0x16a),
tlv.T166(5),
tlv.T521(0x13, "basicim"),
}).Pack(binary.PackTypeNone)
).Pack(binary.PackTypeNone)

response, err := c.SendUniPacketAndAwait(
"wtlogin.login",
Expand Down
4 changes: 2 additions & 2 deletions packets/tlv/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func T142(apkID string, version int) []byte {

func T144(tgtgtKey []byte, appInfo *info.AppInfo, device *info.DeviceInfo) []byte {
return binary.NewBuilder(tgtgtKey).
WriteTlv([][]byte{
WritePacketTlv(
T16e(device.DeviceName),
T147(appInfo.AppID, appInfo.PTVersion, appInfo.PackageName),
T128(appInfo.OS, utils.MustParseHexStr(device.Guid)),
T124(),
}).Pack(0x144)
).Pack(0x144)
}

func T145(guid []byte) []byte {
Expand Down
20 changes: 16 additions & 4 deletions utils/binary/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (b *Builder) pack(v any) *Builder {
func (b *Builder) Pack(typ PackType) []byte {
if typ != PackTypeNone {
// 或许这里是tlv
buf := make([]byte, 4, b.Len()+4)
buf := make([]byte, b.Len()+4)
binary.BigEndian.PutUint16(buf[0:2], uint16(typ)) // type
binary.BigEndian.PutUint16(buf[2:4], uint16(len(b.Data()))) // length
copy(buf[4:], b.Data()) // type + length + value
Expand Down Expand Up @@ -126,8 +126,8 @@ func (b *Builder) WriteString(v string) *Builder {
return b.WriteBytes(utils.S2B(v), true)
}

func (b *Builder) WriteStruct(datas ...any) *Builder {
for _, data := range datas {
func (b *Builder) WriteStruct(data ...any) *Builder {
for _, data := range data {
b.pack(data)
}
return b
Expand Down Expand Up @@ -172,13 +172,25 @@ func (b *Builder) WriteI64(v int64) *Builder {
func (b *Builder) WriteFloat(v float32) *Builder {
return b.WriteU32(math.Float32bits(v))
}

func (b *Builder) WriteDouble(v float64) *Builder {
return b.WriteU64(math.Float64bits(v))
}
func (b *Builder) WriteTlv(tlvs [][]byte) *Builder {

/*
func (b *Builder) WriteTlv(tlvs ...[]byte) *Builder {
b.WriteU16(uint16(len(tlvs)))
for _, tlv := range tlvs {
b.WriteBytes(tlv, false)
}
return b
}
*/

func (b *Builder) WritePacketTlv(tlvs ...[]byte) *Builder {
b.WriteU16(uint16(len(tlvs)))
for _, tlv := range tlvs {
b.WritePacketBytes(tlv, "", true)
}
return b
}

0 comments on commit 135f3a0

Please sign in to comment.