mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04: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: "android_ota_payload", detector_func: is_android_ota_payload_file, extractor_func: extract_android_ota_payload }
|
||||
}
|
||||
@@ -23,7 +23,9 @@ struct Header {
|
||||
}
|
||||
|
||||
pub fn is_android_ota_payload_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
|
||||
let header = common::read_file(app_ctx.file, 0, 4)?;
|
||||
let file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Ok(None)};
|
||||
|
||||
let header = common::read_file(&file, 0, 4)?;
|
||||
if header == b"CrAU" {
|
||||
Ok(Some(Box::new(())))
|
||||
} else {
|
||||
@@ -32,7 +34,8 @@ pub fn is_android_ota_payload_file(app_ctx: &AppContext) -> Result<Option<Box<dy
|
||||
}
|
||||
|
||||
pub fn extract_android_ota_payload(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 header: Header = file.read_be()?;
|
||||
println!("File info:\nFormat version: {}\nManifest size: {}", header.file_format_version, header.manifest_size);
|
||||
|
||||
@@ -82,8 +85,8 @@ pub fn extract_android_ota_payload(app_ctx: &AppContext, _ctx: Option<Box<dyn An
|
||||
break
|
||||
}
|
||||
|
||||
fs::create_dir_all(app_ctx.output_dir)?;
|
||||
let output_path = Path::new(app_ctx.output_dir).join(format!("{}.bin", partition.partition_name));
|
||||
fs::create_dir_all(&app_ctx.output_dir)?;
|
||||
let output_path = Path::new(&app_ctx.output_dir).join(format!("{}.bin", partition.partition_name));
|
||||
let mut out_file = OpenOptions::new().append(true).create(true).open(output_path)?;
|
||||
out_file.write_all(&out_data)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user