loserland_exec

A short description of my package

1 unstable release

0.1.0 Jan 9, 2022

MIT/Apache

23KB
442 lines

loserland_exec

Load a DLL from memory

A neat example of translating unsafe C code to Rust.

To quote fancycode:

The default windows API functions to load external libraries into a program
(LoadLibrary, LoadLibraryEx) only work with files on the filesystem. 

This makes it difficult to execute code given a stream of bytes who don't reside on the Windows Filesystem.

extern crate loserland_exec;

use std::fs::File;

// helloworld.dll exports a function named callme
let mut dll_file = File::open("helloworld.dll").unwrap();
let mut dll_data = Vec::new();

// Read the dll file into a vector of bytes so we can pretend we got them from anywhere
dll_file.read_to_end(&mut dll_data).unwrap();

// Find the function exported by our dll in memory
let callme = loserland_exec::get_proc("callme", &dll_data) as *const ();

// Execute the code
(callme)(); // Hello from plugin!

Status

Looking for help writing up in-depth documentation showing how the memory is laid out and code is executed. Would also like to add linux and darwin compatability.

Contributing

Please feel free to open an issue or reach out on twitter

Questions, comments, concerns, and contributions will be met with compassion.

References

Dependencies

~480–750KB
~12K SLoC