mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-07 20:19:51 +00:00
[joox] feat #1: add joox decipher implementation
This commit is contained in:
@@ -6,8 +6,9 @@ edition = "2021"
|
||||
[dependencies]
|
||||
anyhow = "1.0.86"
|
||||
clap = { version = "4.5.17", features = ["derive"] }
|
||||
umc_kuwo = { path = "../um_crypto/kuwo" }
|
||||
umc_joox = { path = "../um_crypto/joox" }
|
||||
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_utils = { path = "../um_crypto/utils" }
|
||||
|
||||
49
um_cli/src/cmd/joox.rs
Normal file
49
um_cli/src/cmd/joox.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use crate::Cli;
|
||||
use anyhow::Result;
|
||||
use clap::Args;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, BufWriter, Read, Seek, SeekFrom, Write};
|
||||
use std::path::PathBuf;
|
||||
use umc_joox::decrypt::JooxDecipher;
|
||||
use umc_joox::header::Header;
|
||||
|
||||
/// Decrypt a ofl_en file (Joox Music, Encryption V4)
|
||||
#[derive(Args)]
|
||||
pub struct ArgsJoox {
|
||||
/// Path to output file, e.g. /export/Music/song.flac
|
||||
#[clap(short, long)]
|
||||
output: PathBuf,
|
||||
|
||||
/// Path to input file, e.g. /export/Music/song.ofl_en
|
||||
#[arg(name = "input")]
|
||||
input: PathBuf,
|
||||
|
||||
/// Device GUID
|
||||
#[clap(short = 'u', long)]
|
||||
device_guid: String,
|
||||
}
|
||||
|
||||
impl ArgsJoox {
|
||||
pub fn run(&self, _cli: &Cli) -> Result<i32> {
|
||||
let mut file_input = File::open(&self.input)?;
|
||||
|
||||
let mut header_buffer = [0u8; 0x0c];
|
||||
file_input.read_exact(&mut header_buffer)?;
|
||||
let header = Header::from_buffer(&header_buffer, &self.device_guid)?;
|
||||
file_input.seek(SeekFrom::Start(header.audio_start_offset as u64))?;
|
||||
|
||||
let reader = BufReader::new(file_input);
|
||||
let mut input_stream = reader.take(header.original_file_len);
|
||||
|
||||
let file_output = File::create(&self.output)?;
|
||||
let mut writer = BufWriter::new(file_output);
|
||||
|
||||
let mut buffer = vec![0u8; header.get_audio_block_size()].into_boxed_slice();
|
||||
while let Ok(()) = input_stream.read_exact(&mut buffer) {
|
||||
let result = header.decrypt_audio_block(&mut buffer)?;
|
||||
writer.write_all(result)?;
|
||||
}
|
||||
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
use clap::Subcommand;
|
||||
|
||||
pub mod joox;
|
||||
pub mod kgm;
|
||||
pub mod ncm;
|
||||
pub mod qmc1;
|
||||
@@ -15,4 +16,6 @@ pub enum Commands {
|
||||
NCM(ncm::ArgsNCM),
|
||||
#[command(name = "kgm")]
|
||||
KGM(kgm::ArgsKGM),
|
||||
#[command(name = "joox")]
|
||||
JOOX(joox::ArgsJoox),
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ fn run_command(cli: &Cli) -> Result<i32> {
|
||||
Some(Commands::QMCv2(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::NCM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::KGM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::JOOX(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