[xiami] feat: implement xiami decipher

This commit is contained in:
鲁树人
2024-09-18 23:33:22 +01:00
parent 687885b88d
commit 1800f1b627
11 changed files with 140 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ 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" }
um_audio = { path = "../um_audio" }

View File

@@ -4,4 +4,5 @@ pub mod kgm;
pub mod kuwo;
pub mod ncm;
pub mod qmc;
mod xiami;
pub mod xmly;

View File

@@ -0,0 +1,27 @@
use umc_xiami::XiamiFile;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsError;
/// Xiami XM file decipher.
#[wasm_bindgen(js_name=Xiami)]
pub struct JsXiami(XiamiFile);
#[wasm_bindgen(js_class = Xiami)]
impl JsXiami {
/// Parse the Xiami header (0x400 bytes)
pub fn from_header(header: &[u8]) -> Result<JsXiami, JsError> {
let hdr = XiamiFile::from_header(header)?;
Ok(JsXiami(hdr))
}
/// Decrypt encrypted buffer part.
pub fn decrypt(&self, buffer: &mut [u8]) {
self.0.decrypt(buffer)
}
/// After header (0x10 bytes), the number of bytes should be copied without decryption.
#[wasm_bindgen(getter, js_name=copyPlainLength)]
pub fn get_copy_plain_length(&self) -> usize {
self.0.copy_len
}
}