ManualMapper

Struct ManualMapper 

Source
pub struct ManualMapper<S> { /* private fields */ }
Expand description

manual mapper with type-state progression

the type parameter ensures mapping steps happen in correct order: Parsed -> Allocated -> SectionsMapped -> Relocated -> ImportsResolved -> TlsProcessed -> Ready

Implementations§

Source§

impl ManualMapper<Parsed>

Source

pub fn parse(data: &[u8]) -> Result<Self>

parse PE from bytes

Source

pub fn from_file(path: &str) -> Result<Self>

parse PE from file

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn allocate(self) -> Result<ManualMapper<Allocated>>

allocate memory for the PE image

tries preferred base first, falls back to any available address

Source

pub fn allocate_at(self, base: usize) -> Result<ManualMapper<Allocated>>

allocate at specific address

fails if address is not available

Source

pub fn allocate_anywhere(self) -> Result<ManualMapper<Allocated>>

allocate anywhere (no preference)

Source§

impl ManualMapper<Allocated>

Source

pub fn base(&self) -> usize

get allocated base address

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn map_sections(self) -> Result<ManualMapper<SectionsMapped>>

map PE sections to allocated memory

Source§

impl ManualMapper<SectionsMapped>

Source

pub fn base(&self) -> usize

get base address

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn relocate(self) -> Result<ManualMapper<Relocated>>

apply base relocations

Source

pub fn skip_relocations(self) -> ManualMapper<Relocated>

skip relocations (use if loaded at preferred base)

Source§

impl ManualMapper<Relocated>

Source

pub fn base(&self) -> usize

get base address

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn resolve_imports(self) -> Result<ManualMapper<ImportsResolved>>

resolve import address table

Source

pub fn resolve_imports_with<F>( self, resolver_fn: F, ) -> Result<ManualMapper<ImportsResolved>>
where F: Fn(&str, &str) -> Option<usize>,

resolve imports with custom resolver function

Source

pub fn skip_imports(self) -> ManualMapper<ImportsResolved>

skip import resolution (use if PE has no imports or manually resolved)

Source§

impl ManualMapper<ImportsResolved>

Source

pub fn base(&self) -> usize

get base address

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn process_tls(self) -> Result<ManualMapper<TlsProcessed>>

process TLS callbacks

Source

pub fn skip_tls(self) -> ManualMapper<TlsProcessed>

skip TLS processing

Source§

impl ManualMapper<TlsProcessed>

Source

pub fn base(&self) -> usize

get base address

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn finalize(self) -> Result<ManualMapper<Ready>>

finalize mapping with proper memory protections

Source

pub fn finalize_without_protections(self) -> ManualMapper<Ready>

finalize without setting protections (keeps RW everywhere)

Source§

impl ManualMapper<Ready>

Source

pub fn call_entry_point(&self) -> Result<bool>

call DllMain with DLL_PROCESS_ATTACH

Source

pub fn call_entry_point_with_reason(&self, call_reason: u32) -> Result<bool>

call DllMain with custom reason

Source

pub fn get_export(&self, name: &str) -> Result<usize>

get export address by name

Source

pub fn get_export_by_ordinal(&self, ordinal: u16) -> Result<usize>

get export address by ordinal

Source

pub fn base(&self) -> usize

get base address of mapped image

Source

pub fn size(&self) -> usize

get size of mapped image

Source

pub fn pe(&self) -> &ParsedPe

get reference to parsed PE

Source

pub fn into_memory(self) -> MappedMemory

consume and return raw memory handle

Source

pub fn ptr_at(&self, offset: usize) -> *mut u8

get pointer to specific offset in mapped image

Source

pub fn unmap(self) -> Result<()>

unmap and free memory

Auto Trait Implementations§

§

impl<S> Freeze for ManualMapper<S>

§

impl<S> RefUnwindSafe for ManualMapper<S>
where S: RefUnwindSafe,

§

impl<S> Send for ManualMapper<S>
where S: Send,

§

impl<S> Sync for ManualMapper<S>
where S: Sync,

§

impl<S> Unpin for ManualMapper<S>
where S: Unpin,

§

impl<S> UnwindSafe for ManualMapper<S>
where S: 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 = 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.