diff --git a/src/formats/msd10/mod.rs b/src/formats/msd10/mod.rs index 8382eea..7ef3fbe 100644 --- a/src/formats/msd10/mod.rs +++ b/src/formats/msd10/mod.rs @@ -28,8 +28,6 @@ pub fn is_msd10_file(app_ctx: &AppContext) -> Result>, Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; - let save_cmac = app_ctx.options.iter().any(|e| e == "msd10:save_cmac"); - let print_ouith_tree = app_ctx.options.iter().any(|e| e == "msd:print_ouith"); let header: FileHeader = file.read_le()?; println!("\nNumber of sections: {}", header.section_count); @@ -102,7 +100,7 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box) -> Result<(), Box let toc = decrypt_aes_salted_tizen(&toc_data, &passphrase_bytes)?; opt_dump_dec_hdr(app_ctx, &toc, "toc")?; - let (items, info) = parse_blob_1_8(&toc, print_ouith_tree)?; + let (items, info) = parse_blob_1_8(&toc, app_ctx.has_option("msd:print_ouith"))?; if let Some(info) = info { println!("\nImage info:\n{} {}.{} {}/{}/{}", @@ -144,7 +142,7 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box) -> Result<(), Box let toc = decrypt_aes_salted_old(&toc_data, &passphrase_bytes)?; opt_dump_dec_hdr(app_ctx, &toc, "toc")?; - let (items, info) = parse_ouith_blob(&toc, print_ouith_tree)?; + let (items, info) = parse_ouith_blob(&toc, app_ctx.has_option("msd:print_ouith"))?; if let Some(info) = info { println!("\nImage info:\n{} {}.{} {}/{}/20{}", @@ -163,7 +161,7 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box) -> Result<(), Box let mut out_filename = format!("{}", item.name); if item.item_type == 0x11 { //CMAC DATA - if save_cmac { + if app_ctx.has_option("msd10:save_cmac") { out_filename = format!("{}.cmac", item.name); //add an additional extension, because the CMAC data has the same name as its item } else { println!("- Skipping CMAC Data..."); diff --git a/src/formats/msd11/mod.rs b/src/formats/msd11/mod.rs index e6084ca..e3a47e9 100644 --- a/src/formats/msd11/mod.rs +++ b/src/formats/msd11/mod.rs @@ -27,7 +27,6 @@ pub fn is_msd11_file(app_ctx: &AppContext) -> Result>, Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; - let print_ouith_tree = app_ctx.options.iter().any(|e| e == "msd:print_ouith"); let header: FileHeader = file.read_le()?; println!("\nNumber of sections: {}", header.section_count); @@ -82,7 +81,7 @@ pub fn extract_msd11(app_ctx: &AppContext, _ctx: Box) -> Result<(), Box let toc = decrypt_aes_salted_tizen(&toc_data, &passphrase_bytes)?; opt_dump_dec_hdr(app_ctx, &toc, "toc")?; - let (items, info) = parse_blob_1_9(&toc, print_ouith_tree)?; + let (items, info) = parse_blob_1_9(&toc, app_ctx.has_option("msd:print_ouith"))?; if let Some(info) = info { println!("\nImage info:\n{} {}.{}", diff --git a/src/formats/mtk_pkg/mod.rs b/src/formats/mtk_pkg/mod.rs index 99538b6..f8b1ef4 100644 --- a/src/formats/mtk_pkg/mod.rs +++ b/src/formats/mtk_pkg/mod.rs @@ -44,7 +44,6 @@ pub fn is_mtk_pkg_file(app_ctx: &AppContext) -> Result>, Box pub fn extract_mtk_pkg(app_ctx: &AppContext, ctx: Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; let ctx = ctx.downcast::().expect("Missing context"); - let no_del_comp = app_ctx.options.iter().any(|e| e == "mtk_pkg:no_del_comp"); let file_size = file.metadata()?.len(); let header = ctx.decrypted_header; @@ -153,7 +152,7 @@ pub fn extract_mtk_pkg(app_ctx: &AppContext, ctx: Box) -> Result<(), Bo match decompress_lzhs_fs_file2file(&out_file, lzhs_out_path) { Ok(()) => { println!("- Decompressed Successfully!"); - if !no_del_comp { + if !app_ctx.has_option("mtk_pkg:no_del_comp") { //after successfull decompression remove the temporary .lzhs file fs::remove_file(&output_path)?; } diff --git a/src/formats/mtk_pkg_new/mod.rs b/src/formats/mtk_pkg_new/mod.rs index 324f88c..f0fb23f 100644 --- a/src/formats/mtk_pkg_new/mod.rs +++ b/src/formats/mtk_pkg_new/mod.rs @@ -47,7 +47,6 @@ pub fn is_mtk_pkg_new_file(app_ctx: &AppContext) -> Result>, pub fn extract_mtk_pkg_new(app_ctx: &AppContext, ctx: Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; let ctx = ctx.downcast::().expect("Missing context"); - let no_del_comp = app_ctx.options.iter().any(|e| e == "mtk_pkg:no_del_comp"); let file_size = file.metadata()?.len(); @@ -122,7 +121,7 @@ pub fn extract_mtk_pkg_new(app_ctx: &AppContext, ctx: Box) -> Result<() match decompress_lzhs_fs_file2file(&out_file, lzhs_out_path) { Ok(()) => { println!("-- Decompressed Successfully!"); - if !no_del_comp { + if !app_ctx.has_option("mtk_pkg:no_del_comp") { //after successfull decompression remove the temporary .lzhs file fs::remove_file(&output_path)?; } diff --git a/src/formats/mtk_pkg_old/mod.rs b/src/formats/mtk_pkg_old/mod.rs index 35022f6..4eaa79f 100644 --- a/src/formats/mtk_pkg_old/mod.rs +++ b/src/formats/mtk_pkg_old/mod.rs @@ -40,7 +40,6 @@ pub fn is_mtk_pkg_old_file(app_ctx: &AppContext) -> Result>, pub fn extract_mtk_pkg_old(app_ctx: &AppContext, ctx: Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; let ctx = ctx.downcast::().expect("Missing context"); - let no_del_comp = app_ctx.options.iter().any(|e| e == "mtk_pkg:no_del_comp"); let file_size = file.metadata()?.len(); @@ -98,7 +97,7 @@ pub fn extract_mtk_pkg_old(app_ctx: &AppContext, ctx: Box) -> Result<() match decompress_lzhs_fs_file2file_old(&out_file, lzhs_out_path) { Ok(()) => { println!("- Decompressed Successfully!"); - if !no_del_comp { + if !app_ctx.has_option("mtk_pkg:no_del_comp") { //after successfull decompression remove the temporary .lzhs file fs::remove_file(&output_path)?; } diff --git a/src/formats/pana_dvd/mod.rs b/src/formats/pana_dvd/mod.rs index 1f28271..0ecd408 100644 --- a/src/formats/pana_dvd/mod.rs +++ b/src/formats/pana_dvd/mod.rs @@ -120,7 +120,6 @@ fn extract_file(app_ctx: &AppContext, file_reader: &mut Cursor>, offset: let mut hdr_reader = Cursor::new(dec_header); let mut modules: Vec = Vec::new(); - let split_main = app_ctx.options.iter().any(|e| e == "pana_dvd:split_main"); for i in 0..100 { let mut entry: ModuleEntry = hdr_reader.read_le()?; @@ -154,7 +153,7 @@ fn extract_file(app_ctx: &AppContext, file_reader: &mut Cursor>, offset: if module.name() == "MAIN" { println!("- Extracting MAIN..."); extract_main(file_reader, key, &output_path)?; - if split_main { + if app_ctx.has_option("pana_dvd:split_main") { println!("\n- Splitting MAIN..."); split_main_file(&output_path, output_folder)?; } diff --git a/src/formats/sddl_sec/mod.rs b/src/formats/sddl_sec/mod.rs index 90f1513..99eabf0 100644 --- a/src/formats/sddl_sec/mod.rs +++ b/src/formats/sddl_sec/mod.rs @@ -68,9 +68,7 @@ fn parse_tdi_to_modules(tdi_data: Vec) -> Result, Box) -> Result<(), Box> { let mut file = app_ctx.file().ok_or("Extractor expected file")?; - let save_extra = app_ctx.options.iter().any(|e| e == "sddl_sec:save_extra"); - let split_peaks = app_ctx.options.iter().any(|e| e == "sddl_sec:split_peaks"); - let decomp_peaks = !app_ctx.options.iter().any(|e| e == "sddl_sec:no_decomp_peaks"); + let save_extra = app_ctx.has_option("sddl_sec:save_extra"); let mut secfile_hdr_reader = Cursor::new(decipher(&common::read_exact(&mut file, 32)?)); let secfile_header: SecHeader = secfile_hdr_reader.read_be()?; @@ -162,10 +160,10 @@ pub fn extract_sddl_sec(app_ctx: &AppContext, _ctx: Box) -> Result<(), } - if split_peaks && module.module_name() == "PEAKS" { + if app_ctx.has_option("sddl_sec:split_peaks") && module.module_name() == "PEAKS" { println!("\n- Splitting PEAKS"); if let Some(ref path) = final_out_path { - split_peaks_file(path, &app_ctx.output_dir, decomp_peaks)?; + split_peaks_file(path, &app_ctx.output_dir, !app_ctx.has_option("sddl_sec:no_decomp_peaks"))?; } } } diff --git a/src/main.rs b/src/main.rs index 6247135..b696f4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,10 @@ impl AppContext { _ => None, } } + + pub fn has_option(&self, option: &'static str) -> bool { + self.options.iter().any(|o| o == option) + } } fn main() -> Result<(), Box> { diff --git a/src/utils/global.rs b/src/utils/global.rs index 65820dd..7549aed 100644 --- a/src/utils/global.rs +++ b/src/utils/global.rs @@ -3,7 +3,7 @@ use std::{fs::{self, OpenOptions}, io::Write, path::Path}; use crate::AppContext; pub fn opt_dump_dec_hdr(app_ctx: &AppContext, data: &[u8], name: &str) -> Result<(), Box> { - if !app_ctx.options.iter().any(|e| e == "dump_dec_hdrs") { + if !app_ctx.has_option("dump_dec_hdrs") { return Ok(()) }