mtk_pkg: fix mistake preventing extraction of unencrypted partitions

This commit is contained in:
theubusu
2026-01-08 18:17:50 +01:00
parent 38bea12d11
commit e69fac6e83
+6 -4
View File
@@ -104,9 +104,11 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
continue continue
} }
let mut out_data;
if part_entry.is_encrypted() {
let mut matching_key: Option<[u8; 16]> = None; let mut matching_key: Option<[u8; 16]> = None;
let mut matching_iv: Option<[u8; 16]> = None; let mut matching_iv: Option<[u8; 16]> = None;
if part_entry.is_encrypted() {
let crypted_header = &data[..48]; let crypted_header = &data[..48];
// try decrypting with vendor magic repeated 4 times (works for most) // try decrypting with vendor magic repeated 4 times (works for most)
@@ -135,9 +137,7 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
} }
} }
} }
}
let mut out_data;
if matching_key.is_some() && matching_iv.is_some() { if matching_key.is_some() && matching_iv.is_some() {
let (key_array, iv_array) = (matching_key.unwrap(), matching_iv.unwrap()); let (key_array, iv_array) = (matching_key.unwrap(), matching_iv.unwrap());
//data aligned to 16 bytes is AES encrypted. the remaining unaligned data is XORed with the key //data aligned to 16 bytes is AES encrypted. the remaining unaligned data is XORed with the key
@@ -147,11 +147,13 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
for (i, &b) in xor_tail.iter().enumerate() { for (i, &b) in xor_tail.iter().enumerate() {
out_data.push(b ^ key_array[i % key_array.len()]); out_data.push(b ^ key_array[i % key_array.len()]);
} }
} else { } else {
println!("- Failed to decrypt data!"); println!("- Failed to decrypt data!");
continue continue
} }
} else {
out_data = data;
}
//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" {