Crates.io | reflective_pe_dll_loader |
lib.rs | reflective_pe_dll_loader |
version | 0.1.2 |
source | src |
created_at | 2024-04-05 10:07:08.592116 |
updated_at | 2024-04-11 17:29:50.434034 |
description | Reflective PECOFF DLL loader. Loads a DLL from memory for execution. |
homepage | |
repository | https://github.com/JohnScience/reflective_pe_dll_loader |
max_upload_size | |
id | 1197192 |
size | 148,203 |
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);
This crate has limited use cases. If you can avoid building a dynamic library that you'd embed in your executable and instead create an object file that you'd statically link with your executable, you should do that.
It is largely based on the code from https://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/.
Note: the tutorial is incomplete and, for example, does not cover TLS callbacks. This may be a problem for some DLLs but may be fixed in the future.