mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 21:24:22 +02:00
bring back samsung_old - by adding InputTarget system
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::any::Any;
|
||||
use crate::{AppContext, formats::Format};
|
||||
use crate::{InputTarget, AppContext, formats::Format};
|
||||
pub fn format() -> Format {
|
||||
Format { name: "mtk_bdp", detector_func: is_mtk_bdp_file, extractor_func: extract_mtk_bdp }
|
||||
}
|
||||
@@ -78,7 +78,7 @@ fn find_bytes(data: &[u8], pattern: &[u8]) -> Option<usize> {
|
||||
}
|
||||
|
||||
pub fn is_mtk_bdp_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file;
|
||||
let mut file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Ok(None)};
|
||||
let file_size = file.metadata()?.len();
|
||||
let mut data = Vec::new();
|
||||
|
||||
@@ -96,8 +96,9 @@ pub fn is_mtk_bdp_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box
|
||||
}
|
||||
|
||||
pub fn extract_mtk_bdp(app_ctx: &AppContext, ctx: Option<Box<dyn Any>>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut file = app_ctx.file;
|
||||
let mut file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Err("Extractor expected file, not directory".into())};
|
||||
let ctx = ctx.and_then(|c: Box<dyn Any>| c.downcast::<MtkBdpContext>().ok()).ok_or("Context is invalid or missing!")?;
|
||||
|
||||
let offset = ctx.pitit_offset;
|
||||
println!("\nReading PITIT at: {}", offset);
|
||||
|
||||
@@ -181,8 +182,8 @@ pub fn extract_mtk_bdp(app_ctx: &AppContext, ctx: Option<Box<dyn Any>>) -> Resul
|
||||
|
||||
let data = common::read_file(&file, bit_entry.offset as u64, bit_entry.size as usize)?;
|
||||
|
||||
let output_path = Path::new(app_ctx.output_dir).join(format!("{}.bin", name));
|
||||
fs::create_dir_all(app_ctx.output_dir)?;
|
||||
let output_path = Path::new(&app_ctx.output_dir).join(format!("{}.bin", name));
|
||||
fs::create_dir_all(&app_ctx.output_dir)?;
|
||||
let mut out_file = OpenOptions::new().read(true).write(true).create(true).open(output_path)?;
|
||||
out_file.seek(SeekFrom::Start(bit_entry.offset_in_target_part as u64))?;
|
||||
out_file.write_all(&data)?;
|
||||
|
||||
Reference in New Issue
Block a user