Skip to content

Commit

Permalink
chore: Added 16 new HSSP test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Aug 13, 2024
1 parent 1ba727b commit c10a379
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/formats/hssp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod parser;

#[derive(Debug)]
pub struct HsspMetadata {
pub version: u8,
pub checksum: u32,
Expand All @@ -9,11 +8,11 @@ pub struct HsspMetadata {
pub has_main: bool,
}

#[derive(Debug)]
pub struct HsspEncryption {
pub hash: [u8; 32],
pub in_hash: [u8; 32],
pub iv: [u8; 16],
pub data: Option<Vec<u8>>,
}

#[derive(Debug)]
Expand Down
38 changes: 32 additions & 6 deletions src/formats/hssp/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ pub fn metadata(file: &mut dyn DataReader, password: Option<&String>) -> HsspMet
let iv: [u8; 16] = file.read_u8array(&16).try_into().unwrap();
let main = file.read_u32le();
if version == 2 {
let bytes = file.read_u128le();
if bytes == 0 {
let mut is_empty = true;
file.read_u8array(&64).into_iter().for_each(|byte| {
if !is_empty {
return;
}
if byte != 0 {
is_empty = false;
}
});
if is_empty {
version = 3;
} else {
file.jump(&-16);
file.jump(&-64);
}
}

let encrypted = !(pwd_hash == [0; 32] && iv == [0; 16]);

let decrypted_data: Vec<u8>;
let mut decrypted_data: Option<Vec<u8>> = None;
let body: &mut dyn DataReader = if encrypted {
let key = sha256::hash_buf(password.unwrap_or(&"".to_string()).as_bytes());
let in_hash = sha256::hash_buf(&key);
Expand All @@ -42,14 +50,15 @@ pub fn metadata(file: &mut dyn DataReader, password: Option<&String>) -> HsspMet
hash: pwd_hash,
iv,
in_hash,
data: None,
}),
files: Vec::new(),
has_main: false,
};
} else {
let data = file.read_u8array(&{ file.get_size() - if version > 2 { 128 } else { 64 } });
decrypted_data = aes256cbc::decrypt(&data, &key, &iv);
&mut VirtualFileReader::new(&decrypted_data)
decrypted_data = Some(aes256cbc::decrypt(&data, &key, &iv));
&mut VirtualFileReader::new(decrypted_data.as_mut().unwrap())
}
} else {
file
Expand Down Expand Up @@ -84,6 +93,7 @@ pub fn metadata(file: &mut dyn DataReader, password: Option<&String>) -> HsspMet
hash: pwd_hash,
iv,
in_hash: pwd_hash,
data: decrypted_data,
})
} else {
None
Expand All @@ -101,3 +111,19 @@ pub fn check_integrity_all(file: &mut dyn DataReader, metadata: &HsspMetadata) -
}
false
}

pub fn get_file(
reader: &mut dyn DataReader,
metadata: &HsspMetadata,
entry: &HsspFileEntry,
) -> Vec<u8> {
if metadata.encryption.is_some() {
let mut body =
VirtualFileReader::new(metadata.encryption.as_ref().unwrap().data.as_ref().unwrap());
body.seek(&entry.offset);
body.read_u8array(&entry.size)
} else {
reader.seek(&entry.offset);
reader.read_u8array(&entry.size)
}
}
Loading

0 comments on commit c10a379

Please sign in to comment.