mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04:22 +02:00
mtk_pkg: fix mistake preventing extraction of unencrypted partitions
This commit is contained in:
+17
-15
@@ -104,9 +104,11 @@ pub fn extract_mtk_pkg(mut file: &File, output_folder: &str) -> Result<(), Box<d
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut matching_key: Option<[u8; 16]> = None;
|
let mut out_data;
|
||||||
let mut matching_iv: Option<[u8; 16]> = None;
|
|
||||||
if part_entry.is_encrypted() {
|
if part_entry.is_encrypted() {
|
||||||
|
let mut matching_key: Option<[u8; 16]> = None;
|
||||||
|
let mut matching_iv: Option<[u8; 16]> = None;
|
||||||
|
|
||||||
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,22 +137,22 @@ 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
|
let align_len = data.len() & !15;
|
||||||
let align_len = data.len() & !15;
|
let (aes_enc, xor_tail) = data.split_at(align_len);
|
||||||
let (aes_enc, xor_tail) = data.split_at(align_len);
|
out_data = decrypt_aes128_cbc_nopad(aes_enc, &key_array, &iv_array)?;
|
||||||
out_data = decrypt_aes128_cbc_nopad(aes_enc, &key_array, &iv_array)?;
|
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 {
|
||||||
|
println!("- Failed to decrypt data!");
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
println!("- Failed to decrypt data!");
|
out_data = data;
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//strip iMtK thing and get version
|
//strip iMtK thing and get version
|
||||||
|
|||||||
Reference in New Issue
Block a user