mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-15 21:00:03 +02:00
funai_bdp: add support for multiple keys and add more keys
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
use binrw::BinRead;
|
||||
use crate::utils::common;
|
||||
|
||||
pub static DEC_KEY: u32 = 0x13641A98;
|
||||
|
||||
#[derive(BinRead)]
|
||||
pub struct IndexTableEntry {
|
||||
name_bytes: [u8; 32],
|
||||
|
||||
@@ -10,27 +10,38 @@ use binrw::BinReaderExt;
|
||||
use crate::utils::common;
|
||||
use crate::formats::funai_upg::funai_des::funai_des_decrypt;
|
||||
use include::*;
|
||||
use crate::keys;
|
||||
|
||||
pub struct FunaiBdpContext {
|
||||
key: u32,
|
||||
}
|
||||
|
||||
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 {
|
||||
for key_hex in keys::FUNAI_BDP {
|
||||
let key_bytes = hex::decode(key_hex)?;
|
||||
let key_u32 = u32::from_le_bytes(key_bytes.as_slice().try_into()?);
|
||||
let decrypted = funai_des_decrypt(&header, key_u32);
|
||||
|
||||
if decrypted == b"index_table\x00\x00\x00\x00\x00"{
|
||||
return Ok(Some(Box::new(FunaiBdpContext {key: key_u32})))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_funai_bdp(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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 ctx = ctx.downcast::<FunaiBdpContext>().expect("Missing context");
|
||||
|
||||
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);
|
||||
data = funai_des_decrypt(&data, ctx.key);
|
||||
let mut file_reader = Cursor::new(data);
|
||||
|
||||
file_reader.seek(SeekFrom::Start(0x20))?;
|
||||
@@ -46,15 +57,16 @@ pub fn extract_funai_bdp(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(),
|
||||
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)?;
|
||||
file_reader.seek(SeekFrom::Start(entry.offset as u64))?;
|
||||
let data = common::read_exact(&mut file_reader, entry.size as usize)?;
|
||||
|
||||
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)?;
|
||||
|
||||
//at start of location there is an additional 0x20 with the entry's name
|
||||
out_file.write_all(&data[0x20..])?;
|
||||
|
||||
println!("-- Saved file!");
|
||||
}
|
||||
|
||||
@@ -108,6 +108,13 @@ pub static FUNAI_UPG: &[&str] = &[
|
||||
("68353031"), //PHL-0SDX
|
||||
];
|
||||
|
||||
//Funai BDP keys
|
||||
pub static FUNAI_BDP: &[&str] = &[
|
||||
("981A6413"),
|
||||
("81AE6734"),
|
||||
("09E87783"),
|
||||
];
|
||||
|
||||
//EPK keys
|
||||
//github.com/openlgtv/epk2extract
|
||||
pub static EPK: &[(&str, &str)] = &[
|
||||
|
||||
Reference in New Issue
Block a user