Skip to main content

PeImage

Struct PeImage 

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

A loaded PE image (e.g. a .dll). Pointers stored in a PE hold absolute virtual addresses at the preferred image base, so no relocation step is needed: the on-disk values and the addresses computed here share that base.

Implementations§

Source§

impl PeImage

Source

pub fn parse(data: &[u8]) -> Result<PeImage, PewterError>

Source

pub fn file(&self) -> &PEImageDef

The parsed image.

Source

pub fn file_mut(&mut self) -> &mut PEImageDef

The parsed image, mutably — add sections, patch bytes, rewrite the export or import tables, then write_file. All of PEImageDef’s editing surface is reachable through this.

Source

pub fn image_base(&self) -> u64

The preferred image base.

Source

pub fn add_section( &mut self, name: &str, data: &[u8], perms: SectionPermissions, ) -> Result<u64, PewterError>

Append a new section with the given data and access, returning its virtual address — the format-neutral form matching ElfImage::add_section and AnyImage::add_section. For full control over the section characteristics, use file_mut and PEImageDef::new_section.

Source

pub fn write_at_vaddr( &mut self, vaddr: u64, data: &[u8], ) -> Result<(), PewterError>

Overwrite the bytes at virtual address vaddr, reflected by write_file. Translates vaddr to an RVA against the image base and writes through PEImageDef::write_at_rva.

Source

pub fn write_file(&mut self) -> Result<Vec<u8>, PewterError>

Serialize the image back to bytes, reflecting any edits: recomputes the header sizes, section offsets and checksum (see PEImageDef::write_file).

Source

pub fn forwarding_proxy( &self, config: &ProxyConfig<'_>, ) -> Result<Vec<u8>, PewterError>

Build a forwarding proxy DLL for this image (see ProxyConfig): forward every export to forward_to and import payload so the loader loads it.

Trait Implementations§

Source§

impl<'ʄ> Facet<'ʄ> for PeImage

Source§

const SHAPE: &'static Shape

The shape of this type, including: whether it’s a Struct, an Enum, something else? Read more
Source§

impl LoadedImage for PeImage

Source§

fn is_64(&self) -> bool

Whether pointers are 64-bit.
Source§

fn bytes(&self, vaddr: u64, len: usize) -> Option<&[u8]>

len bytes at virtual address vaddr, or None if unmapped.
Source§

fn c_str(&self, vaddr: u64) -> Option<String>

The NUL-terminated string at vaddr, decoded as lossy UTF-8, or None if vaddr is unmapped. Reads to a NUL byte or the end of the mapping.
Source§

fn pointer(&self, vaddr: u64) -> Option<u64>

A pointer-sized value at vaddr, after relocation.
Source§

fn data_segments(&self) -> Vec<(u64, u64)>

Virtual-address ranges of the loaded, non-executable segments (where data such as tables of pointers lives).
Source§

fn exports(&self) -> Result<Vec<Export>, PewterError>

The exported symbols: a PE’s export table, or an ELF’s defined dynamic functions and objects.
Source§

fn machine(&self) -> Option<ImageFileMachine>

The machine as a PE machine type, or None if PE has no equivalent.
Source§

fn pointer_size(&self) -> u64

Source§

fn u32(&self, vaddr: u64) -> Option<u32>

Source§

fn u8(&self, vaddr: u64) -> Option<u8>

Source§

fn pointer_at(&self, base: u64, index: u64) -> Option<u64>

The indexth pointer of an array at base, i.e. the pointer at base + index * pointer_size(). Saves spelling out the stride when walking a table of pointers.
Source§

fn pointers(&self, vaddr: u64, count: u64) -> Option<Vec<u64>>

count consecutive pointers starting at vaddr, or None if any is unmapped.
Source§

fn pointer_slots(&self, segment: (u64, u64)) -> impl Iterator<Item = u64>

The pointer-sized slots of segment (a data_segments range), as the virtual addresses start, start + pointer_size(), … that each still hold a full pointer. Useful for scanning a segment for a structure.
Source§

fn is_mapped(&self, vaddr: u64) -> bool

Whether vaddr is a non-null, mapped address.

Auto Trait Implementations§

§

impl Forget for PeImage

§

impl Freeze for PeImage
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, InternalBitFlags: Freeze, u32: Freeze, InternalBitFlags: Freeze, u64: Freeze, PhantomData<SectionHeap>: Freeze,

§

impl Move for PeImage

§

impl RefUnwindSafe for PeImage
where InternalBitFlags: RefUnwindSafe, u32: RefUnwindSafe, InternalBitFlags: RefUnwindSafe, u64: RefUnwindSafe, InternalBitFlags: RefUnwindSafe,

§

impl Send for PeImage
where RawVecInner: Send, InternalBitFlags: Send, u32: Send, InternalBitFlags: Send, u64: Send, InternalBitFlags: Send,

§

impl Sync for PeImage
where RawVecInner: Sync, InternalBitFlags: Sync, u32: Sync, InternalBitFlags: Sync, u64: Sync, InternalBitFlags: Sync,

§

impl Unpin for PeImage
where *const u8 is !null: Unpin, InternalBitFlags: Unpin, u32: Unpin, InternalBitFlags: Unpin, u64: Unpin, InternalBitFlags: Unpin,

§

impl UnsafeUnpin for PeImage

§

impl UnwindSafe for PeImage
where RawVecInner: UnwindSafe, InternalBitFlags: UnwindSafe, u32: UnwindSafe, InternalBitFlags: UnwindSafe, u64: UnwindSafe, InternalBitFlags: UnwindSafe,

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.