mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04:22 +02:00
testing modular format system
This commit is contained in:
+21
-10
@@ -1,3 +1,9 @@
|
||||
use std::any::Any;
|
||||
use crate::{ProgramContext, formats::Format};
|
||||
pub fn format() -> Format {
|
||||
Format { name: "sony_bdp", detect_func: is_sony_bdp_file, run_func: extract_sony_bdp }
|
||||
}
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::{self, OpenOptions};
|
||||
@@ -57,16 +63,17 @@ struct Entry {
|
||||
size: u32,
|
||||
}
|
||||
|
||||
pub fn is_sony_bdp_file(file: &File) -> bool {
|
||||
let header = common::read_file(&file, 0, 4).expect("Failed to read from file.");
|
||||
pub fn is_sony_bdp_file(app_ctx: &ProgramContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
|
||||
let header = common::read_file(app_ctx.file, 0, 4)?;
|
||||
if header == b"\x01\x73\xEC\xC9" || header == b"\x01\x73\xEC\x1F" || header == b"\xEC\x7D\xB0\xB0" { //MSB1x, MSB0x, BDPPxx
|
||||
true
|
||||
Ok(Some(Box::new(())))
|
||||
} else {
|
||||
false
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_sony_bdp(mut file: &File, output_folder: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn extract_sony_bdp(app_ctx: &ProgramContext, _ctx: Option<Box<dyn Any>>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file;
|
||||
let obf_header = common::read_exact(&mut file, 300)?;
|
||||
let header = hex_substitute(&obf_header);
|
||||
let mut hdr_reader = Cursor::new(header);
|
||||
@@ -96,10 +103,10 @@ pub fn extract_sony_bdp(mut file: &File, output_folder: &str) -> Result<(), Box<
|
||||
let obf_data = common::read_file(&file, entry.offset as u64, entry.size as usize)?;
|
||||
let data = hex_substitute(&obf_data);
|
||||
|
||||
let output_path = Path::new(&output_folder).join(format!("{}.bin", i));
|
||||
let output_path = Path::new(app_ctx.output_dir).join(format!("{}.bin", i));
|
||||
last_file_path = Some(output_path.clone());
|
||||
|
||||
fs::create_dir_all(&output_folder)?;
|
||||
fs::create_dir_all(app_ctx.output_dir)?;
|
||||
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
|
||||
out_file.write_all(&data)?;
|
||||
|
||||
@@ -110,11 +117,15 @@ pub fn extract_sony_bdp(mut file: &File, output_folder: &str) -> Result<(), Box<
|
||||
//The last file is often a Mtk BDP file so we can extract that here.
|
||||
if last_file_path.is_some() {
|
||||
println!("\nChecking if it's also MTK BDP...");
|
||||
|
||||
let last_file = File::open(last_file_path.unwrap())?;
|
||||
if let Some(result) = formats::mtk_bdp::is_mtk_bdp_file(&last_file)? {
|
||||
let mtk_extraction_path = format!("{}/{}", app_ctx.output_dir, i - 1);
|
||||
let ctx: ProgramContext = ProgramContext { file: &last_file, output_dir: &mtk_extraction_path };
|
||||
|
||||
if let Some(result) = formats::mtk_bdp::is_mtk_bdp_file(&ctx)? {
|
||||
println!("- MTK BDP file detected!\n");
|
||||
let mtk_extraction_path = format!("{}/{}", &output_folder, i - 1);
|
||||
formats::mtk_bdp::extract_mtk_bdp(&last_file, &mtk_extraction_path, result)?;
|
||||
|
||||
formats::mtk_bdp::extract_mtk_bdp(&ctx, Some(result))?;
|
||||
} else {
|
||||
println!("- Not an MTK BDP file.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user