音乐控制/解密
This commit is contained in:
1 parent
9e6d73e191
commit
ff1d5cd517
41 files changed
+10827
-4
No files matched your search
@@ -0,0 +1,83 @@
|
||||
//! **临时**端到端验证:对真实 musicex 样本走完整「取密钥 → 解密 → 校验」流程。
|
||||
//!
|
||||
//! 用法(需要 QQ 音乐在运行且已登录):
|
||||
//! ```text
|
||||
//! cargo run --example decrypt_musicex_probe -- "C:\path\to\file.mflac"
|
||||
//! ```
|
||||
//! 验证完即可删除本文件。
|
||||
|
||||
use thing_lib::music::decrypt::probe::{probe_musicex, ProbeOutcome};
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().skip(1);
|
||||
let path = args.next().expect(
|
||||
"用法:decrypt_musicex_probe <文件路径> [输出目录]\n\
|
||||
给了输出目录则会用**生产路径**真正写盘(生成可播放文件)",
|
||||
);
|
||||
let out_dir = args.next();
|
||||
|
||||
match probe_musicex(std::path::Path::new(&path)) {
|
||||
Ok(ProbeOutcome {
|
||||
ekey_len,
|
||||
key_len,
|
||||
raw_key_bytes,
|
||||
cipher_magic,
|
||||
plain_magic,
|
||||
decrypted_bytes,
|
||||
guessed_format,
|
||||
expiration_secs,
|
||||
}) => {
|
||||
println!("=== 成功 ===");
|
||||
println!("ekey 长度 : {ekey_len}");
|
||||
println!("派生密钥长度 : {key_len}");
|
||||
println!(
|
||||
"密钥前 8 字节 : {:02x?}",
|
||||
&raw_key_bytes[..raw_key_bytes.len().min(8)]
|
||||
);
|
||||
println!("密文头 : {:02x?}", cipher_magic);
|
||||
println!("解密后字节数 : {decrypted_bytes}");
|
||||
println!("明文首帧魔数 : {:02x?}", plain_magic);
|
||||
println!("判定格式 : {guessed_format}");
|
||||
println!("ekey 有效期(秒) : {expiration_secs}");
|
||||
if guessed_format == "flac" && plain_magic.starts_with(b"fLaC") {
|
||||
println!("=> 合法 FLAC 头,产物可播");
|
||||
} else {
|
||||
println!("=> 头不合法,需要排查");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("=== 失败 ===");
|
||||
println!("{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:调用**生产路径**真正落盘(验证 decrypt_musicex 本身,而不只是核心算法)
|
||||
if let Some(dir) = out_dir {
|
||||
println!("\n=== 生产路径落盘 ===");
|
||||
match thing_lib::music::decrypt::qq_online::decrypt_musicex(
|
||||
std::path::Path::new(&path),
|
||||
std::path::Path::new(&dir),
|
||||
"QQ音乐",
|
||||
|done, total| {
|
||||
if done == total {
|
||||
println!("进度:{done} 字节(完成)");
|
||||
}
|
||||
},
|
||||
) {
|
||||
Ok(outcome) => {
|
||||
let size = std::fs::metadata(&outcome.output)
|
||||
.map(|m| m.len())
|
||||
.unwrap_or(0);
|
||||
println!("产物 : {}", outcome.output.display());
|
||||
println!("大小 : {size} 字节");
|
||||
println!("格式 : {}", outcome.format);
|
||||
println!("备注 : {}", outcome.note);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("落盘失败:{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//! 诊断:枚举全部 GSMTC 会话的时间轴原始值(判断"来源不提供进度"的形态)。
|
||||
//!
|
||||
//! 运行:`cargo run --example gsmtc_dump`
|
||||
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
|
||||
|
||||
fn ticks_to_unix_ms(ticks: i64) -> i64 {
|
||||
ticks / 10_000 - 62_135_596_800_000
|
||||
}
|
||||
|
||||
fn main() -> windows::core::Result<()> {
|
||||
let mgr = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?;
|
||||
let sessions = mgr.GetSessions()?;
|
||||
let now_ms = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|d| d.as_millis() as i64)
|
||||
.unwrap_or(0);
|
||||
println!("now(unix ms) = {now_ms}");
|
||||
println!("sessions = {}", sessions.Size()?);
|
||||
|
||||
for i in 0..sessions.Size()? {
|
||||
let s = sessions.GetAt(i)?;
|
||||
println!("--- [{}] {}", i, s.SourceAppUserModelId()?);
|
||||
if let Ok(p) = s.TryGetMediaPropertiesAsync()?.get() {
|
||||
println!(
|
||||
" title={:?} artist={:?} album={:?}",
|
||||
p.Title()?,
|
||||
p.Artist()?,
|
||||
p.AlbumTitle()?
|
||||
);
|
||||
}
|
||||
let info = s.GetPlaybackInfo()?;
|
||||
println!(" status={:?}", info.PlaybackStatus()?);
|
||||
if let Ok(c) = info.Controls() {
|
||||
println!(
|
||||
" controls play={} pause={} next={} prev={} seek={}",
|
||||
c.IsPlayEnabled().unwrap_or(false),
|
||||
c.IsPauseEnabled().unwrap_or(false),
|
||||
c.IsNextEnabled().unwrap_or(false),
|
||||
c.IsPreviousEnabled().unwrap_or(false),
|
||||
c.IsPlaybackPositionEnabled().unwrap_or(false)
|
||||
);
|
||||
}
|
||||
let tl = s.GetTimelineProperties()?;
|
||||
let pos = tl.Position()?.Duration;
|
||||
let end = tl.EndTime().map(|t| t.Duration).unwrap_or(-1);
|
||||
let upd = tl.LastUpdatedTime()?.UniversalTime;
|
||||
let upd_ms = ticks_to_unix_ms(upd);
|
||||
println!(
|
||||
" position={}s end={}s lastUpdatedTicks={upd} -> unixMs={upd_ms} (deltaMs={})",
|
||||
pos as f64 / 1e7,
|
||||
end as f64 / 1e7,
|
||||
upd_ms - now_ms
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//! GSMTC 可用性探测(MUSIC_REMOTE_PLAN §7 P0 第 1 项 / §6 第 1 条)
|
||||
//!
|
||||
//! 关键假设:GSMTC(Windows.Media.Control)在**非打包**桌面应用可用(Windows 10 1809+)。
|
||||
//! 本 example 以普通控制台进程运行(无 package identity),跑通即证明假设成立。
|
||||
//!
|
||||
//! 运行:`cargo run --example gsmtc_probe`
|
||||
//! 建议先在任意播放器(网易云/浏览器/Thing)放一首歌,可看到当前会话的元数据与时间轴。
|
||||
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
|
||||
use windows::core::Result;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// 1. 取全局会话管理器(失败 = 整个能力需降级,见计划 §3.1 失败策略)
|
||||
let mgr = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?;
|
||||
|
||||
// 2. 枚举系统全部 SMTC 会话(注意:0.52 投影里 GetSessions/GetCurrentSession 是同步的)
|
||||
let sessions = mgr.GetSessions()?;
|
||||
println!("[ok] GSMTC 可用(unpackaged),当前会话数: {}", sessions.Size()?);
|
||||
|
||||
// 3. 当前活跃会话的元数据 / 播放状态 / 时间轴
|
||||
// 无会话时 ABI 返回 null → windows-rs 投影为 Err(E_POINTER),按"无会话"处理
|
||||
match mgr.GetCurrentSession() {
|
||||
Ok(cur) => {
|
||||
println!("current: {}", cur.SourceAppUserModelId()?);
|
||||
let p = cur.TryGetMediaPropertiesAsync()?.get()?;
|
||||
println!(" {} - {} | album: {}", p.Artist()?, p.Title()?, p.AlbumTitle()?);
|
||||
println!(" status: {:?}", cur.GetPlaybackInfo()?.PlaybackStatus()?);
|
||||
let tl = cur.GetTimelineProperties()?;
|
||||
println!(
|
||||
" position(ticks): {} | lastUpdated(ticks): {}",
|
||||
tl.Position()?.Duration,
|
||||
tl.LastUpdatedTime()?.UniversalTime
|
||||
);
|
||||
}
|
||||
Err(e) => println!("current session: <none> ({e})(先放一首歌再跑,可看完整元数据)"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//! **临时**校验:用产物解析器确认解密出来的文件是合法音频。
|
||||
//!
|
||||
//! 用法:`cargo run --example verify_audio -- <文件路径>`
|
||||
|
||||
fn main() {
|
||||
let path = std::env::args()
|
||||
.nth(1)
|
||||
.expect("用法:verify_audio <文件路径>");
|
||||
let p = std::path::Path::new(&path);
|
||||
|
||||
let size = std::fs::metadata(p).map(|m| m.len()).unwrap_or(0);
|
||||
println!("文件 : {}", p.display());
|
||||
println!("大小 : {size} 字节");
|
||||
|
||||
// 1) 头部魔数
|
||||
let head = std::fs::read(p).map(|b| b[..16.min(b.len())].to_vec());
|
||||
match head {
|
||||
Ok(h) => println!("首帧 : {:02x?}", h),
|
||||
Err(e) => {
|
||||
println!("读取失败:{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) 交给项目同款的解析器(lofty):能读出时长与格式才算真合法
|
||||
match lofty::probe::Probe::open(p).and_then(|probe| probe.read()) {
|
||||
Ok(tagged) => {
|
||||
use lofty::file::AudioFile;
|
||||
let props = tagged.properties();
|
||||
println!("时长 : {:?}", props.duration());
|
||||
println!("码率 : {:?}", props.audio_bitrate());
|
||||
println!("采样率 : {:?}", props.sample_rate());
|
||||
println!("声道 : {:?}", props.channels());
|
||||
println!("=> lofty 成功解析,文件合法可播");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("lofty 解析失败:{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user