From ecd5a7b430240b8a09523c040fd3e8544bd35b71 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Tue, 26 Jan 2021 03:40:55 +0800 Subject: [PATCH] Revert "SpeedUP Rand" --- .github/workflows/go.yml | 22 +++++++------- README.md | 4 +-- binary/tea.go | 4 +-- binary/tea_test.go | 52 ---------------------------------- client/builders.go | 7 ++--- client/client.go | 10 +++---- client/global.go | 9 +++--- client/group_msg.go | 6 ++-- client/pb/oidb/oidb0xb77.proto | 2 +- client/richmsg.go | 2 +- go.mod | 1 - go.sum | 2 -- protocol/tlv/t1.go | 2 +- protocol/tlv/t106.go | 2 +- 14 files changed, 34 insertions(+), 91 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a51b4496..c7b0db0f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,20 +13,20 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ^1.13 + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.13 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Check out code into the Go module directory + uses: actions/checkout@v2 - - name: Get dependencies - run: | - go get -v -t -d ./... + - name: Get dependencies + run: | + go get -v -t -d ./... - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... # - name: Test # run: go test -v . diff --git a/README.md b/README.md index 1e21e992..f87f4b14 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ qq-android协议的golang实现 移植于mirai - [x] 登录号加群 - [x] 登录号退群(包含T出) - [x] 新成员进群/退群 -- [x] 群/好友消息撤回 +- [x] 群/好友消息撤回 - [x] 群禁言 - [x] 群成员权限变更 - [x] 收到邀请进群通知 @@ -44,7 +44,7 @@ qq-android协议的golang实现 移植于mirai - [x] 新好友 - [x] 新好友请求 - [x] 客户端离线 -- [x] 群提示 (戳一戳/运气王等) +- [x] 群提示 (戳一戳/运气王等) #### 主动操作 > 为防止滥用,将不支持主动邀请新成员进群 diff --git a/binary/tea.go b/binary/tea.go index 70b7cfaa..005f4ca1 100644 --- a/binary/tea.go +++ b/binary/tea.go @@ -2,11 +2,9 @@ package binary import ( "encoding/binary" - //"math/rand" + "math/rand" "reflect" "unsafe" - - rand "github.com/LXY1226/fastrand" ) func xorQ(a, b []byte, c []byte) { // MAGIC diff --git a/binary/tea_test.go b/binary/tea_test.go index 3f7b8a99..8bf4a07b 100644 --- a/binary/tea_test.go +++ b/binary/tea_test.go @@ -99,58 +99,6 @@ func BenchmarkTEAde16(b *testing.B) { } } -func BenchmarkTEAen200(b *testing.B) { - data := make([]byte, 200) - _, err := rand.Read(data) - if err != nil { - panic(err) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - testTEA.Encrypt(data) - } -} - -func BenchmarkTEAde200(b *testing.B) { - data := make([]byte, 200) - _, err := rand.Read(data) - if err != nil { - panic(err) - } - data = testTEA.Encrypt(data) - b.ResetTimer() - for i := 0; i < b.N; i++ { - testTEA.Decrypt(data) - } -} - -func BenchmarkTEAen200M(b *testing.B) { - b.RunParallel(func(pb *testing.PB) { - data := make([]byte, 200) - _, err := rand.Read(data) - if err != nil { - panic(err) - } - for pb.Next() { - testTEA.Encrypt(data) - } - }) -} - -func BenchmarkTEAde200M(b *testing.B) { - b.RunParallel(func(pb *testing.PB) { - data := make([]byte, 200) - _, err := rand.Read(data) - if err != nil { - panic(err) - } - data = testTEA.Encrypt(data) - for pb.Next() { - testTEA.Decrypt(data) - } - }) -} - func BenchmarkTEAen256(b *testing.B) { data := make([]byte, 256) _, err := rand.Read(data) diff --git a/client/builders.go b/client/builders.go index c7173ab5..e6c8bd15 100644 --- a/client/builders.go +++ b/client/builders.go @@ -3,10 +3,11 @@ package client import ( "encoding/hex" "fmt" + "github.com/Mrs4s/MiraiGo/client/pb/profilecard" + "github.com/Mrs4s/MiraiGo/client/pb/qweb" + "math/rand" "time" - rand "github.com/LXY1226/fastrand" - "github.com/golang/protobuf/proto" "github.com/Mrs4s/MiraiGo/binary" @@ -15,8 +16,6 @@ import ( "github.com/Mrs4s/MiraiGo/client/pb/cmd0x352" "github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/oidb" - "github.com/Mrs4s/MiraiGo/client/pb/profilecard" - "github.com/Mrs4s/MiraiGo/client/pb/qweb" "github.com/Mrs4s/MiraiGo/client/pb/structmsg" "github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/protocol/crypto" diff --git a/client/client.go b/client/client.go index e239ef5e..b91fab45 100644 --- a/client/client.go +++ b/client/client.go @@ -4,11 +4,11 @@ import ( "bytes" "crypto/md5" "fmt" - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/binary/jce" jsoniter "github.com/json-iterator/go" "io" "math" + "math/rand" "net" "runtime/debug" "sort" @@ -149,9 +149,9 @@ var decoders = map[string]func(*QQClient, uint16, []byte) (interface{}, error){ "PttCenterSvr.pb_pttCenter_CMD_REQ_APPLY_UPLOAD-500": decodePrivatePttStoreResponse, } -//func init() { -// rand.Seed(time.Now().UTC().UnixNano()) -//} +func init() { + rand.Seed(time.Now().UTC().UnixNano()) +} // NewClient create new qq client func NewClient(uin int64, password string) *QQClient { @@ -167,7 +167,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient { OutGoingPacketSessionId: []byte{0x02, 0xB0, 0x5B, 0x8B}, sigInfo: &loginSigInfo{}, requestPacketRequestId: 1921334513, - groupSeq: rand.Int31n(20000), + groupSeq: int32(rand.Intn(20000)), friendSeq: 22911, highwayApplyUpSeq: 77918, ksid: []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", SystemDeviceInfo.IMEI)), diff --git a/client/global.go b/client/global.go index 81fef894..5f96c49e 100644 --- a/client/global.go +++ b/client/global.go @@ -6,13 +6,14 @@ import ( "encoding/hex" "encoding/xml" "fmt" + "github.com/Mrs4s/MiraiGo/client/pb/oidb" + "math/rand" "net" "sort" "strconv" "strings" "time" - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary/jce" devinfo "github.com/Mrs4s/MiraiGo/client/pb" @@ -367,11 +368,11 @@ func GenIMEI() string { sum := 0 // the control sum of digits var final strings.Builder - //randSrc := rand.NewSource(time.Now().UnixNano()) - //randGen := rand.New(randSrc) + randSrc := rand.NewSource(time.Now().UnixNano()) + randGen := rand.New(randSrc) for i := 0; i < 14; i++ { // generating all the base digits - toAdd := rand.Intn(10) + toAdd := randGen.Intn(10) if (i+1)%2 == 0 { // special proc for every 2nd one toAdd *= 2 if toAdd >= 10 { diff --git a/client/group_msg.go b/client/group_msg.go index 82e99601..e55c4403 100644 --- a/client/group_msg.go +++ b/client/group_msg.go @@ -3,7 +3,6 @@ package client import ( "encoding/base64" "fmt" - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/client/pb/longmsg" "github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/multimsg" @@ -14,6 +13,7 @@ import ( "github.com/pkg/errors" "google.golang.org/protobuf/proto" "math" + "math/rand" "time" ) @@ -93,7 +93,7 @@ func (c *QQClient) GetAtAllRemain(groupCode int64) (*AtAllRemainInfo, error) { func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.SendingMessage) *message.GroupMessage { eid := utils.RandomString(6) - mr := rand.Int31() + mr := int32(rand.Uint32()) ch := make(chan int32) c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) { if e.Rand == mr && !utils.IsChanClosed(ch) { @@ -113,7 +113,7 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se } return ok || ok2 || ok3 }) { - div := rand.Int31() + div := int32(rand.Uint32()) fragmented := m.ToFragmented() for i, elems := range fragmented { _, pkt := c.buildGroupSendingPacket(groupCode, mr, int32(len(fragmented)), int32(i), div, forward, elems) diff --git a/client/pb/oidb/oidb0xb77.proto b/client/pb/oidb/oidb0xb77.proto index 8ea654d3..240a8422 100644 --- a/client/pb/oidb/oidb0xb77.proto +++ b/client/pb/oidb/oidb0xb77.proto @@ -34,7 +34,7 @@ message DB77ExtInfo { message DB77RichMsgBody { string title = 10; - string summary = 11; + string summary = 11; string brief = 12; string url = 13; string pictureUrl = 14; diff --git a/client/richmsg.go b/client/richmsg.go index 6683dc73..29665dac 100644 --- a/client/richmsg.go +++ b/client/richmsg.go @@ -1,9 +1,9 @@ package client import ( + "math/rand" "time" - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/client/pb/oidb" "github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/protocol/packets" diff --git a/go.mod b/go.mod index c02e66ab..54a080cb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/Mrs4s/MiraiGo go 1.15 require ( - github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031 github.com/golang/protobuf v1.4.3 github.com/json-iterator/go v1.1.10 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 34336636..0f710ceb 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031 h1:DnoCySrXUFvtngW2kSkuBeZoPfvOgctJXjTulCn7eV0= -github.com/LXY1226/fastrand v0.0.0-20210121160840-7a3db3e79031/go.mod h1:mEFi4jHUsE2sqQGSJ7eQfXnO8esMzEYcftiCGG+L/OE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/protocol/tlv/t1.go b/protocol/tlv/t1.go index 4af317b7..3e8875d2 100644 --- a/protocol/tlv/t1.go +++ b/protocol/tlv/t1.go @@ -1,8 +1,8 @@ package tlv import ( - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/binary" + "math/rand" "time" ) diff --git a/protocol/tlv/t106.go b/protocol/tlv/t106.go index 2383d316..699f166b 100644 --- a/protocol/tlv/t106.go +++ b/protocol/tlv/t106.go @@ -3,8 +3,8 @@ package tlv import ( "crypto/md5" binary2 "encoding/binary" - rand "github.com/LXY1226/fastrand" "github.com/Mrs4s/MiraiGo/binary" + "math/rand" "strconv" "time" )