RESTRUCTURING 1

- change formats to have their own folders with mod + include files + anything they want
- change format list to be defined in formats.rs instead of in each format
- move utils to their respective formats
- some minor code changes in some formats
This commit is contained in:
theubusu
2026-02-17 17:28:59 +01:00
parent 9fe39280cd
commit aa2249f024
69 changed files with 1678 additions and 1629 deletions
+56
View File
@@ -0,0 +1,56 @@
use crate::utils::common;
use binrw::BinRead;
//v3 key + iv
pub static V3_KEY: [u8; 16] = [0x32, 0xe5, 0x26, 0x1e, 0x22, 0x67, 0x5e, 0x93, 0x20, 0xcf, 0x35, 0x91, 0x7c, 0x63, 0x7a, 0x36];
pub static V3_IV: [u8; 16] = [0xe3, 0x9f, 0x36, 0x39, 0x56, 0x9a, 0x6b, 0x8d, 0x3f, 0x2e, 0xc9, 0x44, 0xd9, 0xbc, 0xec, 0x43];
#[derive(BinRead)]
pub struct Header {
_magic_bytes: [u8; 16],
pub file_version: [u8; 4],
_unk1: u32,
ver1_bytes: [u8; 16],
ver2_bytes: [u8; 16],
_unk2: u16,
_type: u8,
pub keep_size: u32,
_unk3: u8,
pub data_start_offset: u32,
pub data_size: u32,
_data_size_2: u32,
pub skip_size: u32,
_unk4: u16,
_encryption_method: u8, // 0x01 - AES128, 0x02 - AES256
_hash_type: u8, // 0x01 - MD5, 0x02 - SHA1
ver3_bytes: [u8; 16],
ver4_bytes: [u8; 16],
_unk6: [u8; 11],
pub payload_count: u8,
}
impl Header {
pub fn ver1(&self) -> String {
common::string_from_bytes(&self.ver1_bytes).replace('\n', "")
}
pub fn ver2(&self) -> String {
common::string_from_bytes(&self.ver2_bytes).replace('\n', "")
}
pub fn ver3(&self) -> String {
common::string_from_bytes(&self.ver3_bytes).replace('\n', "")
}
pub fn ver4(&self) -> String {
common::string_from_bytes(&self.ver4_bytes).replace('\n', "")
}
}
#[derive(BinRead)]
pub struct Entry {
name_bytes: [u8; 16],
pub start_offset: u32,
pub size: u32,
}
impl Entry {
pub fn name(&self) -> String {
common::string_from_bytes(&self.name_bytes)
}
}
+83
View File
@@ -0,0 +1,83 @@
mod include;
use std::any::Any;
use crate::AppContext;
use std::path::{Path};
use std::fs::{self, OpenOptions};
use std::io::{Write, Read, Seek, SeekFrom, Cursor};
use binrw::BinReaderExt;
use crate::utils::aes::{decrypt_aes128_cbc_nopad};
use crate::utils::common;
use include::*;
pub fn is_invincible_image_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
let file = match app_ctx.file() {Some(f) => f, None => return Ok(None)};
let header = common::read_file(&file, 0, 16)?;
if header == b"INVINCIBLE_IMAGE" {
Ok(Some(Box::new(())))
} else {
Ok(None)
}
}
pub fn extract_invincible_image(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
let mut file = app_ctx.file().ok_or("Extractor expected file")?;
let header: Header = file.read_le()?;
println!("File info:\nFile Version: {}.{}\nVersion(1): {}\nVersion(2): {}\nVersion(3): {}\nVersion(4): {}\nData size: {}\nData start offset: {}\nKeep data size: {}\nSkip data size: {}\n\nPayload Count: {}",
header.file_version[0], header.file_version[1], header.ver1(), header.ver2(), header.ver3(), header.ver4(), header.data_size, header.data_start_offset, header.keep_size, header.skip_size, header.payload_count);
let mut entries: Vec<Entry> = Vec::new();
for i in 0..header.payload_count {
let entry: Entry = file.read_le()?;
println!("{}. {}, Start offset: {}, Size: {}",
i + 1, entry.name(), entry.start_offset, entry.size);
entries.push(entry);
}
if header.file_version[0] != 3 {
println!("\nSorry, this version of the file is not supported!");
return Ok(())
}
let mut encrypted_data = Vec::new();
let mut buffer = vec![0u8; header.keep_size as usize];
file.seek(SeekFrom::Start(header.data_start_offset.into()))?;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break; // EOF
}
encrypted_data.extend_from_slice(&buffer[..bytes_read]);
file.seek(SeekFrom::Current(header.skip_size.into()))?;
}
println!("\nDecrypting data...");
let decrypted_data = decrypt_aes128_cbc_nopad(&encrypted_data, &V3_KEY, &V3_IV)?;
let mut data_reader = Cursor::new(decrypted_data);
let mut i = 1;
for entry in entries {
println!("\n({}/{}) - {}, Size: {}", i, header.payload_count, entry.name(), entry.size);
let data = common::read_exact(&mut data_reader, entry.size as usize)?;
let output_path = Path::new(&app_ctx.output_dir).join(entry.name() + ".bin");
fs::create_dir_all(&app_ctx.output_dir)?;
let mut out_file = OpenOptions::new().write(true).create(true).open(output_path)?;
out_file.write_all(&data)?;
println!("- Saved file!");
i += 1;
}
println!("\nExtraction finished!");
Ok(())
}