chore: switch to sdgb 1.53 fully

This commit is contained in:
2026-01-15 04:42:46 +08:00
parent 69ab1ec4d6
commit b5c6de9c17
9 changed files with 18 additions and 165 deletions

View File

@@ -1,22 +0,0 @@
#![feature(test)]
extern crate test;
use sdgb_api::title::{MaiVersionExt, Sdgb1_50};
#[bench]
pub fn sdgb_150_enc_short(b: &mut test::Bencher) {
b.iter(|| _ = Sdgb1_50::encode(b"Hello world"));
}
#[bench]
pub fn sdgb_150_enc_4k(b: &mut test::Bencher) {
let data = [1u8; 4096];
b.iter(|| _ = Sdgb1_50::encode(data));
}
#[bench]
pub fn sdgb_150_dec_4k(b: &mut test::Bencher) {
let data = [1u8; 4096];
let enc_data = Sdgb1_50::encode(data).unwrap();
b.iter(|| _ = Sdgb1_50::decode(enc_data.clone()));
}

View File

@@ -9,25 +9,7 @@ use flate2::write::{ZlibDecoder, ZlibEncoder};
use spdlog::debug; use spdlog::debug;
use crate::error::ApiError; use crate::error::ApiError;
use crate::title::{MaiVersion, MaiVersionExt, Sdgb1_50, Sdgb1_53}; use crate::title::{MaiVersion, MaiVersionExt, Sdgb1_53};
impl MaiVersionExt for Sdgb1_50 {
fn decode(mut data: impl AsMut<[u8]>) -> Result<Vec<u8>, ApiError> {
if data.as_mut().is_empty() {
return Err(ApiError::EmptyResponse);
}
debug!("data size: {}", data.as_mut().len());
let decrypted = decrypt(&mut data, Self::AES_KEY, Self::AES_IV)?;
Ok(decompress(decrypted))
}
fn encode(data: impl AsRef<[u8]>) -> Result<Vec<u8>, ApiError> {
let compressed = compress(data)?;
let enc = encrypt(compressed, Self::AES_KEY, Self::AES_IV)?;
Ok(enc)
}
}
impl MaiVersionExt for Sdgb1_53 { impl MaiVersionExt for Sdgb1_53 {
fn decode(mut data: impl AsMut<[u8]>) -> Result<Vec<u8>, ApiError> { fn decode(mut data: impl AsMut<[u8]>) -> Result<Vec<u8>, ApiError> {
@@ -93,101 +75,3 @@ fn decrypt<'ct>(
let result = decryptor.decrypt_padded_mut::<Pkcs7>(data.as_mut())?; let result = decryptor.decrypt_padded_mut::<Pkcs7>(data.as_mut())?;
Ok(result) Ok(result)
} }
#[cfg(test)]
mod _tests {
use crate::title::{Sdgb1_50, encryption::*};
#[test]
fn test_ping_dec() -> Result<(), ApiError> {
let mut data = b"\x72\x5c\xa5\x55\x27\x14\x85\xd1\x64\xc8\x64\x5b\x6e\x5f\xd8\xe3\
\x3f\x36\x4c\x9a\x3b\xa5\xb0\x9e\x75\xae\x83\xee\xb3\xb9\x2a\x75"
.to_vec();
let decoded = Sdgb1_50::decode(&mut data)?;
assert_eq!(decoded, b"{\"result\":\"Pong\"}");
Ok(())
}
#[test]
fn test_sdgb_150_dec_enc() -> Result<(), ApiError> {
let data = [
161, 166, 3, 157, 202, 233, 151, 73, 40, 113, 186, 162, 177, 46, 118, 113, 98, 231, 67,
185, 246, 180, 109, 253, 1, 152, 0, 31, 81, 211, 28, 137, 95, 12, 110, 105, 181, 246,
177, 1, 45, 59, 182, 113, 56, 97, 56, 100, 34, 168, 27, 51, 228, 77, 192, 194, 248, 45,
118, 80, 21, 159, 37, 248, 54, 85, 94, 61, 48, 59, 117, 163, 161, 165, 206, 36, 23, 71,
73, 231, 214, 81, 82, 117, 115, 32, 122, 8, 161, 213, 252, 125, 35, 131, 144, 147, 74,
27, 138, 26, 133, 240, 73, 197, 25, 173, 213, 237, 216, 76, 101, 210, 202, 172, 216,
91, 83, 87, 243, 79, 143, 42, 149, 130, 210, 13, 63, 98, 198, 165, 122, 58, 254, 39,
150, 71, 155, 231, 55, 142, 5, 102, 253, 148, 191, 9, 212, 188, 69, 236, 60, 152, 13,
40, 111, 219, 162, 160, 34, 150, 211, 85, 190, 176, 137, 60, 25, 228, 218, 163, 240,
143, 44, 238, 77, 92, 12, 166, 209, 238, 100, 92, 98, 142, 10, 104, 213, 12, 89, 236,
114, 212, 222, 0, 237, 1, 208, 216, 114, 114, 71, 135, 21, 213, 61, 6, 162, 155, 119,
143, 70, 83, 136, 136, 136, 251, 94, 137, 244, 26, 125, 15, 132, 207, 60, 57, 105, 78,
177, 84, 85, 152, 183, 77, 67, 163, 61, 165, 144, 125, 255, 89, 108, 58, 137, 142, 9,
8, 54, 228, 34, 55, 124, 158, 83, 36,
];
let dec = Sdgb1_50::decode(data)?;
assert_eq!(dec, r#"{"userId":10103750,"userName":"舞萌","isLogin":false,"lastGameId":null,"lastRomVersion":"1.01.00","lastDataVersion":"1.05.03","lastLoginDate":"1970-01-01 00:00:00","lastPlayDate":"1970-01-01 00:00:00","playerRating":1024,"nameplateId":0,"iconId":11,"trophyId":0,"isNetMember":1,"isInherit":false,"totalAwake":5,"dispRate":0,"dailyBonusDate":"1970-01-01 09:00:00","headPhoneVolume":null,"banState":0}"#.as_bytes());
let enc = Sdgb1_50::encode(dec)?;
assert_eq!(enc, data);
Ok(())
}
#[test]
fn test_user_data_dec() -> Result<(), ApiError> {
let data = [
112, 133, 192, 229, 116, 195, 219, 220, 56, 176, 98, 148, 246, 73, 179, 157, 181, 251,
9, 7, 190, 113, 101, 8, 144, 58, 23, 196, 16, 176, 78, 96, 106, 53, 191, 118, 86, 247,
50, 250, 168, 155, 164, 108, 7, 152, 251, 123, 186, 121, 113, 41, 104, 79, 29, 71, 47,
228, 214, 97, 223, 29, 27, 163, 159, 113, 82, 45, 29, 41, 176, 246, 33, 235, 22, 202,
1, 61, 133, 126, 8, 20, 9, 214, 153, 11, 203, 207, 5, 195, 129, 172, 70, 81, 58, 156,
240, 87, 203, 137, 110, 183, 245, 177, 210, 63, 231, 136, 82, 97, 201, 184, 236, 117,
89, 85, 22, 29, 2, 238, 250, 148, 158, 151, 139, 179, 9, 42, 47, 220, 88, 137, 135,
139, 57, 35, 0, 50, 123, 133, 103, 15, 87, 86, 208, 203, 235, 153, 214, 87, 236, 46,
78, 50, 72, 50, 8, 46, 30, 242, 44, 184, 72, 118, 51, 120, 99, 158, 247, 255, 168, 181,
119, 156, 214, 143, 253, 185, 21, 76, 117, 201, 38, 38, 79, 171, 8, 251, 90, 53, 59,
89, 30, 136, 69, 168, 57, 34, 115, 145, 159, 110, 182, 5, 126, 208, 202, 216, 92, 200,
168, 63, 114, 119, 129, 38, 139, 189, 101, 215, 102, 76, 29, 228, 219, 46, 79, 166,
127, 194, 60, 183, 169, 167, 210, 120, 77, 219, 58, 16, 231, 233, 189, 66, 215, 202,
28, 209, 59, 192, 141, 91, 65, 17, 187, 88, 189, 149, 139, 48, 237, 152, 161, 87, 120,
99, 2, 50, 12, 120, 179, 50, 235, 255, 223, 162, 216, 84, 13, 135, 196, 131, 121, 97,
171, 106, 240, 189, 112, 92, 41, 59, 204, 24, 72, 91, 14, 220, 249, 10, 166, 4, 254,
183, 194, 227, 53, 163, 35, 165, 253, 149, 83, 253, 191, 138, 236, 208, 146, 242, 31,
185, 152, 226, 100, 191, 2, 2, 82, 101, 141, 31, 71, 106, 2, 83, 1, 231, 140, 20, 16,
156, 171, 108, 109, 14, 93, 168, 203, 50, 20, 21, 142, 135, 97, 7, 80, 61, 110, 76,
152, 106, 231, 100, 78, 187, 28, 39, 191, 10, 206, 78, 127, 79, 247, 192, 164, 51, 237,
9, 63, 201, 7, 27, 81, 243, 88, 30, 244, 205, 57, 14, 126, 60, 61, 173, 21, 84, 15,
105, 38, 239, 249, 82, 202, 245, 219, 88, 195, 112, 113, 40, 60, 76, 10, 243, 232, 52,
27, 0, 84, 247, 85, 140, 99, 140, 165, 145, 140, 96, 55, 0, 174, 155, 241, 166, 252,
150, 87, 106, 42, 58, 33, 154, 222, 83, 69, 172, 226, 216, 108, 115, 203, 38, 133, 43,
171, 172, 78, 142, 70, 78, 186, 146, 24, 126, 203, 106, 221, 144, 17, 32, 42, 186, 125,
134, 186, 174, 214, 137, 212, 234, 202, 79, 241, 28, 222, 98, 83, 76, 254, 90, 210, 12,
141, 40, 191, 123, 143, 170, 154, 39, 137, 222, 224, 241, 61, 136, 184, 104, 106, 209,
184, 128, 30, 95, 36, 250, 163, 47, 82, 19, 121, 123, 134, 142, 31, 170, 23, 148, 20,
80, 157, 252, 103, 192, 204, 229, 10, 66, 84, 49, 21, 197, 110, 208, 202, 124, 217,
117, 19, 190, 241, 154, 178, 83, 37, 175, 209, 52, 228, 219, 137, 238, 146, 111, 228,
254, 89, 219, 49, 85, 30, 214, 162, 234, 138, 122, 9, 93, 164, 133, 136, 160, 75, 118,
87, 14, 170, 92, 109, 244, 40, 234, 40, 216, 72, 207, 81, 161, 252, 252, 0, 38, 206,
123, 212, 93, 252, 225, 205, 16, 5, 197, 59, 93, 100, 56, 93, 125, 214, 150, 133, 208,
12, 0, 226, 246, 94, 62, 235, 164, 48, 134, 205, 77, 14, 107, 162, 60, 23, 150, 47,
198, 5, 214, 125, 12, 150, 63, 128, 95, 237, 209, 55, 5, 11, 59, 187, 0, 254, 180, 226,
126, 88, 87, 172, 38, 169, 27, 25, 92, 204, 24, 103, 78, 226, 65, 163, 114, 16, 202,
31, 160, 182, 100, 226, 15, 64, 5, 71, 117, 237, 31, 145, 250, 97, 105, 103, 67, 243,
2, 208, 60, 72, 16, 199, 57, 170, 99, 151, 62, 100, 53, 23, 45, 123, 225, 170, 149, 65,
26, 142, 240, 82, 214, 88, 93, 100, 158, 84, 42, 5, 112, 165, 194, 1, 160, 149, 103,
238, 63, 75, 3, 134, 113, 197, 251, 251, 90, 34, 184, 248, 214, 183, 168, 135, 4, 169,
134, 194, 106, 83, 108, 176, 26, 159, 80, 143, 105, 111, 53, 4, 1, 240, 44, 240, 149,
118, 189, 208, 190, 235, 145, 166, 163, 231, 158, 219, 221, 208, 61, 158, 132, 39, 75,
235, 36, 199, 169, 34, 119, 150, 223, 74, 5, 107, 123, 132, 116, 97, 241, 53, 43, 238,
115, 189, 195, 124, 127, 172, 5, 109, 112, 149, 190, 19, 202, 253, 171, 53, 105, 123,
173, 50, 50, 145, 56, 232, 13, 169, 47, 60, 112, 35, 100, 205, 35, 142, 5, 198, 235,
206, 112, 145, 99, 21, 214, 1, 184, 57, 125, 87, 245, 204, 162, 167, 124, 18, 154, 49,
25, 144, 181, 58, 184, 212, 59, 252, 72, 167, 228, 60, 118, 113, 65, 50, 150, 235, 163,
121, 215, 82, 91, 100, 78, 54, 199, 238, 93, 21, 21, 29, 215, 18, 201, 205, 106, 211,
78, 141, 155,
];
let _ = Sdgb1_50::decode(data)?;
Ok(())
}
}

View File

@@ -3,7 +3,7 @@ use nyquest::AsyncClient;
use crate::{ use crate::{
ApiError, ApiError,
title::{ title::{
MaiVersionExt as _, Sdgb1_50, MaiVersionExt as _, Sdgb1_53,
methods::APIMethod, methods::APIMethod,
model::{GetUserMusicApi, GetUserMusicApiResp}, model::{GetUserMusicApi, GetUserMusicApiResp},
}, },
@@ -21,7 +21,7 @@ pub async fn get_user_all_music(
next_index, next_index,
user_music_list: mut new_list, user_music_list: mut new_list,
.. ..
} = Sdgb1_50::request::<_, GetUserMusicApiResp>( } = Sdgb1_53::request::<_, GetUserMusicApiResp>(
&client, &client,
APIMethod::GetUserMusicApi, APIMethod::GetUserMusicApi,
user_id, user_id,

View File

@@ -58,20 +58,20 @@ pub use api_ext::*;
#[cfg(test)] #[cfg(test)]
mod _test { mod _test {
use crate::title::{MaiVersionExt, Sdgb1_50, methods::APIMethod}; use crate::title::{MaiVersionExt, Sdgb1_53, methods::APIMethod};
#[test] #[test]
fn test_obfuscate_1_50() { fn test_obfuscate_1_50() {
assert_eq!( assert_eq!(
Sdgb1_50::api_hash(APIMethod::Ping), Sdgb1_53::api_hash(APIMethod::Ping),
"250b3482854e7697de7d8eb6ea1fabb1" "250b3482854e7697de7d8eb6ea1fabb1"
); );
assert_eq!( assert_eq!(
Sdgb1_50::api_hash(APIMethod::GetUserPreviewApi), Sdgb1_53::api_hash(APIMethod::GetUserPreviewApi),
"004cf848f96d393a5f2720101e30b93d" "004cf848f96d393a5f2720101e30b93d"
); );
assert_eq!( assert_eq!(
Sdgb1_50::api_hash(APIMethod::GetUserDataApi), Sdgb1_53::api_hash(APIMethod::GetUserDataApi),
"3af1e5b298bb5b7379c94934b2e038c5" "3af1e5b298bb5b7379c94934b2e038c5"
); );
} }

View File

@@ -135,17 +135,8 @@ pub trait MaiVersionExt: MaiVersion {
} }
} }
pub struct Sdgb1_50;
pub struct Sdgb1_53; pub struct Sdgb1_53;
impl MaiVersion for Sdgb1_50 {
const AES_KEY: &[u8; 32] = b"a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R";
const AES_IV: &[u8; 16] = b"d6xHIKq]1J]Dt^ue";
const OBFUSECATE_SUFFIX: &str = "MaimaiChnB44df8yT";
const VERSION: &str = "1.50";
}
impl MaiVersion for Sdgb1_53 { impl MaiVersion for Sdgb1_53 {
const AES_KEY: &[u8; 32] = b"o2U8F6<adcYl25f_qwx_n]5_qxRcbLN>"; const AES_KEY: &[u8; 32] = b"o2U8F6<adcYl25f_qwx_n]5_qxRcbLN>";
const AES_IV: &[u8; 16] = b"AL<G:k:X6Vu7@_U]"; const AES_IV: &[u8; 16] = b"AL<G:k:X6Vu7@_U]";

View File

@@ -31,7 +31,7 @@ pub enum Commands {
/// Retrieve update package of SDGB /// Retrieve update package of SDGB
AuthLite { AuthLite {
#[arg(short, long, default_value = "1.50")] #[arg(short, long, default_value = "1.53")]
title_ver: String, title_ver: String,
#[arg(long, default_value = "SDGB")] #[arg(long, default_value = "SDGB")]
variant: AuthLiteVariant, variant: AuthLiteVariant,

View File

@@ -14,7 +14,7 @@ use sdgb_api::{
all_net::{GetResponse, QRCode}, all_net::{GetResponse, QRCode},
auth_lite::{SDGB, SDHJ, delivery_raw}, auth_lite::{SDGB, SDHJ, delivery_raw},
title::{ title::{
MaiVersionExt, Sdgb1_50, Sdgb1_53, MaiVersionExt, Sdgb1_53,
helper::get_user_all_music, helper::get_user_all_music,
methods::APIMethod, methods::APIMethod,
model::{ model::{
@@ -118,7 +118,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
} }
} }
Commands::Rating { user_id, format } => { Commands::Rating { user_id, format } => {
let rating: GetUserRatingApiResp = Sdgb1_50::request( let rating: GetUserRatingApiResp = Sdgb1_53::request(
&client, &client,
APIMethod::GetUserRatingApi, APIMethod::GetUserRatingApi,
user_id, user_id,
@@ -147,7 +147,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
} }
} }
Commands::Logout { user_id, timestamp } => { Commands::Logout { user_id, timestamp } => {
let logout: UserLogoutApiResp = Sdgb1_50::request( let logout: UserLogoutApiResp = Sdgb1_53::request(
&client, &client,
APIMethod::UserLogoutApi, APIMethod::UserLogoutApi,
user_id, user_id,
@@ -166,7 +166,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
} }
} }
Commands::Preview { user_id, token } => { Commands::Preview { user_id, token } => {
let preview: GetUserPreviewApiResp = Sdgb1_50::request( let preview: GetUserPreviewApiResp = Sdgb1_53::request(
&client, &client,
APIMethod::GetUserPreviewApi, APIMethod::GetUserPreviewApi,
user_id, user_id,
@@ -424,7 +424,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
skip_login, skip_login,
token, token,
} => { } => {
let action = async |_| match Sdgb1_50::request::<_, GetUserDataApiResp>( let action = async |_| match Sdgb1_53::request::<_, GetUserDataApiResp>(
&client, &client,
APIMethod::GetUserDataApi, APIMethod::GetUserDataApi,
user_id, user_id,

View File

@@ -14,7 +14,7 @@ use redb::TableDefinition;
use spdlog::{error, info}; use spdlog::{error, info};
use sdgb_api::title::MaiVersionExt; use sdgb_api::title::MaiVersionExt;
use sdgb_api::title::{Sdgb1_50, methods::APIExt}; use sdgb_api::title::{Sdgb1_53, methods::APIExt};
use sdgb_api::{ApiError, bincode}; use sdgb_api::{ApiError, bincode};
use bincode::{BorrowDecode, Encode, borrow_decode_from_slice}; use bincode::{BorrowDecode, Encode, borrow_decode_from_slice};
@@ -111,7 +111,7 @@ where
concurrency, concurrency,
definition, definition,
async |client, user_id| { async |client, user_id| {
Sdgb1_50::request_ext::<A>(client, A::Payload::from(user_id), user_id).await Sdgb1_53::request_ext::<A>(client, A::Payload::from(user_id), user_id).await
}, },
) )
.await .await

View File

@@ -4,7 +4,7 @@ use nyquest_preset::nyquest::AsyncClient;
use sdgb_api::{ use sdgb_api::{
ApiError, ApiError,
title::{ title::{
MaiVersionExt as _, Sdgb1_50, MaiVersionExt as _, Sdgb1_53,
methods::APIMethod, methods::APIMethod,
model::{UserLoginApi, UserLoginApiResp, UserLogoutApi, UserLogoutApiResp}, model::{UserLoginApi, UserLoginApiResp, UserLogoutApi, UserLogoutApiResp},
}, },
@@ -22,7 +22,7 @@ pub async fn login_action<R>(
let date_time = login.date_time; let date_time = login.date_time;
let login_resp: UserLoginApiResp = let login_resp: UserLoginApiResp =
Sdgb1_50::request(&client, APIMethod::UserLoginApi, user_id, login).await?; Sdgb1_53::request(&client, APIMethod::UserLoginApi, user_id, login).await?;
match login_resp.error() { match login_resp.error() {
None => info!("login succeed"), None => info!("login succeed"),
@@ -31,7 +31,7 @@ pub async fn login_action<R>(
let return_data = action(login_resp).await; let return_data = action(login_resp).await;
let logout_resp = Sdgb1_50::request::<_, UserLogoutApiResp>( let logout_resp = Sdgb1_53::request::<_, UserLogoutApiResp>(
&client, &client,
APIMethod::UserLogoutApi, APIMethod::UserLogoutApi,
user_id, user_id,