Skip to main content

Module

Struct Module 

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

A module (executable or DLL) of the target process, as the bindings expect it: its file name and the builds they accept.

Declare one as a static, call init once the module is loaded, then resolve addresses with address. Generated bindings declare one per IR module as MODULE, and their init() calls Module::init.

§Examples

use imping_runtime::{Build, Module};

static TARGET: Module = Module::new(
    "target.exe",
    &[Build { timestamp: 0x64b8f2a1, image_size: 0xa2b000 }],
);

// SAFETY: the addresses used with `TARGET` belong to this build.
unsafe { TARGET.init() }?;
let update = TARGET.address(0x15040);

Implementations§

Source§

impl Module

Source

pub const fn new(name: &'static str, builds: &'static [Build]) -> Self

Describes a module by its file name, such as "target.exe", and the builds it accepts.

With no builds, init always fails.

Source

pub unsafe fn init(&self) -> Result<()>

Finds the module in this process and checks its image header against the accepted builds.

Once this succeeds, further calls return Ok and do nothing. Failures aren’t remembered, so a DLL the target loads later can be initialized once it’s there.

§Errors
§Safety

Everything later done through this module (addresses, function signatures, type layouts) must be correct for every accepted build; init only checks the identity. For generated bindings, the IR they came from must describe each accepted build correctly.

Source

pub unsafe fn init_any_build(&self) -> Result<Build>

Finds the module in this process and records its base whatever its build, returning the build found.

For trying a build the bindings don’t list; init is the checked way in. An unlisted build is logged as a warning, and generated functions then check their first bytes before they’re called, falling back to their byte pattern. If the module is already initialized, nothing changes and the loaded build is returned.

§Errors
§Safety

Everything later done through this module (addresses, function signatures, type layouts) must be correct for the build actually loaded, which nothing has checked. Generated functions still verify their first bytes where the bindings know them; globals and raw addresses are used unchecked.

Source

pub fn name(&self) -> &'static str

Returns the module’s file name.

Source

pub fn base(&self) -> Option<usize>

Returns the module’s base address, or None until init has succeeded.

Source

pub fn address(&self, rva: u32) -> usize

Returns the address of rva, an address relative to the module’s base.

§Panics

If init has not succeeded.

Trait Implementations§

Source§

impl Debug for Module

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.