peview 0.1.1

A minimal and fast zero-copy parser for the PE32+ file format.
Documentation
mod relocation;
pub use relocation::*;
mod import;
pub use import::*;
mod export;
pub use export::*;

#[derive(Clone, Copy)]
pub enum DataDirectoryType {
    ExportTable,
    ImportTable,
    ResourceTable,
    ExceptionTable,
    CertificateTable,
    RelocationTable,
    Debug,
    Architecture,
    GlobalPointer,
    TLSTable,
    LoadConfigTable,
    BoundImportTable,
    ImportAddressTable,
    DelayImportDescriptor,
    CLRRuntimeHeader,
    Reserved,
}

/// Native structure define by [MSDN](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#optional-header-data-directories-image-only)
#[derive(Clone, Copy)]
#[repr(C)]
pub struct DataDirectory {
    pub rva: u32,
    pub size: u32,
}

impl DataDirectory {
    /// Checks if the specified RVA is within the bounds of this [`DataDirectory`]
    pub fn contains_rva(&self, rva: u32) -> bool {
        (self.rva..self.rva + self.size).contains(&rva)
    }
}

pub trait DataDirectoryTable<'a> {
    fn new(bytes: &'a [u8], dir: &'a DataDirectory) -> Self;

    /// Returns the [`DataDirectoryType`] of this table
    fn typ() -> DataDirectoryType;
}