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 is_le(&self) -> bool

Whether the loaded executable uses the DOS4GW LE container format.

Source

pub fn fixup_post_images(&self, pres: &BTreeSet<u64>) -> BTreeSet<u64>

Runtime (post-fixup) images of link-time (pre-fixup) addresses: for every pre in pres that an LE 07 fixup record patches, the mapped runtime value. Empty for PE (no fixup tables) and for binaries whose tables hold no 07 records. Used to widen address accept-sets (a body may bake the runtime value of a referenced address); never a demand.

Source

pub fn fixup_post_image(&self, pre: u64) -> Option<u64>

Runtime (post-fixup) image of a single link-time address, if that address is an LE 07 fixup site. None for PE, for LE binaries with no absolute fixups, and for pre values that are not fixup sites.

Used by the jump-table reader: an LE table’s base and its entries are stored pre-fixup, so a displacement/entry must be translated to its runtime VA before it can be range-checked or read through the page map. Widening only: PE (and LE non-fixup values) are unchanged.

Source

pub fn fixup_count(&self) -> usize

How many 07 absolute fixup records were absorbed at load (0 for PE and for LE binaries without absolute fixups). Diagnostic/test use.

Source

pub fn fixup_pairs(&self) -> &[(u64, u64)]

The absorbed (pre, post) content pairs for every 07 absolute fixup (empty for PE). Diagnostic/test use; the gates go through Pe::fixup_post_images.

Source

pub fn fixup_rel32_pairs(&self) -> &[(u64, u64)]

The LE 08 self-relative records as (operand_va, target_va).

Source

pub fn fixup_rel32_target(&self, loc: u64) -> Option<u64>

Runtime target of a rel32 branch/call whose operand sits at loc, if an LE 08 self-relative fixup patches it. None for PE and non-sites.

Source

pub fn fixup_status(&self) -> &FixupStatus

What happened with the LE fixup tables (see FixupStatus).

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 Forget for Pe

§

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.