VecPE

Struct VecPE 

Source
pub struct VecPE { /* private fields */ }
Expand description

Represents a PE object with owned data.

Implementations§

Source§

impl VecPE

Source

pub fn new(pe_type: PEType, size: usize) -> Self

Creates a new VecPE object with a mutable PE object, initializing a backing buffer with the given size.

Source

pub fn new_disk(size: usize) -> Self

Creates a new VecPE as type Disk, initializing a vector of the given size.

Source

pub fn new_memory(size: usize) -> Self

Creates a new VecPE as type Memory, initializing a vector of the given size.

Source

pub fn from_file<P: AsRef<Path>>( pe_type: PEType, filename: P, ) -> Result<Self, Error>

Creates a new VecPE object with the given file’s data.

Source

pub fn from_disk_file<P: AsRef<Path>>(filename: P) -> Result<Self, Error>

Creates a new VecPE object with the given file’s data, marking it as a Disk image.

Source

pub fn from_memory_file<P: AsRef<Path>>(filename: P) -> Result<Self, Error>

Creates a new VecPE object with the given file’s data, marking it as a Memory image.

Source

pub fn from_data<B: AsRef<[u8]>>(pe_type: PEType, data: B) -> Self

Creates a new VecPE object with the given data.

Source

pub fn from_disk_data<B: AsRef<[u8]>>(data: B) -> Self

Creates a new VecPE object from the given slice object, marking it as a Disk image.

Source

pub fn from_memory_data<B: AsRef<[u8]>>(data: B) -> Self

Creates a new VecPE object from the given slice object, marking it as a Memory image.

Source

pub fn from_assembly<B: AsRef<[u8]>>( arch: Arch, asm_ref: B, entrypoint: Offset, ) -> Result<Self, Error>

Creates a new VecPE object from a buffer of assembly. Useful for converting shellcode into a binary.

Returns InvalidOffset if the offset given doesn’t point at code.

Source

pub fn as_ptr_pe(&self) -> PtrPE

Get a PtrPE object representing the PE data in this buffer.

Source

pub fn get_buffer(&self) -> &VecBuffer

Get the underlying VecBuffer object.

Source

pub fn get_mut_buffer(&mut self) -> &mut VecBuffer

Get a mutable reference to the underlying VecBuffer object.

Source

pub fn append<B: AsRef<[u8]>>(&mut self, data: B)

Appends the given data to the end of the VecPE object. See VecBuffer::append.

Source

pub fn append_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>

Appends the given reference to the end of the VecPE object. See VecBuffer::append_ref.

Source

pub fn append_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>

Appends the given slice reference to the end of the VecPE object. See VecBuffer::append_slice_ref.

Source

pub fn insert(&mut self, offset: usize, element: u8)

Insert a byte at the given offset. See VecBuffer::insert.

Source

pub fn remove(&mut self, offset: usize)

Remove a byte at the given offset. See VecBuffer::remove.

Source

pub fn push(&mut self, byte: u8)

Push a byte onto the end of the VecPE buffer. See VecBuffer::push.

Source

pub fn pop(&mut self) -> Option<u8>

Pop a byte from the end of the VecPE buffer. See VecBuffer::pop.

Source

pub fn clear(&mut self)

Clear the VecPE buffer. See VecBuffer::clear.

Source

pub fn resize_with<F>(&mut self, new_len: usize, f: F)
where F: FnMut() -> u8,

Resize the buffer and fill with the given closure. See VecBuffer::resize_with.

Source

pub fn resize(&mut self, new_len: usize, value: u8)

Resize the given VecPE buffer. See VecBuffer::resize.

Source

pub fn truncate(&mut self, len: usize)

Truncate the given VecPE buffer. See VecBuffer::truncate.

Source

pub fn pad_to_file_alignment(&mut self) -> Result<(), Error>

Pad the backing vector with 0 to the PE’s file_alignment specification.

Source

pub fn pad_to_section_alignment(&mut self) -> Result<(), Error>

Pad the backing vector with 0 to the PE’s section_alignment specification.

Source

pub fn pad_to_alignment(&mut self) -> Result<(), Error>

Pad with 0 to either file_alignment or section_alignment, depending on what the PEType of the image is.

Trait Implementations§

Source§

impl Buffer for VecPE

Source§

fn len(&self) -> usize

Get the length of this Buffer object.
Source§

fn as_ptr(&self) -> *const u8

Get the Buffer object as a pointer.
Source§

fn as_mut_ptr(&mut self) -> *mut u8

Get the Buffer object as a mutable pointer.
Source§

fn as_slice(&self) -> &[u8]

Get the Buffer object as a slice.
Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Get the Buffer object as a mutable slice.
Source§

fn eob(&self) -> *const u8

Get a pointer to the end of the buffer. Read more
Source§

fn as_ptr_range(&self) -> Range<*const u8>

Get a pointer range of this buffer. See slice::as_ptr_range for more details.
Source§

fn as_mut_ptr_range(&mut self) -> Range<*mut u8>

Get a mutable pointer range of this buffer. See slice::as_mut_ptr_range for more details.
Source§

fn is_empty(&self) -> bool

Check whether or not this buffer is empty.
Source§

fn validate_ptr(&self, ptr: *const u8) -> bool

Validate that the given pointer object is within the range of this buffer.
Source§

fn offset_to_ptr(&self, offset: usize) -> Result<*const u8, Error>

Convert an offset to a u8 pointer. Read more
Source§

fn offset_to_mut_ptr(&mut self, offset: usize) -> Result<*mut u8, Error>

Convert an offset to a mutable u8 pointer. Read more
Source§

fn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>

Convert a pointer to an offset into the buffer. Read more
Source§

fn ref_to_offset<T>(&self, data: &T) -> Result<usize, Error>

Convert a given reference to an object into an offset into the buffer. Read more
Source§

fn slice_ref_to_offset<T>(&self, data: &[T]) -> Result<usize, Error>

Convert a given slice reference to an offset into the buffer. Read more
Source§

fn to_vec(&self) -> Vec<u8>

Convert this buffer to a u8 Vec object.
Source§

fn swap(&mut self, a: usize, b: usize)

Swap two bytes at the given offsets. This panics if the offsets are out of bounds. See slice::swap for more details.
Source§

fn reverse(&mut self)

Reverse the buffer. See slice::reverse for more details.
Source§

fn iter(&self) -> BufferIter<'_>

Return an iterator object (BufferIter) into the buffer.
Source§

fn iter_mut(&mut self) -> BufferIterMut<'_>

Return a mutable iterator object (BufferIterMut) into the buffer.
Source§

fn save<P>(&self, filename: P) -> Result<(), Error>
where P: AsRef<Path>,

Save this buffer to disk.
Source§

fn get<I>(&self, index: I) -> Option<&<I as SliceIndex<[u8]>>::Output>
where I: SliceIndex<[u8]>,

Get the given byte or range of bytes from the buffer. See slice::get for more details.
Source§

fn get_mut<I>( &mut self, index: I, ) -> Option<&mut <I as SliceIndex<[u8]>>::Output>
where I: SliceIndex<[u8]>,

Get the given byte or range of bytes from the buffer as mutable. See slice::get_mut for more details.
Source§

fn get_ref<T>(&self, offset: usize) -> Result<&T, Error>
where T: Castable,

Get a reference to a given object within the buffer. Typically the main interface by which objects are retrieved. Read more
Source§

unsafe fn get_ref_unaligned<T>(&self, offset: usize) -> Result<&T, Error>

Get a reference to a given object within the buffer, but in an unaligned way. Read more
Source§

unsafe fn force_get_ref<T>(&self, offset: usize) -> Result<&T, Error>
where T: Castable,

Get a reference regardless of potential alignment issues. Read more
Source§

fn get_mut_ref<T>(&mut self, offset: usize) -> Result<&mut T, Error>
where T: Castable,

Get a mutable reference to a given object within the buffer. See Buffer::get_ref.
Source§

unsafe fn get_mut_ref_unaligned<T>( &mut self, offset: usize, ) -> Result<&mut T, Error>

Get a mutable reference to a given object within the buffer, but in an unaligned way. Read more
Source§

unsafe fn force_get_mut_ref<T>( &mut self, offset: usize, ) -> Result<&mut T, Error>
where T: Castable,

Get a mutable reference regardless of potential alignment issues. Read more
Source§

fn make_mut_ref<T>(&mut self, data: &T) -> Result<&mut T, Error>
where T: Castable,

Convert a given reference to a mutable reference within the buffer. Read more
Source§

unsafe fn make_mut_ref_unaligned<T>( &mut self, data: &T, ) -> Result<&mut T, Error>

Convert a given reference to a mutable reference without alignment guarantees. Read more
Source§

unsafe fn force_make_mut_ref<T>(&mut self, data: &T) -> Result<&mut T, Error>
where T: Castable,

Convert an object to a mutable reference regardless of potential alignment issues. Read more
Source§

fn get_slice_ref<T>(&self, offset: usize, size: usize) -> Result<&[T], Error>
where T: Castable,

Gets a slice reference of type T at the given offset with the given size. Read more
Source§

unsafe fn get_slice_ref_unaligned<T>( &self, offset: usize, size: usize, ) -> Result<&[T], Error>

Gets a slice ref of type T at the given offset regardless of potential alignment issues. Read more
Source§

unsafe fn force_get_slice_ref<T>( &self, offset: usize, size: usize, ) -> Result<&[T], Error>
where T: Castable,

Get a slice reference regardless of potential alignment issues. Read more
Source§

fn get_mut_slice_ref<T>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>
where T: Castable,

Gets a mutable slice reference of type T at the given offset with the given size. See Buffer::get_slice_ref.
Source§

unsafe fn get_mut_slice_ref_unaligned<T>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>

Gets a mutable slice reference of type T at the given offset with the given size, but without alignment checking. See Buffer::get_slice_ref_unaligned.
Source§

unsafe fn force_get_mut_slice_ref<T>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>
where T: Castable,

Get a mutable slice reference regardless of potential alignment issues. Read more
Source§

fn make_mut_slice_ref<T>(&mut self, data: &[T]) -> Result<&mut [T], Error>
where T: Castable,

Convert a given slice reference to a mutable slice reference within the buffer. Read more
Source§

unsafe fn make_mut_slice_ref_unaligned<T>( &mut self, data: &[T], ) -> Result<&mut [T], Error>

Convert a given slice reference to a mutable slice reference without alignment guarantees. Read more
Source§

unsafe fn force_make_mut_slice_ref<T>( &mut self, data: &[T], ) -> Result<&mut [T], Error>
where T: Castable,

Convert an object to a mutable reference regardless of potential alignment issues. Read more
Source§

fn read(&self, offset: usize, size: usize) -> Result<&[u8], Error>

Read an arbitrary size amount of bytes from the given offset. Read more
Source§

fn read_mut(&mut self, offset: usize, size: usize) -> Result<&mut [u8], Error>

Read an arbitrary size amount of bytes from the given offset, but mutable. Read more
Source§

fn write<B>(&mut self, offset: usize, data: B) -> Result<(), Error>
where B: AsRef<[u8]>,

Write an arbitrary u8 slice to the given offset. Read more
Source§

fn write_ref<T>(&mut self, offset: usize, data: &T) -> Result<(), Error>
where T: Castable,

Write a given object of type T to the given buffer at the given offset. Read more
Source§

fn write_slice_ref<T>(&mut self, offset: usize, data: &[T]) -> Result<(), Error>
where T: Castable,

Write a given slice object of type T to the given buffer at the given offset. Read more
Source§

fn start_with<B>(&mut self, data: B) -> Result<(), Error>
where B: AsRef<[u8]>,

Start the buffer object with the given byte data. Read more
Source§

fn start_with_ref<T>(&mut self, data: &T) -> Result<(), Error>
where T: Castable,

Start the buffer with the given reference data. Read more
Source§

fn start_with_slice_ref<T>(&mut self, data: &[T]) -> Result<(), Error>
where T: Castable,

Start the buffer with the given slice reference data. Read more
Source§

fn end_with<B>(&mut self, data: B) -> Result<(), Error>
where B: AsRef<[u8]>,

End the buffer object with the given byte data. Read more
Source§

fn end_with_ref<T>(&mut self, data: &T) -> Result<(), Error>
where T: Castable,

End the buffer with the given reference data. Read more
Source§

fn end_with_slice_ref<T>(&mut self, data: &[T]) -> Result<(), Error>
where T: Castable,

End the buffer with the given slice reference data. Read more
Source§

fn search<B>(&self, data: B) -> Result<BufferSearchIter, Error>
where B: AsRef<[u8]>,

Search for the given u8 slice data within the given buffer. Read more
Source§

fn search_ref<T>(&self, data: &T) -> Result<BufferSearchIter, Error>
where T: Castable,

Search for the following reference of type T. This converts the object into a u8 slice. See Buffer::search.
Source§

fn search_slice_ref<T>(&self, data: &[T]) -> Result<BufferSearchIter, Error>
where T: Castable,

Search for the following slice reference of type T. This converts the slice into a u8 slice. See Buffer::search.
Source§

fn search_dynamic<'a, B>( &'a self, data: B, ) -> Result<BufferSearchDynamicIter<'a>, Error>
where B: AsRef<[Option<u8>]>,

Return a search iterator for a dynamic byte pattern within the binary. Read more
Source§

fn contains<B>(&self, data: B) -> bool
where B: AsRef<[u8]>,

Check if this buffer contains the following u8 slice sequence.
Source§

fn contains_ref<T>(&self, data: &T) -> Result<bool, Error>
where T: Castable,

Check if this buffer contains the following object of type T.
Source§

fn contains_slice_ref<T>(&self, data: &[T]) -> Result<bool, Error>
where T: Castable,

Check if this buffer contains the following slice of type T.
Source§

fn starts_with<B>(&self, needle: B) -> bool
where B: AsRef<[u8]>,

Check if this buffer starts with the byte sequence needle. See slice::starts_with.
Source§

fn ends_with<B>(&self, needle: B) -> bool
where B: AsRef<[u8]>,

Check if this buffer ends with the byte sequence needle. See slice::ends_with.
Source§

fn rotate_left(&mut self, mid: usize)

Rotate the buffer left at midpoint mid. See slice::rotate_left.
Source§

fn rotate_right(&mut self, mid: usize)

Rotate the buffer right at midpoint mid. See slice::rotate_right.
Source§

fn fill(&mut self, value: u8)

Fill the given buffer with the given value. See slice::fill.
Source§

fn fill_with<F>(&mut self, f: F)
where F: FnMut() -> u8,

Fill the given buffer with the given closure f. See slice::fill_with.
Source§

fn clone_from_data<B>(&mut self, src: B)
where B: AsRef<[u8]>,

Clone the given u8 slice data src into the given buffer.
Source§

fn copy_from_data<B>(&mut self, src: B)
where B: AsRef<[u8]>,

Copy the given u8 slice data src into the given buffer.
Source§

fn copy_within<R>(&mut self, src: R, dest: usize)
where R: RangeBounds<usize>,

Copy from within the given buffer. See slice::copy_within.
Source§

fn swap_with_data<B>(&mut self, other: B)
where B: AsMut<[u8]>,

Swap the data in this buffer with the given u8 slice reference.
Source§

fn is_ascii(&self) -> bool

Check if this buffer is ASCII. See slice::is_ascii.
Source§

fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool

Check if this buffer is equal while ignoring case of letters. See slice::eq_ignore_ascii_case.
Source§

fn make_ascii_uppercase(&mut self)

Make this buffer ASCII uppercase. See slice::make_ascii_uppercase.
Source§

fn make_ascii_lowercase(&mut self)

Make this buffer ASCII lowercase. See slice::make_ascii_lowercase.
Source§

fn sort(&mut self)

Sort this buffer. See slice::sort.
Source§

fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&u8, &u8) -> Ordering,

Sort by the given closure comparing each individual byte. See slice::sort_by.
Source§

fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&u8) -> K, K: Ord,

Sorts the slice with a key extraction function. See slice::sort_by_key.
Source§

fn repeat(&self, n: usize) -> Vec<u8>

Creates a new Buffer object by repeating the current buffer n times. See slice::repeat.
Source§

impl Clone for VecPE

Source§

fn clone(&self) -> VecPE

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 Debug for VecPE

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Idx: SliceIndex<[u8]>> Index<Idx> for VecPE

Source§

type Output = <Idx as SliceIndex<[u8]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: Idx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Idx: SliceIndex<[u8]>> IndexMut<Idx> for VecPE

Source§

fn index_mut(&mut self, index: Idx) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PE for VecPE

Source§

fn get_type(&self) -> PEType

Return the type of PE this object represents.
Source§

fn is_allocated(&self) -> bool

Only for Windows. Return if the PE has been allocated by VirtualAlloc.
Source§

fn get_cstring_size( &self, offset: usize, thunk: bool, max_size: Option<usize>, ) -> Result<usize, Error>

Get the size of a zero-terminated C-string in the data.
Source§

fn get_widestring_size( &self, offset: usize, max_size: Option<usize>, ) -> Result<usize, Error>

Gets the size of a zero-terminated UTF16 string in the data.
Source§

fn get_cstring( &self, offset: usize, thunk: bool, max_size: Option<usize>, ) -> Result<&[CChar], Error>

Get a zero-terminated C-string from the data. The thunk option is there to handle imports by name, whose null terminated value size is dependent on how long the string is (i.e., if it’s an odd length, an extra zero is appended). Read more
Source§

fn get_mut_cstring( &mut self, offset: usize, thunk: bool, max_size: Option<usize>, ) -> Result<&mut [CChar], Error>

Get a mutable zero-terminated C-string from the data.
Source§

fn get_widestring( &self, offset: usize, max_size: Option<usize>, ) -> Result<&[WChar], Error>

Get a zero-terminated UTF16 string from the data.
Source§

fn get_mut_widestring( &mut self, offset: usize, max_size: Option<usize>, ) -> Result<&mut [WChar], Error>

Get a mutable zero-terminated UTF16 string from the data.
Source§

fn translate(&self, addr: PETranslation) -> Result<usize, Error>

Translate an address into an offset usable by the Buffer trait based on the PE object’s type (i.e., the result of PE::get_type). Read more
Source§

fn get_dos_header(&self) -> Result<&ImageDOSHeader, Error>

Get the DOS header without verifying its contents.
Source§

fn get_mut_dos_header(&mut self) -> Result<&mut ImageDOSHeader, Error>

Get a mutable DOS header without verifying its contents.
Source§

fn get_valid_dos_header(&self) -> Result<&ImageDOSHeader, Error>

Get the DOS header and verify it’s a valid DOS header.
Source§

fn get_valid_mut_dos_header(&mut self) -> Result<&mut ImageDOSHeader, Error>

Get a mutable DOS header and verify it’s a valid DOS header.
Source§

fn e_lfanew(&self) -> Result<Offset, Error>

Get the offset to the PE headers.
Source§

fn get_dos_stub(&self) -> Result<&[u8], Error>

Get the executable DOS stub in the data. Read more
Source§

fn get_nt_headers_32(&self) -> Result<&ImageNTHeaders32, Error>

Get 32-bit NT headers without verifying its contents.
Source§

fn get_mut_nt_headers_32(&mut self) -> Result<&mut ImageNTHeaders32, Error>

Get mutable 32-bit NT headers without verifying its contents.
Source§

fn get_valid_nt_headers_32(&self) -> Result<&ImageNTHeaders32, Error>

Get 32-bit NT headers and verify that they’re 32-bit NT headers.
Source§

fn get_valid_mut_nt_headers_32( &mut self, ) -> Result<&mut ImageNTHeaders32, Error>

Get mutable 32-bit NT headers and verify that they’re 32-bit NT headers.
Source§

fn get_nt_headers_64(&self) -> Result<&ImageNTHeaders64, Error>

Get 64-bit NT headers without verifying its contents.
Source§

fn get_mut_nt_headers_64(&mut self) -> Result<&mut ImageNTHeaders64, Error>

Get mutable 64-bit NT headers without verifying its contents.
Source§

fn get_valid_nt_headers_64(&self) -> Result<&ImageNTHeaders64, Error>

Get 64-bit NT headers and verify that they’re 64-bit NT headers.
Source§

fn get_valid_mut_nt_headers_64( &mut self, ) -> Result<&mut ImageNTHeaders64, Error>

Get mutable 64-bit NT headers and verify that they’re 64-bit NT headers.
Source§

fn get_nt_magic(&self) -> Result<u16, Error>

Get the NT signature from the optional header of the NT headers.
Source§

fn get_arch(&self) -> Result<Arch, Error>

Get the architecture of this PE file.
Source§

fn get_valid_nt_headers(&self) -> Result<NTHeaders<'_>, Error>

Get the NT headers of this PE file, inferring from the content of the file which architecture it is and validating the headers. Read more
Source§

fn get_valid_mut_nt_headers(&mut self) -> Result<NTHeadersMut<'_>, Error>

Get mutable NT headers of this PE file, inferring from the content of the file which architecture it is and validating the headers.
Source§

fn validate_checksum(&self) -> Result<bool, Error>

Validate the checksum in the image with the calculated checksum.
Source§

fn calculate_checksum(&self) -> Result<u32, Error>

Calculate the checksum of the PE image.
Source§

fn get_entrypoint(&self) -> Result<RVA, Error>

Get the entrypoint of this PE file.
Source§

fn get_image_base(&self) -> Result<u64, Error>

Get the image base of this PE file. Read more
Source§

fn get_data_directory_offset(&self) -> Result<Offset, Error>

Get the offset to the data directory within the PE file.
Source§

fn get_data_directory_size(&self) -> Result<usize, Error>

Get the size of the data directory. Rounds down number_of_rva_and_sizes to 16, which is what the Windows loader does.
Source§

fn get_data_directory_table(&self) -> Result<&[ImageDataDirectory], Error>

Get the data directory table. Read more
Source§

fn get_mut_data_directory_table( &mut self, ) -> Result<&mut [ImageDataDirectory], Error>

Get a mutable data directory table.
Source§

fn get_data_directory( &self, dir: ImageDirectoryEntry, ) -> Result<&ImageDataDirectory, Error>

Get the data directory reference represented by the ImageDirectoryEntry enum. Returns Error::BadDirectory if the given directory is inaccessible due to the directory size.
Source§

fn get_mut_data_directory( &mut self, dir: ImageDirectoryEntry, ) -> Result<&mut ImageDataDirectory, Error>

Get the mutable data directory reference represented by the ImageDirectoryEntry enum.
Source§

fn has_data_directory(&self, dir: ImageDirectoryEntry) -> bool

Check whether or not this PE file has a given data directory. Read more
Source§

fn cast_directory<T: Castable>( &self, dir: ImageDirectoryEntry, ) -> Result<&T, Error>

Parse an object at the given data directory identified by ImageDirectoryEntry.
Source§

fn cast_directory_mut<T: Castable>( &mut self, dir: ImageDirectoryEntry, ) -> Result<&mut T, Error>

Parse a mutable object at the given data directory identified by ImageDirectoryEntry.
Source§

fn get_section_table_offset(&self) -> Result<Offset, Error>

Get the offset to the section table within the PE file.
Source§

fn get_section_table(&self) -> Result<&[ImageSectionHeader], Error>

Get the section table of the PE file.
Source§

fn get_mut_section_table(&mut self) -> Result<&mut [ImageSectionHeader], Error>

Get a mutable section table from the PE file.
Source§

fn get_section_by_offset( &self, offset: Offset, ) -> Result<&ImageSectionHeader, Error>

Get a reference to a section in the PE file by a given offset. Yields a Error::SectionNotFound error if the offset wasn’t found to be in a section.
Source§

fn get_mut_section_by_offset( &mut self, offset: Offset, ) -> Result<&mut ImageSectionHeader, Error>

Get a mutable reference to a section in the PE file by a given offset. Yields a Error::SectionNotFound error if the offset wasn’t found to be in a section.
Source§

fn get_section_by_rva(&self, rva: RVA) -> Result<&ImageSectionHeader, Error>

Get a reference to a section in the PE file by a given RVA. Yields a Error::SectionNotFound error if the RVA wasn’t found to be in a section.
Source§

fn get_mut_section_by_rva( &mut self, rva: RVA, ) -> Result<&mut ImageSectionHeader, Error>

Get a mutable reference to a section in the PE file by a given RVA. Yields a Error::SectionNotFound error if the RVA wasn’t found to be in a section.
Source§

fn get_section_by_name<S: AsRef<str>>( &self, name: S, ) -> Result<&ImageSectionHeader, Error>

Get a reference to a section in the PE file by its name. Yields a Error::SectionNotFound error if the name wasn’t found in the section table.
Source§

fn get_mut_section_by_name( &mut self, name: String, ) -> Result<&mut ImageSectionHeader, Error>

Get a mutable reference to a section in the PE file by its name. Yields a Error::SectionNotFound error if the name wasn’t found in the section table.
Source§

fn add_section( &mut self, section: &ImageSectionHeader, ) -> Result<&mut ImageSectionHeader, Error>

Add a given section header to the section table. Returns a mutable reference to the section header as it exists in the section table.
Source§

fn append_section( &mut self, section: &ImageSectionHeader, ) -> Result<&mut ImageSectionHeader, Error>

Append a given section header to the end of the PE sections. This function differs from add_section by setting the new section’s pointer_to_raw_data and virtual_address to the end of the previous section’s boundaries. Read more
Source§

fn validate_offset(&self, offset: Offset) -> bool

Verify that the given offset is a valid offset. Read more
Source§

fn validate_rva(&self, rva: RVA) -> bool

Verify that the given RVA is a valid RVA. Read more
Source§

fn validate_va(&self, va: VA) -> bool

Verify that the given VA is a valid VA for this image. Read more
Source§

fn is_aligned_to_file(&self, offset: Offset) -> bool

Check if a given Offset is aligned to the file_alignment attribute of the optional header.
Source§

fn is_aligned_to_section(&self, rva: RVA) -> bool

Check if a given RVA is aligned to the section_alignment attribute of the optional header.
Source§

fn align_to_file(&self, offset: Offset) -> Result<Offset, Error>

Aligns a given Offset to the file_alignment attribute of the optional header.
Source§

fn align_to_section(&self, rva: RVA) -> Result<RVA, Error>

Aligns a given RVA to the section_alignment attribute of the optional header.
Source§

fn offset_to_rva(&self, offset: Offset) -> Result<RVA, Error>

Convert an offset to an RVA address. Produces Error::InvalidRVA if the produced RVA is invalid or if the section it was transposed from no longer contains it.
Source§

fn offset_to_va(&self, offset: Offset) -> Result<VA, Error>

Convert an offset to a VA address.
Source§

fn rva_to_offset(&self, rva: RVA) -> Result<Offset, Error>

Convert an RVA to an offset address. Produces a Error::InvalidOffset error if the produced offset is invalid or if the section it was transposed from no longer contains it.
Source§

fn rva_to_va(&self, rva: RVA) -> Result<VA, Error>

Convert an RVA to a VA address. Produces a Error::InvalidVA error if the produced VA is invalid.
Source§

fn va_to_rva(&self, va: VA) -> Result<RVA, Error>

Convert a VA to an RVA. Produces a Error::InvalidRVA error if the produced RVA is invalid.
Source§

fn va_to_offset(&self, va: VA) -> Result<Offset, Error>

Converts a VA to an offset.
Source§

fn get_resource_address(&self, offset: ResourceOffset) -> Result<RVA, Error>

Get an RVA object relative to the resource directory. Read more
Source§

fn calculate_header_size(&self) -> Result<usize, Error>

Calculates the size of the image headers.
Source§

fn calculate_disk_size(&self) -> Result<usize, Error>

Calculate the size of the image as it appears on disk. Note that if there is appended data at the end of the file, it will not be factored in.
Source§

fn calculate_memory_size(&self) -> Result<usize, Error>

Calculate the size of the image as it appears in memory.
Source§

fn calculate_imphash(&self) -> Result<Vec<u8>, Error>

Calculate the imphash of the PE file.
Source§

fn recreate_image(&self, pe_type: PEType) -> Result<Vec<u8>, Error>

Creates a new vector representing either what the image looks like on disk (i.e., a PEType::Disk image) or what the image looks like in memory (i.e., a PEType::Memory image). Read more
Source§

fn fix_image_size(&mut self) -> Result<(), Error>

Recalculate the PE’s memory size with calculate_memory_size and set this value as the header’s size_of_image value.
Source§

impl PartialEq for VecPE

Source§

fn eq(&self, other: &VecPE) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for VecPE

Source§

impl StructuralPartialEq for VecPE

Auto Trait Implementations§

§

impl Freeze for VecPE

§

impl RefUnwindSafe for VecPE

§

impl Send for VecPE

§

impl Sync for VecPE

§

impl Unpin for VecPE

§

impl UnwindSafe for VecPE

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> Entropy for T
where T: PE,

Source§

fn entropy(&self) -> f64

Calculates the entropy of a given object. Returns a value between 0.0 (low entropy) and 8.0 (high entropy).
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HashData for T
where T: PE,

Source§

fn md5(&self) -> Vec<u8>

Produce an MD5 hash.
Source§

fn sha1(&self) -> Vec<u8>

Produce a SHA1 hash.
Source§

fn sha256(&self) -> Vec<u8>

Produce a SHA256 hash.
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> Same for T

Source§

type Output = T

Should always be Self
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.