bring back samsung_old - by adding InputTarget system

This commit is contained in:
theubusu
2026-02-06 15:08:38 +01:00
parent 43128ca117
commit 9b059c67ab
32 changed files with 291 additions and 224 deletions
+9 -7
View File
@@ -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_pkg", detector_func: is_mtk_pkg_file, extractor_func: extract_mtk_pkg }
}
@@ -82,13 +82,15 @@ static HEADER_KEY: [u8; 16] = [
static HEADER_IV: [u8; 16] = [0x00; 16];
pub fn is_mtk_pkg_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
let mut encrypted_header = common::read_file(app_ctx.file, 0, HEADER_SIZE)?;
let file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Ok(None)};
let mut encrypted_header = common::read_file(&file, 0, HEADER_SIZE)?;
let mut header = decrypt_aes128_cbc_nopad(&encrypted_header, &HEADER_KEY, &HEADER_IV)?;
if &header[4..12] == MTK_HEADER_MAGIC {
Ok(Some(Box::new(MtkPkgContext { is_philips_variant: false, decrypted_header: header})))
} else {
// try for philips which has additional 128 bytes at beginning
encrypted_header = common::read_file(app_ctx.file, PHILIPS_EXTRA_HEADER_SIZE as u64, HEADER_SIZE)?;
encrypted_header = common::read_file(&file, PHILIPS_EXTRA_HEADER_SIZE as u64, HEADER_SIZE)?;
header = decrypt_aes128_cbc_nopad(&encrypted_header, &HEADER_KEY, &HEADER_IV)?;
if &header[4..12] == MTK_HEADER_MAGIC {
Ok(Some(Box::new(MtkPkgContext { is_philips_variant: true, decrypted_header: header })))
@@ -100,7 +102,7 @@ pub fn is_mtk_pkg_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box
}
pub fn extract_mtk_pkg(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::<MtkPkgContext>().ok()).ok_or("Context is invalid or missing!")?;
let file_size = file.metadata()?.len();
@@ -198,13 +200,13 @@ pub fn extract_mtk_pkg(app_ctx: &AppContext, ctx: Option<Box<dyn Any>>) -> Resul
};
//for compressed part create temp file
let output_path = Path::new(app_ctx.output_dir).join(part_entry.name() + if part_entry.is_compressed() {".lzhs"} else {".bin"});
fs::create_dir_all(app_ctx.output_dir)?;
let output_path = Path::new(&app_ctx.output_dir).join(part_entry.name() + if part_entry.is_compressed() {".lzhs"} else {".bin"});
fs::create_dir_all(&app_ctx.output_dir)?;
let mut out_file = OpenOptions::new().write(true).read(true)/* for lzhs */.create(true).open(&output_path)?;
out_file.write_all(&out_data[CRYPTED_HEADER_SIZE + extra_header_len as usize..])?;
if part_entry.is_compressed() {
let lzhs_out_path = Path::new(app_ctx.output_dir).join(part_entry.name() + ".bin");
let lzhs_out_path = Path::new(&app_ctx.output_dir).join(part_entry.name() + ".bin");
match decompress_lzhs_fs_file2file(&out_file, lzhs_out_path) {
Ok(()) => {
println!("- Decompressed Successfully!");