windows-elf-loader
Be capable of loading the elf dynamic library on Windows. This crate is implemented based on rust-elfloader. The dynamic library used in example is also derived from rust-elfloader.
Example
$ cargo run -r --example load
use std::ffi::CStr;
use elf_loader::image::{SyntheticSymbol, SyntheticModule};
use windows_elf_loader::WinElfLoader;
fn main() {
extern "sysv64" fn print(s: *const i8) {
let s = unsafe { CStr::from_ptr(s).to_str().unwrap() };
println!("{}", s);
}
let host = SyntheticModule::new(
"__host",
[SyntheticSymbol::function("print", print as *const ())],
);
let mut loader: WinElfLoader = WinElfLoader::new();
let liba = loader
.load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
.unwrap()
.relocator()
.scope([host])
.relocate()
.unwrap();
let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
println!("{}", f());
}
Note
Here are the translated notes:
- You need to manually handle the ELF dynamic library dependencies.
- Do not directly use syscalls within ELF dynamic libraries.
- ABI conversion is required at the calling boundary between ELF dynamic libraries and Windows programs, as demonstrated in the example.