mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 13:14:22 +02:00
move common msd functions + cleanup formats.rs + fix compiler warning in epk3
This commit is contained in:
+2
-34
@@ -2,14 +2,11 @@ use std::fs::{self, File, OpenOptions};
|
||||
use std::path::{Path};
|
||||
use std::io::{Cursor, Write, Seek, SeekFrom};
|
||||
|
||||
use aes::Aes128;
|
||||
use cbc::{Decryptor, cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}};
|
||||
|
||||
type Aes128CbcDec = Decryptor<Aes128>;
|
||||
|
||||
use crate::common;
|
||||
use crate::keys;
|
||||
|
||||
use crate::formats::msd::{decrypt_aes_salted_tizen, decrypt_aes_tizen};
|
||||
|
||||
pub fn is_msd11_file(file: &File) -> bool {
|
||||
let header = common::read_file(&file, 0, 6).expect("Failed to read from file.");
|
||||
if header == b"MSDU11" {
|
||||
@@ -26,35 +23,6 @@ struct Section {
|
||||
name: String,
|
||||
}
|
||||
|
||||
fn decrypt_aes_salted_tizen(encrypted_data: &[u8], passphrase_bytes: &Vec<u8>) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
let mut data = encrypted_data.to_vec();
|
||||
|
||||
assert!(data[0..8].to_vec() == b"Salted__", "invalid encrypted data!");
|
||||
let salt = &data[8..16];
|
||||
|
||||
//iv = md5 of salt
|
||||
let iv = md5::compute(&salt);
|
||||
|
||||
let decryptor = Aes128CbcDec::new((&(**passphrase_bytes)).into(), (&iv.0).into());
|
||||
let decrypted = decryptor.decrypt_padded_mut::<Pkcs7>(&mut data[16..])
|
||||
.map_err(|e| format!("Decryption error!!: {:?}", e))?;
|
||||
|
||||
Ok(decrypted.to_vec())
|
||||
}
|
||||
|
||||
fn decrypt_aes_tizen(encrypted_data: &[u8], passphrase_bytes: &Vec<u8>, salt: &[u8]) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
|
||||
let mut data = encrypted_data.to_vec();
|
||||
|
||||
//iv = md5 of salt
|
||||
let iv = md5::compute(&salt);
|
||||
|
||||
let decryptor = Aes128CbcDec::new((&(**passphrase_bytes)).into(), (&iv.0).into());
|
||||
let decrypted = decryptor.decrypt_padded_mut::<Pkcs7>(&mut data)
|
||||
.map_err(|e| format!("Decryption error!!: {:?}", e))?;
|
||||
|
||||
Ok(decrypted.to_vec())
|
||||
}
|
||||
|
||||
pub fn extract_msd11(mut file: &File, output_folder: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let _magic = common::read_exact(&mut file, 6)?; //MSDU11 magic
|
||||
|
||||
Reference in New Issue
Block a user