Skip to main content

Pe

Struct Pe 

Source
pub struct Pe {
    pub image_base: u64,
    /* private fields */
}
Expand description

A loaded PE image: the raw file plus the parsed section table.

Fields§

§image_base: u64

Implementations§

Source§

impl Pe

Source

pub fn load(path: &str) -> Result<Pe, String>

Source

pub fn parse(data: Vec<u8>) -> Result<Pe, String>

Source

pub fn id(&self) -> u64

Process-unique id assigned at parse time (see the field docs).

Source

pub fn section_of(&self, va: u64) -> Option<&Section>

The section containing va, if any.

Source

pub fn read(&self, va: u64, len: usize) -> Option<&[u8]>

Read up to len bytes of file data starting at virtual address va. Returns fewer bytes near the end of a section’s raw data (never reads across a section boundary or into uninitialized/BSS tail).

Source

pub fn sections(&self) -> &[Section]

Iterate over all sections in the PE

Source

pub fn is_executable_va(&self, va: u64) -> bool

Source

pub fn is_executable_section_va(&self, va: u64) -> bool

True if va lies inside a section whose PE32 Characteristics mark it as code (CNT_CODE or MEM_EXECUTE) — the STRICT counterpart of Pe::is_executable_va. Use this when deciding whether an immediate / stored dword plausibly denotes a FUNCTION (it lives in .text), as opposed to data (a .rdata vtable VA, a string address) that merely happens to sit inside the image.

Source

pub fn describe_sections(&self, va: u64) -> String

Pretty-print every section as name [RVA..RVA+size) with the image base baked in, plus a hint pointing at the closest section to va (by VA distance) so the user can immediately tell whether they mistyped an address or used the wrong file.

Source

pub fn image_range(&self) -> (u64, u64)

The image’s VA range [image_base, end) (end = highest section end).

Source

pub fn referenced_addrs(&self) -> HashSet<u32>

Every VA the image itself “knows about”: targets of every rel32 CALL / JMP / Jcc byte pattern in .text, plus every little-endian u32 (read at EVERY byte offset of every section’s raw data) that lands inside the image — vtable slots, switch jump tables, baked function pointers, data refs.

Purpose: catch a MISATTRIBUTED or invented origin address. A real function entry is always reachable somehow (called, tail-jumped — long OR short form — or its address stored in a table), so an address referenced NOWHERE cannot be one. Over-approximate by construction (a spurious 0xE8 inside another instruction adds a junk target; a random data dword may collide) — that only ever widens the accept set, so it can’t false-positive a real entry.

Auto Trait Implementations§

§

impl Freeze for Pe

§

impl RefUnwindSafe for Pe

§

impl Send for Pe

§

impl Sync for Pe

§

impl Unpin for Pe

§

impl UnsafeUnpin for Pe

§

impl UnwindSafe for Pe

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.