Pe

Trait Pe 

Source
pub unsafe trait Pe<'a>: PeObject<'a> + Copy {
Show 45 methods // Provided methods fn dos_header(self) -> &'a IMAGE_DOS_HEADER { ... } fn dos_image(self) -> &'a [u8] { ... } fn nt_headers(self) -> &'a IMAGE_NT_HEADERS { ... } fn file_header(self) -> &'a IMAGE_FILE_HEADER { ... } fn optional_header(self) -> &'a IMAGE_OPTIONAL_HEADER { ... } fn data_directory(self) -> &'a [IMAGE_DATA_DIRECTORY] { ... } fn section_headers(self) -> &'a SectionHeaders { ... } fn headers(self) -> Headers<Self> { ... } fn rva_to_file_offset(self, rva: Rva) -> Result<usize> { ... } fn file_offset_to_rva(self, file_offset: usize) -> Result<Rva> { ... } fn rva_to_va(self, rva: Rva) -> Result<Va> { ... } fn va_to_rva(self, va: Va) -> Result<Rva> { ... } fn slice( &self, rva: Rva, min_size_of: usize, align: usize, ) -> Result<&'a [u8]> { ... } fn slice_bytes(self, rva: Rva) -> Result<&'a [u8]> where Self: Sized { ... } fn get_section_bytes( self, section_header: &IMAGE_SECTION_HEADER, ) -> Result<&'a [u8]> { ... } fn read(&self, va: Va, min_size_of: usize, align: usize) -> Result<&'a [u8]> { ... } fn read_bytes(self, va: Va) -> Result<&'a [u8]> where Self: Sized { ... } fn derva<T>(self, rva: Rva) -> Result<&'a T> where T: Pod { ... } fn derva_copy<T>(self, rva: Rva) -> Result<T> where T: Copy + Pod { ... } fn derva_into<T>(self, rva: Rva, dest: &mut T) -> Result<()> where T: ?Sized + Pod { ... } fn derva_slice<T>(self, rva: Rva, len: usize) -> Result<&'a [T]> where T: Pod { ... } fn derva_slice_f<T, F>(self, rva: Rva, f: F) -> Result<&'a [T]> where T: Pod, F: FnMut(&'a T) -> bool { ... } fn derva_slice_s<T>(self, rva: Rva, sentinel: T) -> Result<&'a [T]> where T: PartialEq + Pod { ... } fn derva_c_str(self, rva: Rva) -> Result<&'a CStr> { ... } fn derva_string<T>(self, rva: Rva) -> Result<&'a T> where T: FromBytes + ?Sized { ... } fn deref<T>(self, ptr: Ptr<T>) -> Result<&'a T> where T: Pod { ... } fn deref_copy<T>(self, ptr: Ptr<T>) -> Result<T> where T: Copy + Pod { ... } fn deref_into<T>(self, ptr: Ptr<T>, dest: &mut T) -> Result<()> where T: ?Sized + Pod { ... } fn deref_slice<T>(self, ptr: Ptr<[T]>, len: usize) -> Result<&'a [T]> where T: Pod { ... } fn deref_slice_f<T, F>(self, ptr: Ptr<[T]>, f: F) -> Result<&'a [T]> where T: Pod, F: FnMut(&'a T) -> bool { ... } fn deref_slice_s<T>(self, ptr: Ptr<[T]>, sentinel: T) -> Result<&'a [T]> where T: PartialEq + Pod { ... } fn deref_c_str(self, ptr: Ptr<CStr>) -> Result<&'a CStr> { ... } fn deref_string<T>(self, ptr: Ptr<T>) -> Result<&'a T> where T: FromBytes + ?Sized { ... } fn rich_structure(self) -> Result<RichStructure<'a>> { ... } fn exports(self) -> Result<Exports<'a, Self>> { ... } fn imports(self) -> Result<Imports<'a, Self>> { ... } fn iat(self) -> Result<IAT<'a, Self>> { ... } fn base_relocs(self) -> Result<BaseRelocs<'a>> { ... } fn load_config(self) -> Result<LoadConfig<'a, Self>> { ... } fn tls(self) -> Result<Tls<'a, Self>> { ... } fn security(self) -> Result<Security<'a>> { ... } fn exception(self) -> Result<Exception<'a, Self>> { ... } fn debug(self) -> Result<Debug<'a, Self>> { ... } fn resources(self) -> Result<Resources<'a>> where Self: Copy { ... } fn scanner(self) -> Scanner<Self> { ... }
}

Provided Methods§

Source

fn dos_header(self) -> &'a IMAGE_DOS_HEADER

Returns the DOS header.

Source

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

Returns the DOS image.

This includes the dos header and everything up to the start of the PE headers but is not guaranteed to actually contain anything valid.

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.

§Errors
  • Overflow: The rva is contained within a corrupt section where the range bounds overflow.

  • ZeroFill: The rva points to part of a section zero filled and is not available on disk.

  • Bounds: The rva falls outside any valid section or the PE headers.

Source

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

Converts a file offset to relative virtual address.

§Errors
  • Overflow: The file offset is contained within a corrupt section where the range bounds overflow.

  • Unmapped: The file offset points to part of a section not mapped and is not available in virtual memory.

  • Bounds: The file offset falls outside any valid section or PE headers.

Source

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

Converts from relative virtual address to virtual address.

§Errors
  • Null: The rva is zero.

  • Bounds: The rva does not fall within the virtual image bounds.

Source

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

Converts from virtual address to relative virtual address.

§Errors
  • Null: The va is zero.

  • Bounds: The va does not fall within the virtual image bounds.

Source

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

Slices the image at the specified rva.

If successful the returned slice’s length will be at least the given size but often be quite larger. This allows to access the image without knowing beforehand how large the structure being accessed will be.

The length is the largest consecutive number of bytes available until the end. In case the of PE files on disk, this is limited to the section’s size of raw data.

§Errors
  • Null: The rva is zero.
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.

Shorthand to invoke slice(rva, 0, 1).

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.

§Errors
  • Null: The virtual address or pointer to raw data is zero.

  • Bounds: The data referenced by the section header is out of bounds.

Source

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

Reads the image at the specified va.

If successful the returned slice’s length will be at least the given size but often be quite larger. This allows to access the image without knowing beforehand how large the structure being accessed will be.

The length is the largest consecutive number of bytes available until the end. In case the of PE files on disk, this is limited to the section’s size of raw data.

§Errors
  • Null: The va is zero.
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.

Shorthand to invoke read(va, 0, 1).

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.

Allows reading of an unaligned array of data.

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.

For every element of the array, starting at the given rva, the callable f is called with that element. The length of the array is the index when the callable f returns true.

The returned slice contains all T up to but not including the element for which the callable returned true.

Source

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

Reads an array of pod T.

The length of the array is determined by a sentinel value, a special value of T which marks the end of the array.

The returned slice contains all T up to but not including the sentinel value.

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.

Allows reading of an unaligned array of data.

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.

For every element of the array, starting at the given ptr, the callable f is called with that element. The length of the array is the index when the callable f returns true.

The returned slice contains all T up to but not including the element for which the callable returned true.

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.

The length of the array is determined by a sentinel value, a special value of T which marks the end of the array.

The returned slice contains all T up to but not including the sentinel value.

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.

See the exports module for more information.

Returns Err(Null) if the image has no exports. Any other error indiciates some form of corruption.

Source

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

Gets the Import Directory.

See the imports module for more information.

Returns Err(Null) if the image has no imports. Any other error indicates some form of corruption.

Source

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

Gets the Import Address Table.

See the imports module for more information.

Returns Err(Null) if the image has no iat. Any other error indicates some form of corruption.

Source

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

Gets the Base Relocations Directory.

See the base relocations module for more information.

Returns Err(Null) if the image has no base relocations. Any other error indicates some form of corruption.

Source

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

Gets the Load Config Directory.

See the load config module for more information.

Returns Err(Null) if the image has no load config. Any other error indicates some form of corruption.

Source

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

Gets the TLS Directory.

See the tls module for more information.

Returns Err(Null) if the image has no tls. Any other error indicates some form of corruption.

Source

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

Gets the Security Directory.

See the security module for more information.

Returns Err(Null) if the image has no security info. Any other error indicates some form of corruption.

Source

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

Gets the Exception Directory.

See the exception module for more information.

Returns Err(Null) if the image has no exception directory. Any other error indicates some form of corruption.

Source

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

Gets the Debug Directory.

See the debug module for more information.

Returns Err(Null) if the image has no debug info. Any other error indicates some form of corruption.

Source

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

Gets the Resources.

See the resources module for more information.

Returns Err(Null) if the image has no resources. Any other error indicates some form of corruption.

Source

fn scanner(self) -> Scanner<Self>

Gets Scanner access.

See the scanner module for more information.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> Pe<'a> for PeFile<'a>

Source§

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

Source§

impl<'s, 'a> Pe<'a> for &'s dyn PeObject<'a>