mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
fix some issue with golangci-lint.
This commit is contained in:
parent
7797ecdf61
commit
7fe0b873c3
@ -395,8 +395,10 @@ func (info *DeviceInfo) GenNewGuid() {
|
|||||||
func (info *DeviceInfo) GenNewTgtgtKey() {
|
func (info *DeviceInfo) GenNewTgtgtKey() {
|
||||||
r := make([]byte, 16)
|
r := make([]byte, 16)
|
||||||
rand.Read(r)
|
rand.Read(r)
|
||||||
t := md5.Sum(append(r, info.Guid...))
|
h := md5.New()
|
||||||
info.TgtgtKey = t[:]
|
h.Write(r)
|
||||||
|
h.Write(info.Guid)
|
||||||
|
info.TgtgtKey = h.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (info *DeviceInfo) GenDeviceInfoData() []byte {
|
func (info *DeviceInfo) GenDeviceInfoData() []byte {
|
||||||
|
@ -8,14 +8,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/binary/jce"
|
"github.com/Mrs4s/MiraiGo/binary/jce"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
||||||
"github.com/Mrs4s/MiraiGo/protocol/packets"
|
"github.com/Mrs4s/MiraiGo/protocol/packets"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -350,15 +350,12 @@ func decodeMsgSendResponse(c *QQClient, _ *incomingPacketInfo, payload []byte) (
|
|||||||
if err := proto.Unmarshal(payload, &rsp); err != nil {
|
if err := proto.Unmarshal(payload, &rsp); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
||||||
}
|
}
|
||||||
if rsp.GetResult() != 0 {
|
switch rsp.GetResult() {
|
||||||
switch rsp.GetResult() {
|
case 0: // OK.
|
||||||
case 55:
|
case 55:
|
||||||
c.Error("send msg error: %v Bot has blocked target's content", rsp.GetResult())
|
c.Error("send msg error: %v Bot has blocked target's content", rsp.GetResult())
|
||||||
break
|
default:
|
||||||
default:
|
c.Error("send msg error: %v %v", rsp.GetResult(), rsp.GetErrMsg())
|
||||||
c.Error("send msg error: %v %v", rsp.GetResult(), rsp.GetErrMsg())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
binary2 "encoding/binary"
|
binary2 "encoding/binary"
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -46,10 +44,10 @@ func (c *QQClient) highwayUploadStream(ip uint32, port int, updKey []byte, strea
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
offset := 0
|
offset := 0
|
||||||
reader := binary.NewNetworkReader(conn)
|
reader := binary.NewNetworkReader(conn)
|
||||||
chunk := *binary.Get256KBytes()
|
buf := binary.Get256KBytes()
|
||||||
defer func() { // 延迟捕获 chunk
|
chunk := *buf
|
||||||
binary.Put256KBytes(&chunk)
|
defer binary.Put256KBytes(buf)
|
||||||
}()
|
|
||||||
w := binary.NewWriter()
|
w := binary.NewWriter()
|
||||||
defer binary.PutWriter(w)
|
defer binary.PutWriter(w)
|
||||||
for {
|
for {
|
||||||
@ -131,10 +129,10 @@ func (c *QQClient) highwayUploadByBDH(stream io.Reader, length int64, cmdId int3
|
|||||||
return nil, errors.Wrap(err, "echo error")
|
return nil, errors.Wrap(err, "echo error")
|
||||||
}
|
}
|
||||||
var rspExt []byte
|
var rspExt []byte
|
||||||
chunk := *binary.Get256KBytes()
|
buf := binary.Get256KBytes()
|
||||||
defer func() { // 延迟捕获 chunk
|
chunk := *buf
|
||||||
binary.Put256KBytes(&chunk)
|
defer binary.Put256KBytes(buf)
|
||||||
}()
|
|
||||||
w := binary.NewWriter()
|
w := binary.NewWriter()
|
||||||
defer binary.PutWriter(w)
|
defer binary.PutWriter(w)
|
||||||
for {
|
for {
|
||||||
@ -466,7 +464,8 @@ func (c *QQClient) excitingUploadStream(stream io.ReadSeeker, cmdId int32, ticke
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "request error")
|
return nil, errors.Wrap(err, "request error")
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(rsp.Body)
|
body, _ := io.ReadAll(rsp.Body)
|
||||||
|
_ = rsp.Body.Close()
|
||||||
r := binary.NewReader(body)
|
r := binary.NewReader(body)
|
||||||
r.ReadByte()
|
r.ReadByte()
|
||||||
hl := r.ReadInt32()
|
hl := r.ReadInt32()
|
||||||
@ -487,32 +486,6 @@ func (c *QQClient) excitingUploadStream(stream io.ReadSeeker, cmdId int32, ticke
|
|||||||
return rspExt, nil
|
return rspExt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只是为了写的跟上面一样长(bushi,当然也应该是最快的玩法
|
|
||||||
func (c *QQClient) uploadPtt(ip string, port int32, updKey, fileKey, data, md5 []byte) error {
|
|
||||||
url := make([]byte, 512)[:0]
|
|
||||||
url = append(url, "http://"...)
|
|
||||||
url = append(url, ip...)
|
|
||||||
url = append(url, ':')
|
|
||||||
url = strconv.AppendInt(url, int64(port), 10)
|
|
||||||
url = append(url, "/?ver=4679&ukey="...)
|
|
||||||
p := len(url)
|
|
||||||
url = url[:p+len(updKey)*2]
|
|
||||||
hex.Encode(url[p:], updKey)
|
|
||||||
url = append(url, "&filekey="...)
|
|
||||||
p = len(url)
|
|
||||||
url = url[:p+len(fileKey)*2]
|
|
||||||
hex.Encode(url[p:], fileKey)
|
|
||||||
url = append(url, "&filesize="...)
|
|
||||||
url = strconv.AppendInt(url, int64(len(data)), 10)
|
|
||||||
url = append(url, "&bmd5="...)
|
|
||||||
p = len(url)
|
|
||||||
url = url[:p+32]
|
|
||||||
hex.Encode(url[p:], md5)
|
|
||||||
url = append(url, "&mType=pttDu&voice_encodec=1"...)
|
|
||||||
_, err := utils.HttpPostBytes(string(url), data)
|
|
||||||
return errors.Wrap(err, "failed to upload ptt")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *QQClient) uploadGroupHeadPortrait(groupCode int64, img []byte) error {
|
func (c *QQClient) uploadGroupHeadPortrait(groupCode int64, img []byte) error {
|
||||||
url := fmt.Sprintf(
|
url := fmt.Sprintf(
|
||||||
"http://htdata3.qq.com/cgi-bin/httpconn?htcmd=0x6ff0072&ver=5520&ukey=%v&range=0&uin=%v&seq=23&groupuin=%v&filetype=3&imagetype=5&userdata=0&subcmd=1&subver=101&clip=0_0_0_0&filesize=%v",
|
"http://htdata3.qq.com/cgi-bin/httpconn?htcmd=0x6ff0072&ver=5520&ukey=%v&range=0&uin=%v&seq=23&groupuin=%v&filetype=3&imagetype=5&userdata=0&subcmd=1&subver=101&clip=0_0_0_0&filesize=%v",
|
||||||
|
@ -47,7 +47,7 @@ func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*messag
|
|||||||
}
|
}
|
||||||
if len(c.srvSsoAddrs) == 0 {
|
if len(c.srvSsoAddrs) == 0 {
|
||||||
for i, addr := range rsp.UploadIp {
|
for i, addr := range rsp.UploadIp {
|
||||||
c.srvSsoAddrs = append(c.srvSsoAddrs, fmt.Sprintf("%v:%v", binary.UInt32ToIPV4Address(uint32(addr)), rsp.UploadPort[i]))
|
c.srvSsoAddrs = append(c.srvSsoAddrs, fmt.Sprintf("%v:%v", binary.UInt32ToIPV4Address(addr), rsp.UploadPort[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err = c.highwayUploadByBDH(img, length, 2, rsp.UploadKey, fh, EmptyBytes, false); err == nil {
|
if _, err = c.highwayUploadByBDH(img, length, 2, rsp.UploadKey, fh, EmptyBytes, false); err == nil {
|
||||||
@ -74,7 +74,7 @@ func (c *QQClient) UploadGroupImageByFile(groupCode int64, path string) (*messag
|
|||||||
}
|
}
|
||||||
defer func() { _ = img.Close() }()
|
defer func() { _ = img.Close() }()
|
||||||
fh, length := utils.ComputeMd5AndLength(img)
|
fh, length := utils.ComputeMd5AndLength(img)
|
||||||
seq, pkt := c.buildGroupImageStorePacket(groupCode, fh[:], int32(length))
|
seq, pkt := c.buildGroupImageStorePacket(groupCode, fh, int32(length))
|
||||||
r, err := c.sendAndWait(seq, pkt)
|
r, err := c.sendAndWait(seq, pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -105,7 +105,7 @@ ok:
|
|||||||
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
|
if bytes.Equal(tmp, []byte{0x47, 0x49, 0x46, 0x38}) {
|
||||||
imageType = 2000
|
imageType = 2000
|
||||||
}
|
}
|
||||||
return message.NewGroupImage(binary.CalculateImageResourceId(fh[:]), fh[:], rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil
|
return message.NewGroupImage(binary.CalculateImageResourceId(fh), fh, rsp.FileId, int32(length), int32(i.Width), int32(i.Height), imageType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQClient) UploadPrivateImage(target int64, img io.ReadSeeker) (*message.FriendImageElement, error) {
|
func (c *QQClient) UploadPrivateImage(target int64, img io.ReadSeeker) (*message.FriendImageElement, error) {
|
||||||
|
@ -229,35 +229,37 @@ func msgType0x210Sub44Decoder(c *QQClient, protobuf []byte) error {
|
|||||||
if err := proto.Unmarshal(protobuf, &s44); err != nil {
|
if err := proto.Unmarshal(protobuf, &s44); err != nil {
|
||||||
return errors.Wrap(err, "failed to unmarshal protobuf message")
|
return errors.Wrap(err, "failed to unmarshal protobuf message")
|
||||||
}
|
}
|
||||||
if s44.GroupSyncMsg != nil {
|
if s44.GroupSyncMsg == nil {
|
||||||
func() {
|
return nil
|
||||||
groupJoinLock.Lock()
|
}
|
||||||
defer groupJoinLock.Unlock()
|
groupJoinLock.Lock()
|
||||||
if s44.GroupSyncMsg.GetGrpCode() != 0 { // member sync
|
defer groupJoinLock.Unlock()
|
||||||
c.Debug("syncing members.")
|
if s44.GroupSyncMsg.GetGrpCode() != 0 { // member sync
|
||||||
if group := c.FindGroup(s44.GroupSyncMsg.GetGrpCode()); group != nil {
|
return errors.New("invalid group code")
|
||||||
group.Update(func(_ *GroupInfo) {
|
}
|
||||||
var lastJoinTime int64 = 0
|
c.Debug("syncing members.")
|
||||||
for _, m := range group.Members {
|
if group := c.FindGroup(s44.GroupSyncMsg.GetGrpCode()); group != nil {
|
||||||
if lastJoinTime < m.JoinTime {
|
group.lock.Lock()
|
||||||
lastJoinTime = m.JoinTime
|
defer group.lock.Unlock()
|
||||||
}
|
|
||||||
}
|
var lastJoinTime int64 = 0
|
||||||
if newMem, err := c.GetGroupMembers(group); err == nil {
|
for _, m := range group.Members {
|
||||||
group.Members = newMem
|
if lastJoinTime < m.JoinTime {
|
||||||
for _, m := range newMem {
|
lastJoinTime = m.JoinTime
|
||||||
if lastJoinTime < m.JoinTime {
|
}
|
||||||
go c.dispatchNewMemberEvent(&MemberJoinGroupEvent{
|
}
|
||||||
Group: group,
|
|
||||||
Member: m,
|
if newMem, err := c.GetGroupMembers(group); err == nil {
|
||||||
})
|
group.Members = newMem
|
||||||
}
|
for _, m := range newMem {
|
||||||
}
|
if lastJoinTime < m.JoinTime {
|
||||||
}
|
go c.dispatchNewMemberEvent(&MemberJoinGroupEvent{
|
||||||
|
Group: group,
|
||||||
|
Member: m,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -353,19 +353,3 @@ func decodeGroupShortVideoUploadResponse(_ *QQClient, _ *incomingPacketInfo, pay
|
|||||||
}
|
}
|
||||||
return rsp.PttShortVideoUploadRsp, nil
|
return rsp.PttShortVideoUploadRsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func constructPTTExtraInfo(codec, length int32) []byte {
|
|
||||||
return binary.NewWriterF(func(w *binary.Writer) {
|
|
||||||
w.WriteByte(3)
|
|
||||||
w.WriteByte(8)
|
|
||||||
w.WriteUInt16(4)
|
|
||||||
w.WriteUInt32(uint32(codec))
|
|
||||||
w.WriteByte(9)
|
|
||||||
w.WriteUInt16(4)
|
|
||||||
w.WriteUInt32(uint32(14)) // length 时间
|
|
||||||
w.WriteByte(10)
|
|
||||||
info := []byte{0x08, 0x00, 0x28, 0x00, 0x38, 0x00} // todo
|
|
||||||
w.WriteUInt16(uint16(len(info)))
|
|
||||||
w.Write(info)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -4,7 +4,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -144,7 +144,8 @@ func (c *QQClient) bigDataRequest(subCmd uint32, req proto.Message) ([]byte, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "request error")
|
return nil, errors.Wrap(err, "request error")
|
||||||
}
|
}
|
||||||
rspBody, _ := ioutil.ReadAll(rsp.Body)
|
defer rsp.Body.Close()
|
||||||
|
rspBody, _ := io.ReadAll(rsp.Body)
|
||||||
r := binary.NewReader(rspBody)
|
r := binary.NewReader(rspBody)
|
||||||
r.ReadByte()
|
r.ReadByte()
|
||||||
l1 := int(r.ReadInt32())
|
l1 := int(r.ReadInt32())
|
||||||
|
@ -430,7 +430,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
|
|||||||
}
|
}
|
||||||
if content != "" {
|
if content != "" {
|
||||||
if elem.RichMsg.GetServiceId() == 35 {
|
if elem.RichMsg.GetServiceId() == 35 {
|
||||||
reg := regexp.MustCompile(`m_resid="(\w+?.*?)"`)
|
reg := regexp.MustCompile(`m_resid="(.+)"`)
|
||||||
sub := reg.FindAllStringSubmatch(content, -1)
|
sub := reg.FindAllStringSubmatch(content, -1)
|
||||||
if len(sub) > 0 && len(sub[0]) > 1 {
|
if len(sub) > 0 && len(sub[0]) > 1 {
|
||||||
res = append(res, &ForwardElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]})
|
res = append(res, &ForwardElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]})
|
||||||
|
@ -230,7 +230,6 @@ func (e *GroupShowPicElement) Pack() (r []*msg.Elem) {
|
|||||||
Size: &e.Size,
|
Size: &e.Size,
|
||||||
Md5: e.Md5,
|
Md5: e.Md5,
|
||||||
Flag: []byte{0x11, 0x00, 0x00, 0x00},
|
Flag: []byte{0x11, 0x00, 0x00, 0x00},
|
||||||
// OldData: imgOld,
|
|
||||||
PbReserve: reserve,
|
PbReserve: reserve,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package tlv
|
package tlv
|
||||||
|
|
||||||
func GuidFlag() uint32 {
|
func GuidFlag() uint32 {
|
||||||
var flag uint32 = 0
|
var flag uint32
|
||||||
flag |= 1 << 24 & 0xFF000000
|
flag |= 1 << 24 & 0xFF000000
|
||||||
flag |= 0 << 8 & 0xFF00
|
flag |= 0 << 8 & 0xFF00
|
||||||
return flag
|
return flag
|
||||||
|
@ -31,7 +31,7 @@ func ComputeMd5AndLength(r io.Reader) ([]byte, int64) {
|
|||||||
h := md5.New()
|
h := md5.New()
|
||||||
length, _ := io.Copy(h, r)
|
length, _ := io.Copy(h, r)
|
||||||
fh := h.Sum(nil)
|
fh := h.Sum(nil)
|
||||||
return fh[:], length
|
return fh, length
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *multiReadSeeker) Read(p []byte) (int, error) {
|
func (r *multiReadSeeker) Read(p []byte) (int, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user