mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-15 21:00:03 +02:00
add funai_bdp extractor
This commit is contained in:
@@ -21,6 +21,7 @@ pub mod sony_bdp;
|
||||
pub mod rvp;
|
||||
pub mod funai_upg;
|
||||
pub mod funai_upg_phl;
|
||||
pub mod funai_bdp;
|
||||
pub mod pana_dvd;
|
||||
pub mod android_ota_payload;
|
||||
pub mod bdl;
|
||||
@@ -116,6 +117,11 @@ pub fn get_registry() -> Vec<Format> {
|
||||
detector_func: crate::formats::funai_upg_phl::is_funai_upg_phl_file,
|
||||
extractor_func: crate::formats::funai_upg_phl::extract_funai_upg_phl,
|
||||
},
|
||||
Format {
|
||||
name: "funai_bdp",
|
||||
detector_func: crate::formats::funai_bdp::is_funai_bdp_file,
|
||||
extractor_func: crate::formats::funai_bdp::extract_funai_bdp,
|
||||
},
|
||||
Format {
|
||||
name: "pana_dvd",
|
||||
detector_func: crate::formats::pana_dvd::is_pana_dvd_file,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
use binrw::BinRead;
|
||||
use crate::utils::common;
|
||||
|
||||
pub static DEC_KEY: u32 = 0x13641A98;
|
||||
|
||||
#[derive(BinRead)]
|
||||
pub struct IndexTableEntry {
|
||||
name_bytes: [u8; 32],
|
||||
pub offset: u32,
|
||||
pub size: u32,
|
||||
_unk: u32,
|
||||
}
|
||||
impl IndexTableEntry {
|
||||
pub fn name(&self) -> String {
|
||||
common::string_from_bytes(&self.name_bytes)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
mod include;
|
||||
use std::any::Any;
|
||||
use crate::AppContext;
|
||||
|
||||
use std::path::Path;
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::io::{Cursor, Read, Seek, SeekFrom, Write};
|
||||
use binrw::BinReaderExt;
|
||||
|
||||
use crate::utils::common;
|
||||
use crate::formats::funai_upg::funai_des::funai_des_decrypt;
|
||||
use include::*;
|
||||
|
||||
pub fn is_funai_bdp_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)?;
|
||||
let dec_header = funai_des_decrypt(&header, DEC_KEY);
|
||||
|
||||
if dec_header == b"index_table\x00\x00\x00\x00\x00"{
|
||||
Ok(Some(Box::new(())))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_funai_bdp(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 mut data = Vec::new(); //to decrypt entire file
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
println!("Decrypting file...");
|
||||
data = funai_des_decrypt(&data, DEC_KEY);
|
||||
let mut file_reader = Cursor::new(data);
|
||||
|
||||
file_reader.seek(SeekFrom::Start(0x20))?;
|
||||
|
||||
let index_entry_count: u32 = file_reader.read_le()?;
|
||||
let mut entries: Vec<IndexTableEntry> = Vec::new();
|
||||
|
||||
for _i in 0..index_entry_count {
|
||||
let entry: IndexTableEntry = file_reader.read_le()?;
|
||||
entries.push(entry);
|
||||
}
|
||||
|
||||
for (i, entry) in entries.iter().enumerate() {
|
||||
println!("\n({}/{}) - {}, Offset: {}, Size: {}", i +1, index_entry_count, entry.name(), entry.offset, entry.size);
|
||||
|
||||
//at start of location there is an additional 0x20 with the entry's name
|
||||
file_reader.seek(SeekFrom::Start(entry.offset as u64 + 0x20))?;
|
||||
let data = common::read_exact(&mut file_reader, entry.size as usize - 0x20)?;
|
||||
|
||||
let output_path = Path::new(&app_ctx.output_dir).join(format!("{}.bin", entry.name()));
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -34,7 +34,7 @@ fn des_function(mut state: u32, key: u32) -> u32 {
|
||||
}
|
||||
|
||||
pub fn funai_des_decrypt(input: &[u8], key: u32) -> Vec<u8> {
|
||||
assert!(input.len() % 8 == 0);
|
||||
//assert!(input.len() % 8 == 0);
|
||||
let mut buf = input.to_vec();
|
||||
|
||||
for chunk in buf.chunks_exact_mut(8) {
|
||||
|
||||
Reference in New Issue
Block a user