parent
fd215a8adb
commit
807523bf22
@ -0,0 +1,18 @@
|
||||
use nom::Err::{Error as NomError, Failure as NomFailure};
|
||||
|
||||
pub enum ParseError {
|
||||
Error(NomError),
|
||||
Failure(NomFailure),
|
||||
}
|
||||
|
||||
impl From<NomError> for ParseError {
|
||||
fn from(e: NomError) -> Self {
|
||||
ParseError::Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NomFailure> for ParseError {
|
||||
fn from(e: NomFailure) -> Self {
|
||||
ParseError::Failure(e)
|
||||
}
|
||||
}
|
@ -1,13 +1,33 @@
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
use std::io::{Read};
|
||||
|
||||
use nom::Err::{Error as NomError, Failure as NomFailure};
|
||||
|
||||
use crate::parsers::dcx;
|
||||
use crate::unpackers::errors::{self as unpackers_errors, UnpackError};
|
||||
|
||||
pub fn extract_dcx(dcx_path: &str) -> Result<(), io::Error> {
|
||||
pub fn extract_dcx(dcx_path: &str, output_path: &str) -> Result<(), UnpackError> {
|
||||
let mut dcx_file = fs::File::open(dcx_path)?;
|
||||
let file_len = dcx_file.metadata()?.len() as usize;
|
||||
let mut dcx_data = vec![0u8; file_len];
|
||||
dcx_file.read_exact(&mut dcx_data)?;
|
||||
dcx::parse(&dcx_data);
|
||||
let dcx = match dcx::parse(&dcx_data) {
|
||||
Ok((_, dcx)) => { dcx }
|
||||
Err(NomError(e)) | Err(NomFailure(e)) => {
|
||||
let reason = unpackers_errors::get_nom_error_reason(e.1);
|
||||
return Err(UnpackError::Parsing("DCX parsing failed: ".to_owned() + &reason))
|
||||
}
|
||||
e => {
|
||||
return Err(UnpackError::Unknown(format!("Unknown error: {:?}", e)))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
println!("{:?}", dcx);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn decompress_dcx(dcx: &dcx::Dcx) -> Vec<u8> {
|
||||
let mut data = vec![0u8; dcx.sizes.uncompressed_size as usize];
|
||||
data
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UnpackError {
|
||||
Io(io::Error),
|
||||
Parsing(String),
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
impl From<io::Error> for UnpackError {
|
||||
fn from(e: io::Error) -> Self {
|
||||
UnpackError::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_nom_error_reason(kind: nom::error::ErrorKind) -> String {
|
||||
format!("{:?} {:?}", kind, kind.description())
|
||||
}
|
Loading…
Reference in new issue