WIP pfl upg extractor

This commit is contained in:
theubusu
2025-09-27 00:31:18 +02:00
parent 81fd148cb8
commit 6e8fd5f0cc
7 changed files with 441 additions and 29 deletions
+12 -1
View File
@@ -1,5 +1,5 @@
use std::fs::{File};
use std::io::{Read, Seek, SeekFrom};
use std::io::{self, Read, Seek, SeekFrom};
pub fn read_file(mut file: &File, offset: u64, size: usize) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
file.seek(SeekFrom::Start(offset))?;
@@ -9,4 +9,15 @@ pub fn read_file(mut file: &File, offset: u64, size: usize) -> Result<Vec<u8>, B
// reset seek (!
file.seek(SeekFrom::Start(offset))?;
Ok(buffer)
}
pub 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)
}
pub 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()
}