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
impl Module
Sourcepub const fn new(name: &'static str, builds: &'static [Build]) -> Self
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.
Sourcepub unsafe fn init(&self) -> Result<()>
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
Error::ModuleNotLoadedif no module of this name is loaded.Error::BuildMismatchif it is none of the accepted builds.Error::InvalidImageif its image header can’t be read.Error::UnsupportedPlatformon platforms other than Windows.
§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.
Sourcepub unsafe fn init_any_build(&self) -> Result<Build>
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
Error::ModuleNotLoadedif no module of this name is loaded.Error::InvalidImageif its image header can’t be read.Error::UnsupportedPlatformon platforms other than Windows.
§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.