github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/internal/tlv/t106.go (about) 1 package tlv 2 3 import ( 4 "crypto/md5" 5 "math/rand" 6 "strconv" 7 "time" 8 9 "github.com/Mrs4s/MiraiGo/binary" 10 ) 11 12 func T106(uin, salt, appId, ssoVer uint32, passwordMd5 [16]byte, guidAvailable bool, guid, tgtgtKey []byte, wtf uint32) []byte { 13 return binary.NewWriterF(func(w *binary.Writer) { 14 w.WriteUInt16(0x106) 15 pos := w.FillUInt16() 16 keydata, kcl := binary.OpenWriterF(func(w *binary.Writer) { 17 w.Write(passwordMd5[:]) 18 w.WriteUInt32(0) // []byte{0x00, 0x00, 0x00, 0x00}... 19 if salt != 0 { 20 w.WriteUInt32(salt) 21 } else { 22 w.WriteUInt32(uin) 23 } 24 }) 25 key := md5.Sum(keydata) 26 kcl() 27 body, cl := binary.OpenWriterF(func(w *binary.Writer) { 28 w.WriteUInt16(4) 29 w.WriteUInt32(rand.Uint32()) 30 w.WriteUInt32(ssoVer) 31 w.WriteUInt32(16) // appId 32 w.WriteUInt32(0) // app client version 33 if uin == 0 { 34 w.WriteUInt64(uint64(salt)) 35 } else { 36 w.WriteUInt64(uint64(uin)) 37 } 38 w.WriteUInt32(uint32(time.Now().Unix())) 39 w.WriteUInt32(0) // fake ip w.Write([]byte{0x00, 0x00, 0x00, 0x00}) 40 w.WriteByte(0x01) 41 w.Write(passwordMd5[:]) 42 w.Write(tgtgtKey) 43 w.WriteUInt32(wtf) 44 w.WriteBool(guidAvailable) 45 if len(guid) == 0 { 46 w.WriteUInt32(rand.Uint32()) 47 w.WriteUInt32(rand.Uint32()) 48 w.WriteUInt32(rand.Uint32()) 49 w.WriteUInt32(rand.Uint32()) 50 } else { 51 w.Write(guid) 52 } 53 w.WriteUInt32(appId) 54 w.WriteUInt32(1) // password login 55 w.WriteStringShort(strconv.FormatInt(int64(uin), 10)) 56 w.WriteUInt16(0) 57 }) 58 w.EncryptAndWrite(key[:], body) 59 w.WriteUInt16At(pos, uint16(w.Len()-4)) 60 cl() 61 }) 62 }