Anyway, my fist Rust program is not quite a typical one. I was rather curious how to dynamically load a library and call an exported function (In my case, I'm invoking 'cosf', which is available in 'msvcr100.dll' on Windows). This is an essential tool a system hacker needs to posses :), so here it is:
Code: Select all
// [CODE BY FIPS @ 4FIPS.COM, (c) 2017 FILIP STOKLAS, MIT-LICENSED]
extern crate libloading;
use libloading::{Library, Symbol};
type CosFunc = fn(f32) -> f32;
fn main() {
let dll = Library::new("msvcr100.dll").unwrap();
unsafe {
let func: Symbol<CosFunc> = dll.get(b"cosf").unwrap();
println!("cos(0) = {}", func(0.0));
}
}
// output:
// cos(0) = 1