PeView

Struct PeView 

Source
pub struct PeView<'a> { /* private fields */ }
Expand description

View into a mapped PE image.

Implementations§

Source§

impl<'a> PeView<'a>

Source

pub fn from_bytes<T: AsRef<[u8]> + ?Sized>(image: &'a T) -> Result<PeView<'a>>

Constructs a view from a byte slice.

§Errors
  • Bounds: The byte slice is too small to fit the PE headers.

  • Misaligned: The minimum alignment of 4 is not satisfied.

  • BadMagic: This is not a PE file.

  • PeMagic: Trying to parse a PE32 file with the PE32+ parser and vice versa.

  • Insanity: Reasonable limits on e_lfanew, SizeOfHeaders or NumberOfSections are exceeded.

Source

pub unsafe fn module(base: *const u8) -> PeView<'a>

Constructs a new view from module handle.

§Safety

The underlying memory is borrowed and an unbounded lifetime is returned. Ensure the lifetime outlives this view instance!

No sanity or safety checks are done to make sure this is really PE32(+) image. When using this with a HMODULE from the system the caller must be sure this is a PE32(+) image.

Source

pub fn to_file(self) -> Vec<u8>

Converts the view to file alignment.

Trait Implementations§

Source§

impl<'a> Clone for PeView<'a>

Source§

fn clone(&self) -> PeView<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Pe<'a> for PeView<'a>

Source§

fn dos_header(self) -> &'a IMAGE_DOS_HEADER

Returns the DOS header.
Source§

fn dos_image(self) -> &'a [u8]

Returns the DOS image. Read more
Source§

fn nt_headers(self) -> &'a IMAGE_NT_HEADERS

Returns the NT headers.
Source§

fn file_header(self) -> &'a IMAGE_FILE_HEADER

Returns the file header.
Source§

fn optional_header(self) -> &'a IMAGE_OPTIONAL_HEADER

Returns the optional header.
Source§

fn data_directory(self) -> &'a [IMAGE_DATA_DIRECTORY]

Returns the data directory.
Source§

fn section_headers(self) -> &'a SectionHeaders

Returns the section headers.
Source§

fn headers(self) -> Headers<Self>

Returns the pe headers together in a single struct.
Source§

fn rva_to_file_offset(self, rva: Rva) -> Result<usize>

Converts a relative virtual address to file offset. Read more
Source§

fn file_offset_to_rva(self, file_offset: usize) -> Result<Rva>

Converts a file offset to relative virtual address. Read more
Source§

fn rva_to_va(self, rva: Rva) -> Result<Va>

Converts from relative virtual address to virtual address. Read more
Source§

fn va_to_rva(self, va: Va) -> Result<Rva>

Converts from virtual address to relative virtual address. Read more
Source§

fn slice(&self, rva: Rva, min_size_of: usize, align: usize) -> Result<&'a [u8]>

Slices the image at the specified rva. Read more
Source§

fn slice_bytes(self, rva: Rva) -> Result<&'a [u8]>
where Self: Sized,

Slices the image at the specified rva returning a byte slice with no alignment or minimum size. Read more
Source§

fn get_section_bytes( self, section_header: &IMAGE_SECTION_HEADER, ) -> Result<&'a [u8]>

Gets the bytes defined by a section header in this image. Read more
Source§

fn read(&self, va: Va, min_size_of: usize, align: usize) -> Result<&'a [u8]>

Reads the image at the specified va. Read more
Source§

fn read_bytes(self, va: Va) -> Result<&'a [u8]>
where Self: Sized,

Reads the image at the specified va returning a byte slice with no alignment or minimum size. Read more
Source§

fn derva<T>(self, rva: Rva) -> Result<&'a T>
where T: Pod,

Reads an aligned pod T.
Source§

fn derva_copy<T>(self, rva: Rva) -> Result<T>
where T: Copy + Pod,

Reads an unaligned pod T.
Source§

fn derva_into<T>(self, rva: Rva, dest: &mut T) -> Result<()>
where T: ?Sized + Pod,

Reads and byte-wise copies the content to the given destination. Read more
Source§

fn derva_slice<T>(self, rva: Rva, len: usize) -> Result<&'a [T]>
where T: Pod,

Reads an array of pod T with given length.
Source§

fn derva_slice_f<T, F>(self, rva: Rva, f: F) -> Result<&'a [T]>
where T: Pod, F: FnMut(&'a T) -> bool,

Reads an array of pod T. Read more
Source§

fn derva_slice_s<T>(self, rva: Rva, sentinel: T) -> Result<&'a [T]>
where T: PartialEq + Pod,

Reads an array of pod T. Read more
Source§

fn derva_c_str(self, rva: Rva) -> Result<&'a CStr>

Reads a nul-terminated C string.
Source§

fn derva_string<T>(self, rva: Rva) -> Result<&'a T>
where T: FromBytes + ?Sized,

Reads a string.
Source§

fn deref<T>(self, ptr: Ptr<T>) -> Result<&'a T>
where T: Pod,

Dereferences the pointer to a pod T.
Source§

fn deref_copy<T>(self, ptr: Ptr<T>) -> Result<T>
where T: Copy + Pod,

Dereferences the pointer to an unaligned pod T.
Source§

fn deref_into<T>(self, ptr: Ptr<T>, dest: &mut T) -> Result<()>
where T: ?Sized + Pod,

Reads and byte-wise copies the content to the given destination. Read more
Source§

fn deref_slice<T>(self, ptr: Ptr<[T]>, len: usize) -> Result<&'a [T]>
where T: Pod,

Reads an array of pod T with given length.
Source§

fn deref_slice_f<T, F>(self, ptr: Ptr<[T]>, f: F) -> Result<&'a [T]>
where T: Pod, F: FnMut(&'a T) -> bool,

Reads an array of pod T. Read more
Source§

fn deref_slice_s<T>(self, ptr: Ptr<[T]>, sentinel: T) -> Result<&'a [T]>
where T: PartialEq + Pod,

Reads an array of pod T. Read more
Source§

fn deref_c_str(self, ptr: Ptr<CStr>) -> Result<&'a CStr>

Dereferences the pointer to a nul-terminated C string.
Source§

fn deref_string<T>(self, ptr: Ptr<T>) -> Result<&'a T>
where T: FromBytes + ?Sized,

Dereferences the pointer to a string.
Source§

fn rich_structure(self) -> Result<RichStructure<'a>>

Returns the Rich structure.
Source§

fn exports(self) -> Result<Exports<'a, Self>>

Gets the Export Directory. Read more
Source§

fn imports(self) -> Result<Imports<'a, Self>>

Gets the Import Directory. Read more
Source§

fn iat(self) -> Result<IAT<'a, Self>>

Gets the Import Address Table. Read more
Source§

fn base_relocs(self) -> Result<BaseRelocs<'a>>

Gets the Base Relocations Directory. Read more
Source§

fn load_config(self) -> Result<LoadConfig<'a, Self>>

Gets the Load Config Directory. Read more
Source§

fn tls(self) -> Result<Tls<'a, Self>>

Gets the TLS Directory. Read more
Source§

fn security(self) -> Result<Security<'a>>

Gets the Security Directory. Read more
Source§

fn exception(self) -> Result<Exception<'a, Self>>

Gets the Exception Directory. Read more
Source§

fn debug(self) -> Result<Debug<'a, Self>>

Gets the Debug Directory. Read more
Source§

fn resources(self) -> Result<Resources<'a>>
where Self: Copy,

Gets the Resources. Read more
Source§

fn scanner(self) -> Scanner<Self>

Gets Scanner access. Read more
Source§

impl<'a> PeObject<'a> for PeView<'a>

Source§

fn image(&self) -> &'a [u8]

Returns the image as a byte slice.
Source§

fn align(&self) -> Align

Returns whether this image uses file alignment or section alignment.
Source§

impl<'a> Copy for PeView<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PeView<'a>

§

impl<'a> RefUnwindSafe for PeView<'a>

§

impl<'a> Send for PeView<'a>

§

impl<'a> Sync for PeView<'a>

§

impl<'a> Unpin for PeView<'a>

§

impl<'a> UnwindSafe for PeView<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'b, 'a, P, S> GetProcAddress<'a, &'b S> for P
where P: Pe<'a>, S: AsRef<[u8]> + ?Sized,

Source§

fn get_export(self, name: &'b S) -> Result<Export<'a>, Error>

Convenient method to get an exported function. Read more
Source§

fn get_proc_address(self, name: T) -> Result<Va>

Convenient method to get the address of an exported function. Read more
Source§

impl<'b, 'a, P> GetProcAddress<'a, Import<'b>> for P
where P: Pe<'a>,

Source§

fn get_export(self, name: Import<'b>) -> Result<Export<'a>, Error>

Convenient method to get an exported function. Read more
Source§

fn get_proc_address(self, name: T) -> Result<Va>

Convenient method to get the address of an exported function. Read more
Source§

impl<'a, P> GetProcAddress<'a, u16> for P
where P: Pe<'a>,

Source§

fn get_export(self, name: u16) -> Result<Export<'a>, Error>

Convenient method to get an exported function. Read more
Source§

fn get_proc_address(self, name: T) -> Result<Va>

Convenient method to get the address of an exported function. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.