windows-elf-loader 0.1.1

Be capable of loading the elf dynamic library on Windows.
Documentation
  • Coverage
  • 12.5%
    1 out of 8 items documented0 out of 4 items with examples
  • Size
  • Source code size: 28.25 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 26s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • weizhiao/Relink
    141 26 5
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • weizhiao

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.