mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-07 20:19:51 +00:00
[xiami] feat: implement xiami decipher
This commit is contained in:
@@ -11,5 +11,6 @@ umc_kgm = { path = "../um_crypto/kgm" }
|
||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||
umc_ncm = { path = "../um_crypto/ncm" }
|
||||
umc_qmc = { path = "../um_crypto/qmc" }
|
||||
umc_xiami = { path = "../um_crypto/xiami" }
|
||||
umc_xmly = { path = "../um_crypto/xmly" }
|
||||
umc_utils = { path = "../um_crypto/utils" }
|
||||
|
||||
@@ -5,6 +5,7 @@ pub mod kgm;
|
||||
pub mod ncm;
|
||||
pub mod qmc1;
|
||||
pub mod qmc2;
|
||||
pub mod xiami;
|
||||
pub mod xmly;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -21,4 +22,6 @@ pub enum Commands {
|
||||
JOOX(joox::ArgsJoox),
|
||||
#[command(name = "xmly")]
|
||||
XMLY(xmly::ArgsXimalaya),
|
||||
#[command(name = "xiami")]
|
||||
Xiami(xiami::ArgsXiami),
|
||||
}
|
||||
|
||||
44
um_cli/src/cmd/xiami.rs
Normal file
44
um_cli/src/cmd/xiami.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::Cli;
|
||||
use anyhow::Result;
|
||||
use clap::Args;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::{BufReader, BufWriter, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Decrypt a XM file (Xiami)
|
||||
#[derive(Args)]
|
||||
pub struct ArgsXiami {
|
||||
/// Path to output file, e.g. /export/Music/song.flac
|
||||
#[clap(short, long)]
|
||||
output: PathBuf,
|
||||
|
||||
/// Path to input file, e.g. /export/Music/song.xm
|
||||
#[arg(name = "input")]
|
||||
input: PathBuf,
|
||||
}
|
||||
|
||||
impl ArgsXiami {
|
||||
pub fn run(&self, cli: &Cli) -> Result<i32> {
|
||||
let mut reader = BufReader::with_capacity(cli.buffer_size, File::open(&self.input)?);
|
||||
let mut writer = BufWriter::with_capacity(cli.buffer_size, File::create(&self.output)?);
|
||||
|
||||
let mut header = [0u8; 0x10];
|
||||
reader.read_exact(&mut header)?;
|
||||
let xm = umc_xiami::XiamiFile::from_header(&header)?;
|
||||
let mut copy_reader = (&mut reader).take(xm.copy_len as u64);
|
||||
io::copy(&mut copy_reader, &mut writer)?;
|
||||
|
||||
let mut buffer = vec![0u8; cli.buffer_size];
|
||||
loop {
|
||||
let n = reader.read(&mut buffer[..])?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
xm.decrypt(&mut buffer[..n]);
|
||||
writer.write_all(&buffer[..n])?;
|
||||
}
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ fn run_command(cli: &Cli) -> Result<i32> {
|
||||
Some(Commands::KGM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::JOOX(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::XMLY(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::Xiami(cmd)) => cmd.run(&cli),
|
||||
None => {
|
||||
// https://github.com/clap-rs/clap/issues/3857#issuecomment-1161796261
|
||||
todo!("implement a sensible default command, similar to um/cli");
|
||||
|
||||
Reference in New Issue
Block a user