Skip to content

Commit

Permalink
optimize: binary Pack parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 6, 2024
1 parent 5c54f83 commit d073503
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/LagrangeDev/LagrangeGo/packets/tlv"

"github.com/LagrangeDev/LagrangeGo/utils/binary"
binary2 "github.com/LagrangeDev/LagrangeGo/utils/binary"

"github.com/LagrangeDev/LagrangeGo/utils"
Expand Down Expand Up @@ -94,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(-1)
}).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 @@ -131,7 +132,7 @@ func (c *QQClient) GetQrcodeResult() (qrcodeState.State, error) {
WriteU64(0).
WriteU32(0).
WriteU8(0).
WriteU8(0x83).Pack(-1)
WriteU8(0x83).Pack(binary.PackTypeNone)

response, err := c.SendUniPacketAndAwait("wtlogin.trans_emp",
wtlogin.BuildCode2dPacket(0, 0x12, c.appInfo, body))
Expand Down Expand Up @@ -244,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(-1)
}).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 @@ -37,7 +37,7 @@ func T100(ssoVersion, appID, subAppID, appClientVersion, sigmap, dbBufVer int) [
func T106(appId, appClientVersion, uin int, guid string, passwordMd5, tgtgtKey, ip []byte, savePassword bool) []byte {
// password_md5 + bytes(4) + write_u32(uin).pack()
key := utils.MD5Digest(append(passwordMd5, append(make([]byte, 4),
binary.NewBuilder(nil).WriteU32(uint32(uin)).Pack(-1)...)...))
binary.NewBuilder(nil).WriteU32(uint32(uin)).Pack(binary.PackTypeNone)...)...))

body := binary.NewBuilder(nil).
WriteStruct(uint16(4), // tgtgt version
Expand All @@ -57,7 +57,7 @@ func T106(appId, appClientVersion, uin int, guid string, passwordMd5, tgtgtKey,
WriteU32(0).
WriteU32(1).
WritePacketString(strconv.Itoa(uin), "u16", false).
Pack(-1)
Pack(binary.PackTypeNone)

return binary.NewBuilder(nil).
WritePacketBytes(crypto.NewTeaCipher(key).Encrypt(body), "u32", true).
Expand Down
14 changes: 7 additions & 7 deletions packets/wtlogin/oicq.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func BuildCode2dPacket(uin uint32, cmdID int, appInfo *info.AppInfo, body []byte
WritePacketBytes(make([]byte, 14), "", true).
WriteU32(uint32(appInfo.AppID)).
WritePacketBytes(body, "", true).
Pack(-1),
Pack(binary.PackTypeNone),
)
}

Expand Down Expand Up @@ -75,13 +75,13 @@ func BuildLoginPacket(uin uint32, cmd string, appinfo *info.AppInfo, body []byte
WritePacketBytes(ecdh.ECDH["secp192k1"].GetPublicKey(), "", true).
WritePacketBytes(encBody, "", true).
WriteU8(3).
Pack(-1)
Pack(binary.PackTypeNone)

frame := binary.NewBuilder(nil).
WriteU8(2).
WriteU16(uint16(len(frameBody))+3). // + 2 + 1
WritePacketBytes(frameBody, "", true).
Pack(-1)
Pack(binary.PackTypeNone)

return frame
}
Expand Down Expand Up @@ -116,12 +116,12 @@ func BuildUniPacket(uin, seq int, cmd string, sign map[string]string,
WritePacketBytes(nil, "u32", true).
WritePacketString(appInfo.CurrentVersion, "u16", true).
WritePacketBytes(head.Encode(), "u32", true).
Pack(-1)
Pack(binary.PackTypeNone)

ssoPacket := binary.NewBuilder(nil).
WritePacketBytes(ssoHeader, "u32", true).
WritePacketBytes(body, "u32", true).
Pack(-1)
Pack(binary.PackTypeNone)

encrypted := crypto.NewTeaCipher(sigInfo.D2Key).Encrypt(ssoPacket)

Expand All @@ -139,9 +139,9 @@ func BuildUniPacket(uin, seq int, cmd string, sign map[string]string,
WriteU8(0).
WritePacketString(strconv.Itoa(uin), "u32", true).
WritePacketBytes(encrypted, "", true).
Pack(-1)
Pack(binary.PackTypeNone)

return binary.NewBuilder(nil).WritePacketBytes(service, "u32", true).Pack(-1)
return binary.NewBuilder(nil).WritePacketBytes(service, "u32", true).Pack(binary.PackTypeNone)
}

func DecodeLoginResponse(buf []byte, sig *info.SigInfo) (bool, error) {
Expand Down

0 comments on commit d073503

Please sign in to comment.