windows-elf-loader 0.1.2

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: 25.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 357.52 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s 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::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);
    }
    // Symbols required by dynamic library liba.so
    let host = SyntheticModule::new(
        "__host",
        [SyntheticSymbol::function("print", print as *const ())],
    );
    let mut loader: WinElfLoader = WinElfLoader::new();
    // Load and relocate dynamic library liba.so
    let liba = loader
        .load_file(r".\crates\windows-elf-loader\example_dylib\liba.so")
        .unwrap()
        .relocator()
        .scope([host])
        .relocate()
        .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.