1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

implement t512

This commit is contained in:
wfjsw 2020-08-16 19:56:55 +08:00
parent be0e431f8f
commit f167e00ded
3 changed files with 73 additions and 15 deletions

View File

@ -34,10 +34,12 @@ func (r *Reader) ReadByte() byte {
func (r *Reader) ReadBytes(len int) []byte { func (r *Reader) ReadBytes(len int) []byte {
b := make([]byte, len) b := make([]byte, len)
if len > 0 {
_, err := r.buf.Read(b) _, err := r.buf.Read(b)
if err != nil { if err != nil {
panic(err) panic(err)
} }
}
return b return b
} }

View File

@ -5,14 +5,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/longmsg"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/multimsg"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/packets"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/golang/protobuf/proto"
"io" "io"
"log" "log"
"math" "math"
@ -21,6 +13,15 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/longmsg"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/multimsg"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/packets"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/golang/protobuf/proto"
) )
type QQClient struct { type QQClient struct {
@ -84,6 +85,9 @@ type loginSigInfo struct {
d2Key []byte d2Key []byte
wtSessionTicketKey []byte wtSessionTicketKey []byte
deviceToken []byte deviceToken []byte
psKeyMap map[string][]byte
pt4TokenMap map[string][]byte
} }
func init() { func init() {
@ -656,6 +660,28 @@ func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo {
return nil return nil
} }
func (c *QQClient) getCookies() string {
return fmt.Sprintf("uin=o%d; skey=%s;", c.Uin, c.sigInfo.sKey)
}
func (c *QQClient) getCookiesWithDomain(domain string) string {
cookie := c.getCookies()
if psKey, ok := c.sigInfo.psKeyMap[domain]; ok {
return fmt.Sprintf("%s p_uin=o%d; p_skey=%s;", cookie, c.Uin, psKey)
} else {
return cookie
}
}
func (c *QQClient) getCSRFToken() int {
accu := 5381
for _, b := range c.sigInfo.sKey {
accu = accu + (accu << 5) + int(b)
}
return 2147483647 & accu
}
func (c *QQClient) editMemberCard(groupCode, memberUin int64, card string) { func (c *QQClient) editMemberCard(groupCode, memberUin int64, card string) {
_, _ = c.sendAndWait(c.buildEditGroupTagPacket(groupCode, memberUin, card)) _, _ = c.sendAndWait(c.buildEditGroupTagPacket(groupCode, memberUin, card))
} }

View File

@ -2,8 +2,9 @@ package client
import ( import (
"fmt" "fmt"
"github.com/Mrs4s/MiraiGo/binary"
"time" "time"
"github.com/Mrs4s/MiraiGo/binary"
) )
// --- tlv decoders for qq client --- // --- tlv decoders for qq client ---
@ -52,6 +53,8 @@ func (c *QQClient) decodeT119(data []byte) {
//noPicSig []byte //noPicSig []byte
//ctime = time.Now().Unix() //ctime = time.Now().Unix()
//etime = ctime + 2160000 //etime = ctime + 2160000
psKeyMap map[string][]byte
pt4TokenMap map[string][]byte
) )
if _, ok := m[0x125]; ok { if _, ok := m[0x125]; ok {
@ -69,9 +72,9 @@ func (c *QQClient) decodeT119(data []byte) {
if _, ok := m[0x200]; ok { if _, ok := m[0x200]; ok {
//pf, pfkey = readT200(t200) //pf, pfkey = readT200(t200)
} }
if _, ok := m[0x512]; ok { if t512, ok := m[0x512]; ok {
psKeyMap, pt4TokenMap = readT512(t512)
} // 暂不处理, Http api cookie }
if _, ok := m[0x531]; ok { if _, ok := m[0x531]; ok {
//a1, noPicSig = readT531(t531) //a1, noPicSig = readT531(t531)
} }
@ -87,6 +90,9 @@ func (c *QQClient) decodeT119(data []byte) {
d2Key: m[0x305], d2Key: m[0x305],
wtSessionTicketKey: m[0x134], wtSessionTicketKey: m[0x134],
deviceToken: m[0x322], deviceToken: m[0x322],
psKeyMap: psKeyMap,
pt4TokenMap: pt4TokenMap,
} }
c.Nickname = nick c.Nickname = nick
c.Age = age c.Age = age
@ -142,6 +148,30 @@ func readT200(data []byte) (pf, pfKey []byte) {
return return
} }
func readT512(data []byte) (psKeyMap map[string][]byte, pt4TokenMap map[string][]byte) {
reader := binary.NewReader(data)
length := int(reader.ReadUInt16())
psKeyMap = make(map[string][]byte, length)
pt4TokenMap = make(map[string][]byte, length)
for i := 0; i < length; i++ {
domain := reader.ReadStringShort()
psKey := reader.ReadBytesShort()
pt4Token := reader.ReadBytesShort()
if len(psKey) > 0 {
psKeyMap[domain] = psKey
}
if len(pt4Token) > 0 {
pt4TokenMap[domain] = pt4Token
}
}
return
}
func readT531(data []byte) (a1, noPicSig []byte) { func readT531(data []byte) (a1, noPicSig []byte) {
reader := binary.NewReader(data) reader := binary.NewReader(data)
m := reader.ReadTlvMap(2) m := reader.ReadTlvMap(2)