pub struct PeView<'a> { /* private fields */ }
Expand description
View into a mapped PE image.
Implementations
sourceimpl<'a> PeView<'a>
impl<'a> PeView<'a>
sourcepub fn from_bytes<T: AsRef<[u8]> + ?Sized>(image: &'a T) -> Result<PeView<'a>>
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 one_lfanew
,SizeOfHeaders
orNumberOfSections
are exceeded.
sourcepub unsafe fn module(base: *const u8) -> PeView<'a>
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.
Trait Implementations
sourceimpl<'a> Pe<'a> for PeView<'a>
impl<'a> Pe<'a> for PeView<'a>
sourcefn image(&self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
fn image(&self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
Returns the image as a byte slice.
sourcefn slice(&self, rva: Rva, min_size_of: usize, align_of: usize) -> Result<&'a [u8]>
fn slice(&self, rva: Rva, min_size_of: usize, align_of: usize) -> Result<&'a [u8]>
Slices the image at the specified rva. Read more
sourcefn read(&self, va: Va, min_size_of: usize, align_of: usize) -> Result<&'a [u8]>
fn read(&self, va: Va, min_size_of: usize, align_of: usize) -> Result<&'a [u8]>
Reads the image at the specified va. Read more
sourcefn dos_header(self) -> &'a IMAGE_DOS_HEADERwhere
Self: Copy,
fn dos_header(self) -> &'a IMAGE_DOS_HEADERwhere
Self: Copy,
Returns the DOS header.
sourcefn dos_image(self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
where
Self: Copy,
fn dos_image(self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
where
Self: Copy,
Returns the DOS image. Read more
sourcefn nt_headers(self) -> &'a IMAGE_NT_HEADERSwhere
Self: Copy,
fn nt_headers(self) -> &'a IMAGE_NT_HEADERSwhere
Self: Copy,
Returns the NT headers.
sourcefn file_header(self) -> &'a IMAGE_FILE_HEADERwhere
Self: Copy,
fn file_header(self) -> &'a IMAGE_FILE_HEADERwhere
Self: Copy,
Returns the file header.
sourcefn optional_header(self) -> &'a IMAGE_OPTIONAL_HEADERwhere
Self: Copy,
fn optional_header(self) -> &'a IMAGE_OPTIONAL_HEADERwhere
Self: Copy,
Returns the optional header.
sourcefn data_directory(self) -> &'a [IMAGE_DATA_DIRECTORY]where
Self: Copy,
fn data_directory(self) -> &'a [IMAGE_DATA_DIRECTORY]where
Self: Copy,
Returns the data directory.
sourcefn section_headers(self) -> &'a [IMAGE_SECTION_HEADER]where
Self: Copy,
fn section_headers(self) -> &'a [IMAGE_SECTION_HEADER]where
Self: Copy,
Returns the section headers.
sourcefn headers(self) -> Headers<Self>where
Self: Copy,
fn headers(self) -> Headers<Self>where
Self: Copy,
Returns the pe headers together in a single struct.
sourcefn rva_to_file_offset(self, rva: Rva) -> Result<usize>where
Self: Copy,
fn rva_to_file_offset(self, rva: Rva) -> Result<usize>where
Self: Copy,
Converts a relative virtual address to file offset. Read more
sourcefn file_offset_to_rva(self, file_offset: usize) -> Result<Rva>where
Self: Copy,
fn file_offset_to_rva(self, file_offset: usize) -> Result<Rva>where
Self: Copy,
Converts a file offset to relative virtual address. Read more
sourcefn rva_to_va(self, rva: Rva) -> Result<Va>where
Self: Copy,
fn rva_to_va(self, rva: Rva) -> Result<Va>where
Self: Copy,
Converts from relative virtual address to virtual address. Read more
sourcefn va_to_rva(self, va: Va) -> Result<Rva>where
Self: Copy,
fn va_to_rva(self, va: Va) -> Result<Rva>where
Self: Copy,
Converts from virtual address to relative virtual address. Read more
sourcefn slice_bytes(self, rva: Rva) -> Result<&'a [u8]>where
Self: Sized,
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
sourcefn read_bytes(self, va: Va) -> Result<&'a [u8]>where
Self: Sized,
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
sourcefn derva_copy<T>(self, rva: Rva) -> Result<T>where
Self: Copy,
T: Copy + Pod,
fn derva_copy<T>(self, rva: Rva) -> Result<T>where
Self: Copy,
T: Copy + Pod,
Reads an unaligned pod
T
.sourcefn derva_into<T>(self, rva: Rva, dest: &mut T) -> Result<()>where
Self: Copy,
T: ?Sized + Pod,
fn derva_into<T>(self, rva: Rva, dest: &mut T) -> Result<()>where
Self: Copy,
T: ?Sized + Pod,
Reads and byte-wise copies the content to the given destination. Read more
sourcefn derva_slice<T>(self, rva: Rva, len: usize) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
fn derva_slice<T>(self, rva: Rva, len: usize) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
Reads an array of pod
T
with given length.sourcefn derva_slice_f<T, F>(self, rva: Rva, f: F) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
F: FnMut(&'a T) -> bool,
fn derva_slice_f<T, F>(self, rva: Rva, f: F) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
F: FnMut(&'a T) -> bool,
Reads an array of pod
T
. Read moresourcefn derva_slice_s<T>(self, rva: Rva, sentinel: T) -> Result<&'a [T]>where
Self: Copy,
T: PartialEq + Pod,
fn derva_slice_s<T>(self, rva: Rva, sentinel: T) -> Result<&'a [T]>where
Self: Copy,
T: PartialEq + Pod,
Reads an array of pod
T
. Read moresourcefn derva_c_str(self, rva: Rva) -> Result<&'a CStr>where
Self: Copy,
fn derva_c_str(self, rva: Rva) -> Result<&'a CStr>where
Self: Copy,
Reads a nul-terminated C string.
sourcefn derva_string<T>(self, rva: Rva) -> Result<&'a T>where
Self: Copy,
T: FromBytes + ?Sized,
fn derva_string<T>(self, rva: Rva) -> Result<&'a T>where
Self: Copy,
T: FromBytes + ?Sized,
Reads a string.
sourcefn deref<T>(self, ptr: Ptr<T>) -> Result<&'a T>where
Self: Copy,
T: Pod,
fn deref<T>(self, ptr: Ptr<T>) -> Result<&'a T>where
Self: Copy,
T: Pod,
Dereferences the pointer to a pod
T
.sourcefn deref_copy<T>(self, ptr: Ptr<T>) -> Result<T>where
Self: Copy,
T: Copy + Pod,
fn deref_copy<T>(self, ptr: Ptr<T>) -> Result<T>where
Self: Copy,
T: Copy + Pod,
Dereferences the pointer to an unaligned pod
T
.sourcefn deref_into<T>(self, ptr: Ptr<T>, dest: &mut T) -> Result<()>where
Self: Copy,
T: ?Sized + Pod,
fn deref_into<T>(self, ptr: Ptr<T>, dest: &mut T) -> Result<()>where
Self: Copy,
T: ?Sized + Pod,
Reads and byte-wise copies the content to the given destination. Read more
sourcefn deref_slice<T>(self, ptr: Ptr<[T]>, len: usize) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
fn deref_slice<T>(self, ptr: Ptr<[T]>, len: usize) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
Reads an array of pod
T
with given length.sourcefn deref_slice_f<T, F>(self, ptr: Ptr<[T]>, f: F) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
F: FnMut(&'a T) -> bool,
fn deref_slice_f<T, F>(self, ptr: Ptr<[T]>, f: F) -> Result<&'a [T]>where
Self: Copy,
T: Pod,
F: FnMut(&'a T) -> bool,
Reads an array of pod
T
. Read moresourcefn deref_slice_s<T>(self, ptr: Ptr<[T]>, sentinel: T) -> Result<&'a [T]>where
Self: Copy,
T: PartialEq + Pod,
fn deref_slice_s<T>(self, ptr: Ptr<[T]>, sentinel: T) -> Result<&'a [T]>where
Self: Copy,
T: PartialEq + Pod,
Reads an array of pod
T
. Read moresourcefn deref_c_str(self, ptr: Ptr<CStr>) -> Result<&'a CStr>where
Self: Copy,
fn deref_c_str(self, ptr: Ptr<CStr>) -> Result<&'a CStr>where
Self: Copy,
Dereferences the pointer to a nul-terminated C string.
sourcefn deref_string<T>(self, ptr: Ptr<T>) -> Result<&'a T>where
Self: Copy,
T: FromBytes + ?Sized,
fn deref_string<T>(self, ptr: Ptr<T>) -> Result<&'a T>where
Self: Copy,
T: FromBytes + ?Sized,
Dereferences the pointer to a string.
sourcefn exports(self) -> Result<Exports<'a, Self>>where
Self: Copy,
fn exports(self) -> Result<Exports<'a, Self>>where
Self: Copy,
Gets the Export Directory. Read more
sourcefn imports(self) -> Result<Imports<'a, Self>>where
Self: Copy,
fn imports(self) -> Result<Imports<'a, Self>>where
Self: Copy,
Gets the Import Directory. Read more
sourcefn iat(self) -> Result<IAT<'a, Self>>where
Self: Copy,
fn iat(self) -> Result<IAT<'a, Self>>where
Self: Copy,
Gets the Import Address Table. Read more
sourcefn base_relocs(self) -> Result<BaseRelocs<'a, Self>>where
Self: Copy,
fn base_relocs(self) -> Result<BaseRelocs<'a, Self>>where
Self: Copy,
Gets the Base Relocations Directory. Read more
sourcefn load_config(self) -> Result<LoadConfig<'a, Self>>where
Self: Copy,
fn load_config(self) -> Result<LoadConfig<'a, Self>>where
Self: Copy,
Gets the Load Config Directory. Read more
sourcefn security(self) -> Result<Security<'a, Self>>where
Self: Copy,
fn security(self) -> Result<Security<'a, Self>>where
Self: Copy,
Gets the Security Directory. Read more
impl<'a> Copy for PeView<'a>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more