add format specific options (example on sddl_sec and msd10)

This commit is contained in:
theubusu
2026-02-17 21:28:43 +01:00
parent c72966cd7e
commit 4c648bf5a5
4 changed files with 31 additions and 14 deletions
+9 -3
View File
@@ -27,6 +27,7 @@ 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>> { 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 mut file = app_ctx.file().ok_or("Extractor expected file")?;
let save_cmac = app_ctx.options.iter().any(|e| e == "msd10:save_cmac");
let header: FileHeader = file.read_le()?; let header: FileHeader = file.read_le()?;
println!("\nNumber of sections: {}", header.section_count); println!("\nNumber of sections: {}", header.section_count);
@@ -109,7 +110,7 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box
out_data = stored_data; out_data = stored_data;
} }
let output_path = Path::new(&app_ctx.output_dir).join(item.name.clone()); let output_path = Path::new(&app_ctx.output_dir).join(format!("{}", item.name));
fs::create_dir_all(&app_ctx.output_dir)?; fs::create_dir_all(&app_ctx.output_dir)?;
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?; let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
out_file.write_all(&out_data)?; out_file.write_all(&out_data)?;
@@ -137,10 +138,15 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box
return Err("Item ID in TOC does not match ID from header!".into()); return Err("Item ID in TOC does not match ID from header!".into());
} }
if item.item_type == 0x11 { //Skip CMAC DATA let mut out_filename = format!("{}", item.name);
if item.item_type == 0x11 { //CMAC DATA
if 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..."); println!("- Skipping CMAC Data...");
continue continue
} }
}
file.seek(SeekFrom::Start(offset as u64))?; file.seek(SeekFrom::Start(offset as u64))?;
@@ -156,7 +162,7 @@ pub fn extract_msd10(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box
out_data = stored_data; out_data = stored_data;
} }
let output_path = Path::new(&app_ctx.output_dir).join(item.name.clone()); let output_path = Path::new(&app_ctx.output_dir).join(out_filename);
fs::create_dir_all(&app_ctx.output_dir)?; fs::create_dir_all(&app_ctx.output_dir)?;
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?; let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
out_file.write_all(&out_data)?; out_file.write_all(&out_data)?;
+10 -8
View File
@@ -66,6 +66,8 @@ 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>> { 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 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 mut secfile_hdr_reader = Cursor::new(decipher(&common::read_exact(&mut file, 32)?)); let mut secfile_hdr_reader = Cursor::new(decipher(&common::read_exact(&mut file, 32)?));
let secfile_header: SecHeader = secfile_hdr_reader.read_be()?; let secfile_header: SecHeader = secfile_hdr_reader.read_be()?;
@@ -74,10 +76,10 @@ pub fn extract_sddl_sec(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(),
let (tdi_file, tdi_data) = get_sec_file(&file)?; let (tdi_file, tdi_data) = get_sec_file(&file)?;
println!("[TDI] Name: {}, Size: {}", tdi_file.name(), tdi_file.size()); println!("[TDI] Name: {}, Size: {}", tdi_file.name(), tdi_file.size());
//if save_extra { //Save SDIT if save_extra { //Save SDIT
// let mut out_file = OpenOptions::new().write(true).create(true).open(Path::new(&output_folder).join(tdi_file.name()))?; let mut out_file = OpenOptions::new().write(true).create(true).open(Path::new(&app_ctx.output_dir).join(tdi_file.name()))?;
// out_file.write_all(&tdi_data)?; out_file.write_all(&tdi_data)?;
//} }
if tdi_file.name() != TDI_FILENAME { if tdi_file.name() != TDI_FILENAME {
return Err(format!("Invalid TDI filename {}!, expected: {}", tdi_file.name(), TDI_FILENAME).into()); return Err(format!("Invalid TDI filename {}!, expected: {}", tdi_file.name(), TDI_FILENAME).into());
} }
@@ -91,10 +93,10 @@ pub fn extract_sddl_sec(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(),
if !info_file.name().ends_with(INFO_FILE_EXTENSION) { if !info_file.name().ends_with(INFO_FILE_EXTENSION) {
return Err(format!("Info file {} does not have the expected extension {}!", info_file.name(), INFO_FILE_EXTENSION).into()); return Err(format!("Info file {} does not have the expected extension {}!", info_file.name(), INFO_FILE_EXTENSION).into());
} }
//if save_extra { //Save info file if save_extra { //Save info file
// let mut out_file = OpenOptions::new().write(true).create(true).open(Path::new(&output_folder).join(info_file.name()))?; let mut out_file = OpenOptions::new().write(true).create(true).open(Path::new(&app_ctx.output_dir).join(info_file.name()))?;
// out_file.write_all(&info_data)?; out_file.write_all(&info_data)?;
//} }
//print info file //print info file
println!("{}", String::from_utf8_lossy(&info_data)); println!("{}", String::from_utf8_lossy(&info_data));
} }
+3 -1
View File
@@ -72,7 +72,9 @@ pub fn extract_sony_bdp(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(),
let last_file = File::open(last_file_path.unwrap())?; let last_file = File::open(last_file_path.unwrap())?;
let mtk_extraction_path = app_ctx.output_dir.join(format!("{}", i + 1)); let mtk_extraction_path = app_ctx.output_dir.join(format!("{}", i + 1));
let ctx: AppContext = AppContext { input: InputTarget::File(last_file), output_dir: mtk_extraction_path };
//this is getting stupid...
let ctx: AppContext = AppContext { input: InputTarget::File(last_file), output_dir: mtk_extraction_path, options: app_ctx.options.clone() };
if let Some(result) = formats::mtk_bdp::is_mtk_bdp_file(&ctx)? { if let Some(result) = formats::mtk_bdp::is_mtk_bdp_file(&ctx)? {
println!("- MTK BDP file detected!\n"); println!("- MTK BDP file detected!\n");
+7
View File
@@ -12,6 +12,10 @@ use crate::formats::{Format, get_registry};
struct Args { struct Args {
input_target: String, input_target: String,
output_directory: Option<String>, output_directory: Option<String>,
///format specific options
#[arg(short, long)]
options: Vec<String>,
} }
pub enum InputTarget { pub enum InputTarget {
@@ -22,6 +26,7 @@ pub enum InputTarget {
pub struct AppContext { pub struct AppContext {
pub input: InputTarget, pub input: InputTarget,
pub output_dir: PathBuf, pub output_dir: PathBuf,
pub options: Vec<String>,
} }
impl AppContext { impl AppContext {
pub fn file(&self) -> Option<&File> { pub fn file(&self) -> Option<&File> {
@@ -73,11 +78,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
app_ctx = AppContext { app_ctx = AppContext {
input: InputTarget::File(file), input: InputTarget::File(file),
output_dir: output_directory_path, output_dir: output_directory_path,
options: args.options,
}; };
} else if target_path.is_dir() { } else if target_path.is_dir() {
app_ctx = AppContext { app_ctx = AppContext {
input: InputTarget::Directory(target_path), input: InputTarget::Directory(target_path),
output_dir: output_directory_path, output_dir: output_directory_path,
options: args.options,
}; };
} else { } else {
return Err("Invalid input path!".into()); return Err("Invalid input path!".into());