From 85129aa06c1619f0c753d659b985ce8a5b13d743 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Fri, 10 Mar 2023 21:54:44 +0800 Subject: [PATCH] support manual update AppVersion --- client/entities.go | 2 +- client/global.go | 7 + client/internal/auth/auth.go | 268 +++++++++++++----------- client/internal/auth/device.go | 4 +- client/internal/auth/protocol_string.go | 29 --- 5 files changed, 159 insertions(+), 151 deletions(-) delete mode 100644 client/internal/auth/protocol_string.go diff --git a/client/entities.go b/client/entities.go index 9eafbcf0..463d1cb9 100644 --- a/client/entities.go +++ b/client/entities.go @@ -23,7 +23,7 @@ type ( UserOnlineStatus int - ClientProtocol = auth.Protocol + ClientProtocol = auth.ProtocolType LoginResponse struct { Success bool diff --git a/client/global.go b/client/global.go index 5cb62e57..0dcf7a7c 100644 --- a/client/global.go +++ b/client/global.go @@ -105,6 +105,13 @@ func GenIMEI() string { return final.String() } +func UpdateAppVersion(protocolType auth.ProtocolType, data []byte) error { + if _, ok := auth.AppVersions[protocolType]; !ok { + return errors.New("unknown protocol type: " + strconv.Itoa(int(protocolType))) + } + return auth.AppVersions[protocolType].ReadJson(data) +} + func getSSOAddress(device *auth.Device) ([]netip.AddrPort, error) { protocol := device.Protocol.Version() key, _ := hex.DecodeString("F0441F5FF42DA58FDCF7949ABA62D411") diff --git a/client/internal/auth/auth.go b/client/internal/auth/auth.go index eac19e60..a36dc329 100644 --- a/client/internal/auth/auth.go +++ b/client/internal/auth/auth.go @@ -1,16 +1,117 @@ package auth -//go:generate stringer -type=Protocol -linecomment -type Protocol int +import ( + "encoding/hex" + "encoding/json" + "fmt" + + "github.com/pkg/errors" +) + +//go:generate stringer -type=ProtocolType -linecomment +type ProtocolType int const ( - Unset Protocol = iota - AndroidPhone // Android Phone - AndroidWatch // Android Watch - MacOS // MacOS - QiDian // 企点 - IPad // iPad - AndroidPad // Android Pad + Unset ProtocolType = iota + AndroidPhone // Android Phone + AndroidWatch // Android Watch + MacOS // MacOS + QiDian // 企点 + IPad // iPad + AndroidPad // Android Pad +) + +var ( + AppVersions = map[ProtocolType]*AppVersion{ + AndroidPhone: { + ApkId: "com.tencent.mobileqq", + AppId: 537151682, + SubAppId: 537151682, + SortVersionName: "8.9.33.10335", + BuildTime: 1673599898, + ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, + SdkVersion: "6.0.0.2534", + SSOVersion: 19, + MiscBitmap: 150470524, + SubSigmap: 0x10400, + MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | + WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | + WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 + Protocol: AndroidPhone, + }, + AndroidPad: { + ApkId: "com.tencent.mobileqq", + AppId: 537151218, + SubAppId: 537151218, + SortVersionName: "8.9.33.10335", + BuildTime: 1673599898, + ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, + SdkVersion: "6.0.0.2534", + SSOVersion: 19, + MiscBitmap: 150470524, + SubSigmap: 0x10400, + MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | + WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | + WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 + Protocol: AndroidPad, + }, + AndroidWatch: { + ApkId: "com.tencent.qqlite", + AppId: 537064446, + SubAppId: 537064446, + SortVersionName: "2.0.5", + BuildTime: 1559564731, + ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, + SdkVersion: "6.0.0.236", + SSOVersion: 5, + MiscBitmap: 16252796, + SubSigmap: 0x10400, + MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_D2 | WLOGIN_PSKEY | WLOGIN_DA2, // 34869472 + Protocol: AndroidWatch, + }, + IPad: { + ApkId: "com.tencent.minihd.qq", + AppId: 537118796, + SubAppId: 537118796, + SortVersionName: "5.9.3", + BuildTime: 1595836208, + ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, + SdkVersion: "6.0.0.2433", + SSOVersion: 12, + MiscBitmap: 150470524, + SubSigmap: 66560, + MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 + Protocol: IPad, + }, + MacOS: { + ApkId: "com.tencent.minihd.qq", + AppId: 537128930, + SubAppId: 537128930, + SortVersionName: "5.8.9", + BuildTime: 1595836208, + ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, + SdkVersion: "6.0.0.2433", + SSOVersion: 12, + MiscBitmap: 150470524, + SubSigmap: 66560, + MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 + Protocol: MacOS, + }, + QiDian: { + ApkId: "com.tencent.qidian", + AppId: 537096038, + SubAppId: 537036590, + SortVersionName: "5.0.0", + BuildTime: 1630062176, + ApkSign: []byte{160, 30, 236, 171, 133, 233, 227, 186, 43, 15, 106, 21, 140, 133, 92, 41}, + SdkVersion: "6.0.0.2484", + SSOVersion: 18, + MiscBitmap: 184024956, + SubSigmap: 66560, + MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_D2 | WLOGIN_PSKEY | WLOGIN_DA2, // 34869472 + Protocol: QiDian, + }, + } ) // see oicq/wlogin_sdk/request/WtloginHelper.java class SigType @@ -57,123 +158,37 @@ type AppVersion struct { MiscBitmap uint32 SubSigmap uint32 MainSigMap uint32 - Protocol Protocol + Protocol ProtocolType } -var ( - aPhone = &AppVersion{ - ApkId: "com.tencent.mobileqq", - AppId: 537151682, - SubAppId: 537151682, - SortVersionName: "8.9.33.10335", - BuildTime: 1673599898, - ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, - SdkVersion: "6.0.0.2534", - SSOVersion: 19, - MiscBitmap: 150470524, - SubSigmap: 0x10400, - MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | - WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | - WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 - Protocol: AndroidPhone, - } +func (v *AppVersion) String() string { + return fmt.Sprintf("%s %s - %v", v.Protocol, v.SortVersionName, v.BuildTime) +} - aPad = &AppVersion{ - ApkId: "com.tencent.mobileqq", - AppId: 537151218, - SubAppId: 537151218, - SortVersionName: "8.9.33.10335", - BuildTime: 1673599898, - ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, - SdkVersion: "6.0.0.2534", - SSOVersion: 19, - MiscBitmap: 150470524, - SubSigmap: 0x10400, - MainSigMap: WLOGIN_A5 | WLOGIN_RESERVED | WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | - WLOGIN_LSKEY | WLOGIN_SKEY | WLOGIN_SIG64 | 1<<16 | WLOGIN_VKEY | WLOGIN_D2 | - WLOGIN_SID | WLOGIN_PSKEY | WLOGIN_AQSIG | WLOGIN_LHSIG | WLOGIN_PAYTOKEN, // 16724722 - Protocol: AndroidPad, - } - - aWatch = &AppVersion{ - ApkId: "com.tencent.qqlite", - AppId: 537064446, - SubAppId: 537064446, - SortVersionName: "2.0.5", - BuildTime: 1559564731, - ApkSign: []byte{0xA6, 0xB7, 0x45, 0xBF, 0x24, 0xA2, 0xC2, 0x77, 0x52, 0x77, 0x16, 0xF6, 0xF3, 0x6E, 0xB6, 0x8D}, - SdkVersion: "6.0.0.236", - SSOVersion: 5, - MiscBitmap: 16252796, - SubSigmap: 0x10400, - MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_D2 | WLOGIN_PSKEY | WLOGIN_DA2, // 34869472 - Protocol: AndroidWatch, - } - - ipad = &AppVersion{ - ApkId: "com.tencent.minihd.qq", - AppId: 537118796, - SubAppId: 537118796, - SortVersionName: "5.9.3", - BuildTime: 1595836208, - ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, - SdkVersion: "6.0.0.2433", - SSOVersion: 12, - MiscBitmap: 150470524, - SubSigmap: 66560, - MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 - Protocol: IPad, - } - - macOS = &AppVersion{ - ApkId: "com.tencent.minihd.qq", - AppId: 537128930, - SubAppId: 537128930, - SortVersionName: "5.8.9", - BuildTime: 1595836208, - ApkSign: []byte{170, 57, 120, 244, 31, 217, 111, 249, 145, 74, 102, 158, 24, 100, 116, 199}, - SdkVersion: "6.0.0.2433", - SSOVersion: 12, - MiscBitmap: 150470524, - SubSigmap: 66560, - MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_VKEY | WLOGIN_D2 | WLOGIN_SID | WLOGIN_PSKEY, // 1970400 - Protocol: MacOS, - } - - qidian = &AppVersion{ - ApkId: "com.tencent.qidian", - AppId: 537096038, - SubAppId: 537036590, - SortVersionName: "5.0.0", - BuildTime: 1630062176, - ApkSign: []byte{160, 30, 236, 171, 133, 233, 227, 186, 43, 15, 106, 21, 140, 133, 92, 41}, - SdkVersion: "6.0.0.2484", - SSOVersion: 18, - MiscBitmap: 184024956, - SubSigmap: 66560, - MainSigMap: WLOGIN_STWEB | WLOGIN_A2 | WLOGIN_ST | WLOGIN_SKEY | WLOGIN_D2 | WLOGIN_PSKEY | WLOGIN_DA2, // 34869472 - Protocol: QiDian, - } -) - -func (i Protocol) Version() *AppVersion { - switch i { - case AndroidPhone: - return aPhone - case AndroidPad: - return aPad - case AndroidWatch: - return aWatch - case IPad: - return ipad - case MacOS: - return macOS - case QiDian: - return qidian +func (v *AppVersion) ReadJson(d []byte) error { + var f appVersionFile + if err := json.Unmarshal(d, &f); err != nil { + return errors.Wrap(err, "failed to unmarshal json message") } + v.ApkId = f.ApkId + v.AppId = f.AppId + v.SubAppId = f.SubAppId + v.SortVersionName = f.SortVersionName + v.BuildTime = f.BuildTime + v.ApkSign, _ = hex.DecodeString(f.ApkSign) + v.SdkVersion = f.SdkVersion + v.SSOVersion = f.SSOVersion + v.MiscBitmap = f.MiscBitmap + v.SubSigmap = f.SubSigmap + v.MainSigMap = f.MainSigMap + v.Protocol = f.ProtocolType return nil } +func (i ProtocolType) Version() *AppVersion { + return AppVersions[i] +} + type SigInfo struct { LoginBitmap uint64 TGT []byte @@ -216,3 +231,18 @@ type SigInfo struct { Ksid []byte // msgCtrlBuf []byte } + +type appVersionFile struct { + ApkId string `json:"apk_id"` + AppId uint32 `json:"app_id"` + SubAppId uint32 `json:"sub_app_id"` + SortVersionName string `json:"sort_version_name"` + BuildTime uint32 `json:"build_time"` + ApkSign string `json:"apk_sign"` // hex encoded + SdkVersion string `json:"sdk_version"` + SSOVersion uint32 `json:"sso_version"` + MiscBitmap uint32 `json:"misc_bitmap"` + MainSigMap uint32 `json:"main_sig_map"` + SubSigmap uint32 `json:"sub_sig_map"` + ProtocolType ProtocolType `json:"protocol_type"` +} diff --git a/client/internal/auth/device.go b/client/internal/auth/device.go index 8bd06ae8..05e0b37d 100644 --- a/client/internal/auth/device.go +++ b/client/internal/auth/device.go @@ -45,7 +45,7 @@ type Device struct { VendorOSName []byte Guid []byte TgtgtKey []byte - Protocol Protocol + Protocol ProtocolType Version *OSVersion } @@ -135,7 +135,7 @@ func (info *Device) ReadJson(d []byte) error { switch f.Protocol { case 1, 2, 3, 4, 5, 6: - info.Protocol = Protocol(f.Protocol) + info.Protocol = ProtocolType(f.Protocol) default: info.Protocol = AndroidPad } diff --git a/client/internal/auth/protocol_string.go b/client/internal/auth/protocol_string.go deleted file mode 100644 index 2f8deec6..00000000 --- a/client/internal/auth/protocol_string.go +++ /dev/null @@ -1,29 +0,0 @@ -// Code generated by "stringer -type=Protocol -linecomment"; DO NOT EDIT. - -package auth - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[Unset-0] - _ = x[AndroidPhone-1] - _ = x[AndroidWatch-2] - _ = x[MacOS-3] - _ = x[QiDian-4] - _ = x[IPad-5] - _ = x[AndroidPad-6] -} - -const _Protocol_name = "UnsetAndroid PhoneAndroid WatchMacOS企点iPadAndroid Pad" - -var _Protocol_index = [...]uint8{0, 5, 18, 31, 36, 42, 46, 57} - -func (i Protocol) String() string { - if i < 0 || i >= Protocol(len(_Protocol_index)-1) { - return "Protocol(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Protocol_name[_Protocol_index[i]:_Protocol_index[i+1]] -}