1use std::{fs::{File, OpenOptions}, path::Path};
2
3use pe::{PeImage, PeError};
4pub mod pe;
5pub mod types;
6pub mod utils;
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 #[non_exhaustive]
11 #[error("failed to read file")]
12 Read(#[from] std::io::Error),
13
14 #[error("failed to parse")]
15 Parse(#[from] ParseError)
16}
17
18
19#[derive(Debug, thiserror::Error)]
20pub enum ParseError {
21 #[error(transparent)]
22 PE(#[from] pe::PeError)
23}
24
25pub type Result<T> = std::result::Result<T, PeError>;
26
27pub enum ParsedAs {
28 PE(PeImage),
29}
30
31pub enum ParseAs {
32 PE,
33}
34
35pub fn parse_file(f: File, parse_as: ParseAs) -> Result<ParsedAs>{
36 match parse_as {
37 ParseAs::PE => Ok(ParsedAs::PE(pe::PeImage::parse_file(f, 0)?)),
38 }
39}
40
41pub fn parse_path(path: &Path, parse_as: ParseAs) -> Result<ParsedAs>{
42 let f = OpenOptions::new()
43 .read(true)
44 .open(path)?;
45
46 parse_file(f, parse_as)
47}
48
49#[cfg(test)]
50mod tests {
51
52}