windows-elf-loader

Crates.iowindows-elf-loader
lib.rswindows-elf-loader
version0.1.0
created_at2025-05-31 10:04:57.865413+00
updated_at2025-05-31 10:04:57.865413+00
descriptionBe capable of loading the elf dynamic library on Windows.
homepage
repositoryhttps://github.com/weizhiao/elf_loader
max_upload_size
id1696251
size30,472
wzhao (weizhiao)

documentation

README

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::{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());
}

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.
Commit count: 94

cargo fmt