reflective_pe_dll_loader 0.1.0

Reflective PECOFF DLL loader. Loads a DLL from memory for execution.
docs.rs failed to build reflective_pe_dll_loader-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: reflective_pe_dll_loader-0.1.2

Reflective PE COFF DLL loader

Crates.io Downloads Documentation License Dependency Status

A loader is a program that loads some executable code (e.g. in ELF, PE COFF, or Mach-O formats) into memory so that it can be executed.

A reflective loader is such a loader that loads the executable code from a memory buffer, rather than from a file on disk.

use reflective_pe_dll_loader::{PeDll, Symbol};

let bytes: &[u8] = include_bytes!("../test-dlls/hello_world_lib.dll");
let pe_dll = PeDll::new(&bytes).unwrap();

let add: Symbol<extern "C" fn(i32, i32) -> i32> = {
    let symbol = pe_dll.get_symbol_by_name("add").unwrap();
    unsafe { symbol.assume_type() }
};

assert_eq!(add(1, 2), 3);

Credits

It is largely based on the code from https://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/.