mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04:22 +02:00
msd10,11: implement OUITH parsers for Tizen, some key cleanup, debug print in old parser
This commit is contained in:
+27
-39
@@ -1,12 +1,13 @@
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::path::{Path};
|
||||
use std::io::{Cursor, Write, Seek, SeekFrom};
|
||||
use std::io::{Write, Seek, SeekFrom};
|
||||
use binrw::{BinRead, BinReaderExt};
|
||||
|
||||
use crate::utils::common;
|
||||
use crate::keys;
|
||||
use crate::formats::msd::{decrypt_aes_salted_old, decrypt_aes_salted_tizen, decrypt_aes_tizen};
|
||||
use crate::utils::msd_ouith_parser_old::{parse_ouith_blob};
|
||||
use crate::utils::msd_ouith_parser_tizen_1_8::{parse_blob_1_8};
|
||||
|
||||
#[derive(BinRead)]
|
||||
struct FileHeader {
|
||||
@@ -40,21 +41,6 @@ struct Section {
|
||||
size: u32,
|
||||
}
|
||||
|
||||
#[derive(BinRead)]
|
||||
struct TizenTocEntry {
|
||||
#[br(count = 44)] _unk1: Vec<u8>,
|
||||
_name_length: u8,
|
||||
#[br(count = _name_length)] name_bytes: Vec<u8>,
|
||||
#[br(count = 314)] _unk2: Vec<u8>,
|
||||
#[br(count = 8)] salt: Vec<u8>,
|
||||
#[br(count = 13)] _unk3: Vec<u8>,
|
||||
}
|
||||
impl TizenTocEntry {
|
||||
fn name(&self) -> String {
|
||||
common::string_from_bytes(&self.name_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_msd10_file(file: &File) -> bool {
|
||||
let header = common::read_file(&file, 0, 6).expect("Failed to read from file.");
|
||||
if header == b"MSDU10" {
|
||||
@@ -118,31 +104,37 @@ pub fn extract_msd10(mut file: &File, output_folder: &str) -> Result<(), Box<dyn
|
||||
//parse TOC
|
||||
if firmware_type == "tizen" {
|
||||
let toc = decrypt_aes_salted_tizen(&toc_data, &passphrase_bytes)?;
|
||||
let mut toc_reader = Cursor::new(toc);
|
||||
let (items, info) = parse_blob_1_8(&toc)?;
|
||||
|
||||
toc_reader.seek(SeekFrom::Current(256))?; // probably signature
|
||||
toc_reader.seek(SeekFrom::Current(50))?; // Tizen Software Upgrade Tree Binary Format ver. 1.8
|
||||
if let Some(info) = info {
|
||||
println!("\nImage info:\n{} {}.{} {}/{}/{}",
|
||||
info.name(), info.major_ver, info.minor_ver, info.date_day, info.date_month, info.date_year);
|
||||
}
|
||||
|
||||
for i in 0..header.section_count {
|
||||
let entry: TizenTocEntry = toc_reader.read_le()?;
|
||||
let offset = sections[i as usize].offset;
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
let size = sections[i as usize].size;
|
||||
let offset = sections[i as usize].offset;
|
||||
|
||||
println!("\n({}/{}) - {}, Size: {}", sections[i as usize].index, sections.len(), entry.name(), size);
|
||||
println!("\n({}/{}) - {}, Size: {}",
|
||||
item.item_id, items.len(), item.name, size);
|
||||
|
||||
let encrypted_data = common::read_file(&file, offset as u64, size as usize)?;
|
||||
assert!(sections[i as usize].index == item.item_id, "Item ID in TOC does not match ID from header!");
|
||||
|
||||
println!("- Decrypting...");
|
||||
let decrypted_data = decrypt_aes_tizen(&encrypted_data, &passphrase_bytes, &entry.salt)?;
|
||||
let stored_data = common::read_file(&file, offset as u64, size as usize)?;
|
||||
|
||||
let output_path = Path::new(&output_folder).join(entry.name());
|
||||
let out_data;
|
||||
if item.aes_encryption {
|
||||
println!("- Decrypting...");
|
||||
let salt = item.aes_salt.as_ref().ok_or("AES salt missing!")?;
|
||||
out_data = decrypt_aes_tizen(&stored_data, &passphrase_bytes, salt)?;
|
||||
} else {
|
||||
out_data = stored_data;
|
||||
}
|
||||
|
||||
let output_path = Path::new(&output_folder).join(item.name.clone());
|
||||
fs::create_dir_all(&output_folder)?;
|
||||
let mut out_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(output_path)?;
|
||||
|
||||
out_file.write_all(&decrypted_data)?;
|
||||
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
|
||||
out_file.write_all(&out_data)?;
|
||||
|
||||
println!("-- Saved file!");
|
||||
|
||||
@@ -158,6 +150,7 @@ pub fn extract_msd10(mut file: &File, output_folder: &str) -> Result<(), Box<dyn
|
||||
}
|
||||
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
let offset = sections[i as usize].offset;
|
||||
let type_str = if item.item_type == 0x0A {"Partition"} else if item.item_type == 0x0B {"File"} else if item.item_type == 0x11 {"CMAC Data"} else {"Unknown"};
|
||||
println!("\n({}/{}) - {}, Type: {}, Size: {}",
|
||||
item.item_id, items.len(), item.name, type_str, item.all_size);
|
||||
@@ -169,7 +162,6 @@ pub fn extract_msd10(mut file: &File, output_folder: &str) -> Result<(), Box<dyn
|
||||
continue
|
||||
}
|
||||
|
||||
let offset = sections[i as usize].offset;
|
||||
file.seek(SeekFrom::Start(offset as u64))?;
|
||||
|
||||
//skip heading metadata thing
|
||||
@@ -186,11 +178,7 @@ pub fn extract_msd10(mut file: &File, output_folder: &str) -> Result<(), Box<dyn
|
||||
|
||||
let output_path = Path::new(&output_folder).join(item.name.clone());
|
||||
fs::create_dir_all(&output_folder)?;
|
||||
let mut out_file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(output_path)?;
|
||||
|
||||
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
|
||||
out_file.write_all(&out_data)?;
|
||||
|
||||
println!("-- Saved file!");
|
||||
|
||||
Reference in New Issue
Block a user