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

SpeedUP Rand

This commit is contained in:
Lin 2021-01-22 00:14:01 +08:00
parent 83f2eb02e6
commit aa6ed0fc34
14 changed files with 94 additions and 36 deletions

View File

@ -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 .

View File

@ -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] 群提示 (戳一戳/运气王等)
#### 主动操作
> 为防止滥用,将不支持主动邀请新成员进群

View File

@ -2,9 +2,11 @@ package binary
import (
"encoding/binary"
"math/rand"
//"math/rand"
"reflect"
"unsafe"
rand "github.com/LXY1226/fastrand"
)
func xorQ(a, b []byte, c []byte) { // MAGIC

View File

@ -99,6 +99,58 @@ 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)

View File

@ -4,11 +4,10 @@ import (
"crypto/md5"
"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"
@ -17,6 +16,8 @@ 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"

View File

@ -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"
@ -145,9 +145,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 {
@ -163,7 +163,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient {
OutGoingPacketSessionId: []byte{0x02, 0xB0, 0x5B, 0x8B},
sigInfo: &loginSigInfo{},
requestPacketRequestId: 1921334513,
groupSeq: int32(rand.Intn(20000)),
groupSeq: rand.Int31n(20000),
friendSeq: 22911,
highwayApplyUpSeq: 77918,
ksid: []byte(fmt.Sprintf("|%s|A8.2.7.27f6ea96", SystemDeviceInfo.IMEI)),
@ -427,7 +427,7 @@ func (c *QQClient) GetFriendList() (*FriendListResponse, error) {
}
func (c *QQClient) SendPrivateMessage(target int64, m *message.SendingMessage) *message.PrivateMessage {
mr := int32(rand.Uint32())
mr := rand.Int31()
seq := c.nextFriendSeq()
t := time.Now().Unix()
imgCount := m.Count(func(e message.IMessageElement) bool { return e.Type() == message.Image })
@ -436,7 +436,7 @@ func (c *QQClient) SendPrivateMessage(target int64, m *message.SendingMessage) *
return nil
}
if msgLen > 300 || imgCount > 2 {
div := int32(rand.Uint32())
div := rand.Int31()
fragmented := m.ToFragmented()
for i, elems := range fragmented {
_, pkt := c.buildFriendSendingPacket(target, c.nextFriendSeq(), mr, int32(len(fragmented)), int32(i), div, t, elems)
@ -476,7 +476,7 @@ func (c *QQClient) SendTempMessage(groupCode, target int64, m *message.SendingMe
Elements: m.Elements,
}
}
mr := int32(rand.Uint32())
mr := rand.Int31()
seq := c.nextFriendSeq()
t := time.Now().Unix()
_, pkt := c.buildTempSendingPacket(group.Uin, target, seq, mr, t, m)

View File

@ -7,13 +7,13 @@ import (
"encoding/hex"
"encoding/xml"
"fmt"
"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"
@ -368,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 := randGen.Intn(10)
toAdd := rand.Intn(10)
if (i+1)%2 == 0 { // special proc for every 2nd one
toAdd *= 2
if toAdd >= 10 {

View File

@ -2,6 +2,7 @@ package client
import (
"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"
@ -12,7 +13,6 @@ import (
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"math"
"math/rand"
"time"
)
@ -85,7 +85,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 := int32(rand.Uint32())
mr := rand.Int31()
ch := make(chan int32)
c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) {
if e.Rand == mr && !utils.IsChanClosed(ch) {
@ -105,7 +105,7 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se
}
return ok || ok2 || ok3
}) {
div := int32(rand.Uint32())
div := rand.Int31()
fragmented := m.ToFragmented()
for i, elems := range fragmented {
_, pkt := c.buildGroupSendingPacket(groupCode, mr, int32(len(fragmented)), int32(i), div, forward, elems)

View File

@ -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;

View File

@ -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"

1
go.mod
View File

@ -3,6 +3,7 @@ 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

2
go.sum
View File

@ -1,5 +1,7 @@
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=

View File

@ -1,8 +1,8 @@
package tlv
import (
rand "github.com/LXY1226/fastrand"
"github.com/Mrs4s/MiraiGo/binary"
"math/rand"
"time"
)

View File

@ -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"
)