Crates.io | loserland_exec |
lib.rs | loserland_exec |
version | 0.1.0 |
source | src |
created_at | 2022-01-09 15:39:41.768167 |
updated_at | 2022-01-09 15:39:41.768167 |
description | A short description of my package |
homepage | |
repository | |
max_upload_size | |
id | 510892 |
size | 22,420 |
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!
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.
Please feel free to open an issue or reach out on twitter
Questions, comments, concerns, and contributions will be met with compassion.