| Crates.io | windows-elf-loader |
| lib.rs | windows-elf-loader |
| version | 0.1.0 |
| created_at | 2025-05-31 10:04:57.865413+00 |
| updated_at | 2025-05-31 10:04:57.865413+00 |
| description | Be capable of loading the elf dynamic library on Windows. |
| homepage | |
| repository | https://github.com/weizhiao/elf_loader |
| max_upload_size | |
| id | 1696251 |
| size | 30,472 |
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.
$ cargo run -r --example load
use std::{collections::HashMap, ffi::CStr};
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);
}
// Symbols required by dynamic library liba.so
let mut map = HashMap::new();
map.insert("print", print as _);
let pre_find = |name: &str| -> Option<*const ()> { map.get(name).copied() };
let mut loader: WinElfLoader = WinElfLoader::new();
// Load and relocate dynamic library liba.so
let liba = loader
.load_dylib("liba", include_bytes!("../example_dylib/liba.so"))
.unwrap()
.easy_relocate([], &pre_find)
.unwrap();
// Call function a in liba.so
let f = unsafe { liba.get::<extern "sysv64" fn() -> i32>("a").unwrap() };
println!("{}", f());
}
Here are the translated notes: