mtk_pkg & old: fix bug in version detection, add compression detection. fix mistake in main

This commit is contained in:
theubusu
2025-12-17 01:55:40 +01:00
parent 16427a8767
commit f2027924bc
3 changed files with 18 additions and 11 deletions
+11 -5
View File
@@ -44,7 +44,10 @@ impl PartEntry {
self.name().is_ascii() self.name().is_ascii()
} }
fn is_encrypted(&self) -> bool { fn is_encrypted(&self) -> bool {
(self.flags & 1 << 0) == 1 << 0 (self.flags & 1 << 0) != 0
}
fn is_compressed(&self) -> bool { //lzhs fs
(self.flags & 1 << 8) != 0
} }
} }
@@ -91,7 +94,8 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
break break
} }
println!("\n#{} - {}, Size: {} {}", part_n, part_entry.name(), part_entry.size, if part_entry.is_encrypted() {"[ENCRYPTED]"} else {""} ); println!("\n#{} - {}, Size: {}{} {}",
part_n, part_entry.name(), part_entry.size, if part_entry.is_compressed() {" [COMPRESSED]"} else {""}, if part_entry.is_encrypted() {"[ENCRYPTED]"} else {""} );
let data = common::read_exact(&mut file, part_entry.size as usize + 48)?; let data = common::read_exact(&mut file, part_entry.size as usize + 48)?;
@@ -142,9 +146,11 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
//strip iMtK thing and get version //strip iMtK thing and get version
let extra_header_len = if &out_data[48..52] == b"iMtK" { let extra_header_len = if &out_data[48..52] == b"iMtK" {
let imtk_len = u32::from_le_bytes(out_data[52..56].try_into().unwrap()); let imtk_len = u32::from_le_bytes(out_data[52..56].try_into().unwrap());
let version_len = u32::from_le_bytes(out_data[56..60].try_into().unwrap()); if &out_data[56..60] != b"iPAd" {
let version = common::string_from_bytes(&out_data[60..60 + version_len as usize]); let version_len = u32::from_le_bytes(out_data[56..60].try_into().unwrap());
println!("- Version: {}", version); let version = common::string_from_bytes(&out_data[60..60 + version_len as usize]);
println!("- Version: {}", version);
}
imtk_len + 8 imtk_len + 8
} else { } else {
0 0
+6 -5
View File
@@ -81,9 +81,8 @@ pub fn extract_mtk_pkg_old(mut file: &File, output_folder: &str) -> Result<(), B
while file.stream_position()? < file_size as u64 { while file.stream_position()? < file_size as u64 {
part_n += 1; part_n += 1;
let part_entry: PartEntry = file.read_le()?; let part_entry: PartEntry = file.read_le()?;
let is_encrypted = if (part_entry.flags & 1 << 0) == 1 << 0 {true} else {false};
println!("\n#{} - {}, Size: {} {}", part_n, part_entry.name(), part_entry.size, if is_encrypted {"[ENCRYPTED]"} else {""} ); println!("\n#{} - {}, Size: {} {}", part_n, part_entry.name(), part_entry.size, if part_entry.is_encrypted() {"[ENCRYPTED]"} else {""} );
let data = common::read_exact(&mut file, part_entry.size as usize)?; let data = common::read_exact(&mut file, part_entry.size as usize)?;
let out_data; let out_data;
@@ -99,9 +98,11 @@ pub fn extract_mtk_pkg_old(mut file: &File, output_folder: &str) -> Result<(), B
//strip iMtK thing and get version //strip iMtK thing and get version
let extra_header_len = if &out_data[0..4] == b"iMtK" { let extra_header_len = if &out_data[0..4] == b"iMtK" {
let imtk_len = u32::from_le_bytes(out_data[4..8].try_into().unwrap()); let imtk_len = u32::from_le_bytes(out_data[4..8].try_into().unwrap());
let version_len = u32::from_le_bytes(out_data[8..12].try_into().unwrap()); if &out_data[56..60] != b"iPAd" {
let version = common::string_from_bytes(&out_data[12..12 + version_len as usize]); let version_len = u32::from_le_bytes(out_data[8..12].try_into().unwrap());
println!("- Version: {}", version); let version = common::string_from_bytes(&out_data[12..12 + version_len as usize]);
println!("- Version: {}", version);
}
imtk_len + 8 imtk_len + 8
} else { } else {
0 0
+1 -1
View File
@@ -70,7 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Novatek TIMG file detected!"); println!("Novatek TIMG file detected!");
formats::nvt_timg::extract_nvt_timg(&file, &output_path)?; formats::nvt_timg::extract_nvt_timg(&file, &output_path)?;
} }
if formats::android_ota_payload::is_android_ota_payload_file(&file) { else if formats::android_ota_payload::is_android_ota_payload_file(&file) {
println!("Android OTA payload file detected!"); println!("Android OTA payload file detected!");
formats::android_ota_payload::extract_android_ota_payload(&file, &output_path)?; formats::android_ota_payload::extract_android_ota_payload(&file, &output_path)?;
} }