mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04:22 +02:00
WIP pfl upg extractor
This commit is contained in:
+14
-24
@@ -1,6 +1,6 @@
|
||||
use std::str;
|
||||
use std::path::{Path};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{Read, Write};
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
|
||||
use flate2::read::GzDecoder;
|
||||
@@ -25,20 +25,10 @@ fn decompress_gzip(compressed_data: &[u8]) -> Result<Vec<u8>, Box<dyn std::error
|
||||
Ok(decompressed)
|
||||
}
|
||||
|
||||
fn read_exact<R: Read>(reader: &mut R, size: usize) -> io::Result<Vec<u8>> {
|
||||
let mut buf = vec![0u8; size];
|
||||
reader.read_exact(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn string_from_bytes(buf: &[u8]) -> String {
|
||||
let end = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
|
||||
String::from_utf8_lossy(&buf[..end]).to_string()
|
||||
}
|
||||
|
||||
pub fn extract_tpv_timg(mut file: &File, output_folder: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
//TIMG header
|
||||
let _timg = read_exact(&mut file, 288)?;
|
||||
let _timg = common::read_exact(&mut file, 288)?;
|
||||
|
||||
loop {
|
||||
//PIMG
|
||||
@@ -50,35 +40,35 @@ pub fn extract_tpv_timg(mut file: &File, output_folder: &str) -> Result<(), Box<
|
||||
}
|
||||
|
||||
//4 bytes 00
|
||||
let _ = read_exact(&mut file, 4)?;
|
||||
let _ = common::read_exact(&mut file, 4)?;
|
||||
|
||||
//4 bytes size
|
||||
let size_bytes = read_exact(&mut file, 4)?;
|
||||
let size_bytes = common::read_exact(&mut file, 4)?;
|
||||
let size = u32::from_le_bytes(size_bytes.try_into().unwrap());
|
||||
|
||||
//4 bytes nothing
|
||||
let _ = read_exact(&mut file, 4)?;
|
||||
let _ = common::read_exact(&mut file, 4)?;
|
||||
|
||||
//16 bytes checksum? or maybe signature
|
||||
let _checksum = read_exact(&mut file, 16)?;
|
||||
let _checksum = common::read_exact(&mut file, 16)?;
|
||||
|
||||
//16 bytes name
|
||||
let name_bytes = read_exact(&mut file, 16)?;
|
||||
let name = string_from_bytes(&name_bytes);
|
||||
let name_bytes = common::read_exact(&mut file, 16)?;
|
||||
let name = common::string_from_bytes(&name_bytes);
|
||||
|
||||
//64 bytes destination device
|
||||
let dev_bytes = read_exact(&mut file, 64)?;
|
||||
let dev = string_from_bytes(&dev_bytes);
|
||||
let dev_bytes = common::read_exact(&mut file, 64)?;
|
||||
let dev = common::string_from_bytes(&dev_bytes);
|
||||
|
||||
//16 bytes compression type
|
||||
let comp_bytes = read_exact(&mut file, 16)?;
|
||||
let comp_type = string_from_bytes(&comp_bytes);
|
||||
let comp_bytes = common::read_exact(&mut file, 16)?;
|
||||
let comp_type = common::string_from_bytes(&comp_bytes);
|
||||
|
||||
//1032 bytes maybe comment? skip this
|
||||
let _ = read_exact(&mut file, 1032)?;
|
||||
let _ = common::read_exact(&mut file, 1032)?;
|
||||
|
||||
//actual data
|
||||
let data = read_exact(&mut file, size as usize)?;
|
||||
let data = common::read_exact(&mut file, size as usize)?;
|
||||
|
||||
println!("PIMG - Name: {} Size: {} Dest: {} Compression: {}", name, size, dev, comp_type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user