diff --git a/binary/utils.go b/binary/utils.go index 9267fff3..2c3895d0 100644 --- a/binary/utils.go +++ b/binary/utils.go @@ -20,9 +20,15 @@ func ZlibUncompress(src []byte) []byte { func CalculateImageResourceId(md5 []byte) string { return strings.ToUpper(fmt.Sprintf( - "{%s-%s-%s-%s-%s}.png", - hex.EncodeToString(md5[0:4]), hex.EncodeToString(md5[4:6]), hex.EncodeToString(md5[6:8]), - hex.EncodeToString(md5[8:10]), hex.EncodeToString(md5[10:]), + "{%s}.png", GenUUID(md5), + )) +} + +func GenUUID(h []byte) string { + return strings.ToUpper(fmt.Sprintf( + "%s-%s-%s-%s-%s", + hex.EncodeToString(h[0:4]), hex.EncodeToString(h[4:6]), hex.EncodeToString(h[6:8]), + hex.EncodeToString(h[8:10]), hex.EncodeToString(h[10:]), )) } diff --git a/client/global.go b/client/global.go index cc251295..3ab40f74 100644 --- a/client/global.go +++ b/client/global.go @@ -2,10 +2,12 @@ package client import ( "crypto/md5" + "encoding/json" "github.com/Mrs4s/MiraiGo/binary" devinfo "github.com/Mrs4s/MiraiGo/client/pb" "github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/MiraiGo/utils" "google.golang.org/protobuf/proto" "math/rand" "sort" @@ -45,12 +47,21 @@ type Version struct { Sdk uint32 } +type DeviceInfoFile struct { + Display string `json:"display"` + FingerPrint string `json:"finger_print"` + BootId string `json:"boot_id"` + ProcVersion string `json:"proc_version"` + IMEI string `json:"imei"` +} + type groupMessageBuilder struct { MessageSeq int32 MessageCount int32 MessageSlices []*msg.Message } +// default var SystemDeviceInfo = &DeviceInfo{ Display: []byte("MIRAI.123456.001"), Product: []byte("mirai"), @@ -81,6 +92,7 @@ var SystemDeviceInfo = &DeviceInfo{ } var EmptyBytes = []byte{} +var NumberRange = "0123456789" func init() { r := make([]byte, 16) @@ -91,6 +103,50 @@ func init() { SystemDeviceInfo.GenNewTgtgtKey() } +func GenRandomDevice() { + r := make([]byte, 16) + rand.Read(r) + SystemDeviceInfo.Display = []byte("MIRAI." + utils.RandomStringRange(6, NumberRange) + ".001") + SystemDeviceInfo.FingerPrint = []byte("mamoe/mirai/mirai:10/MIRAI.200122.001/" + utils.RandomStringRange(7, NumberRange) + ":user/release-keys") + SystemDeviceInfo.BootId = []byte(binary.GenUUID(r)) + SystemDeviceInfo.ProcVersion = []byte("Linux version 3.0.31-" + utils.RandomString(8) + " (android-build@xxx.xxx.xxx.xxx.com)") + rand.Read(r) + t := md5.Sum(r) + SystemDeviceInfo.IMSIMd5 = t[:] + SystemDeviceInfo.IMEI = utils.RandomStringRange(15, NumberRange) + SystemDeviceInfo.AndroidId = SystemDeviceInfo.Display + SystemDeviceInfo.GenNewGuid() + SystemDeviceInfo.GenNewTgtgtKey() +} + +func (info *DeviceInfo) ToJson() []byte { + f := &DeviceInfoFile{ + Display: string(info.Display), + FingerPrint: string(info.FingerPrint), + BootId: string(info.BootId), + ProcVersion: string(info.ProcVersion), + IMEI: info.IMEI, + } + d, _ := json.Marshal(f) + return d +} + +func (info *DeviceInfo) ReadJson(d []byte) error { + var f DeviceInfoFile + if err := json.Unmarshal(d, &f); err != nil { + return err + } + info.Display = []byte(f.Display) + info.FingerPrint = []byte(f.FingerPrint) + info.BootId = []byte(f.BootId) + info.ProcVersion = []byte(f.ProcVersion) + info.IMEI = f.IMEI + info.AndroidId = SystemDeviceInfo.Display + SystemDeviceInfo.GenNewGuid() + SystemDeviceInfo.GenNewTgtgtKey() + return nil +} + func (info *DeviceInfo) GenNewGuid() { t := md5.Sum(append(info.AndroidId, info.MacAddress...)) info.Guid = t[:] diff --git a/message/elements.go b/message/elements.go index 670a0b0b..294cede0 100644 --- a/message/elements.go +++ b/message/elements.go @@ -41,12 +41,6 @@ func NewText(s string) *TextElement { return &TextElement{Content: s} } -func NewImage(data []byte) *ImageElement { - return &ImageElement{ - Data: data, - } -} - func NewGroupImage(id string, md5 []byte) *GroupImageElement { return &GroupImageElement{ ImageId: id, diff --git a/utils/string.go b/utils/string.go index ea6de605..f4bd74dc 100644 --- a/utils/string.go +++ b/utils/string.go @@ -7,8 +7,11 @@ import ( ) func RandomString(len int) string { + return RandomStringRange(len, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") +} + +func RandomStringRange(len int, str string) string { var res string - var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" b := bytes.NewBufferString(str) length := b.Len() bigInt := big.NewInt(int64(length))