mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-15 21:00:03 +02:00
add helper method to AppContext to simplify getting options
This commit is contained in:
@@ -28,8 +28,6 @@ pub fn is_msd10_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<d
|
||||
|
||||
pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn Any>) -> 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<dyn Any>) -> 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<dyn Any>) -> 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...");
|
||||
|
||||
@@ -27,7 +27,6 @@ pub fn is_msd11_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<d
|
||||
|
||||
pub fn extract_msd11(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn Any>) -> 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{} {}.{}",
|
||||
|
||||
@@ -44,7 +44,6 @@ pub fn is_mtk_pkg_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box
|
||||
pub fn extract_mtk_pkg(app_ctx: &AppContext, ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file().ok_or("Extractor expected file")?;
|
||||
let ctx = ctx.downcast::<MtkPkgContext>().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<dyn Any>) -> 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)?;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ pub fn is_mtk_pkg_new_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>,
|
||||
pub fn extract_mtk_pkg_new(app_ctx: &AppContext, ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file().ok_or("Extractor expected file")?;
|
||||
let ctx = ctx.downcast::<MtkPkgNewContext>().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<dyn Any>) -> 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)?;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ pub fn is_mtk_pkg_old_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>,
|
||||
pub fn extract_mtk_pkg_old(app_ctx: &AppContext, ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file().ok_or("Extractor expected file")?;
|
||||
let ctx = ctx.downcast::<MtkPkgOldContext>().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<dyn Any>) -> 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)?;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,6 @@ fn extract_file(app_ctx: &AppContext, file_reader: &mut Cursor<Vec<u8>>, offset:
|
||||
|
||||
let mut hdr_reader = Cursor::new(dec_header);
|
||||
let mut modules: Vec<ModuleEntry> = 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<Vec<u8>>, 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)?;
|
||||
}
|
||||
|
||||
@@ -68,9 +68,7 @@ fn parse_tdi_to_modules(tdi_data: Vec<u8>) -> Result<Vec<TdiTgtInf>, Box<dyn std
|
||||
|
||||
pub fn extract_sddl_sec(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn Any>) -> 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"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
|
||||
+1
-1
@@ -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<dyn std::error::Error>> {
|
||||
if !app_ctx.options.iter().any(|e| e == "dump_dec_hdrs") {
|
||||
if !app_ctx.has_option("dump_dec_hdrs") {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user