Page 1 of 1

Exploring the Rust programming language

Posted: Sun Sep 24, 2017 8:45 pm
by fips
I have finally found some time to learn more about the Rust programming language, which has been under my radar for a couple of years now, but I had no chance to get my hands dirty until recently. There's a great book to start with, called: The Rust Programming Language, which is very well written and quite approachable (demonstrating how vital the Rust comunity is). I now begin to feel that Rust is a serious contender to C++, almost as if Rust came into existence to fix all the C++'s mistakes and expand the benefits, which I guess was among other motivations actually the case.

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
Some more useful resources:
GoogleTechTalks: The Rust Programming Language (YouTube):
StrangeLoop: Level Up Your Concurrency Skills With Rust (YouTube):
A Case for Oxidation: The Rust Programming Language (YouTube):
Diving Into Rust For The First Time (YouTube):
Stanford Seminar - The Rust Programming Language (YouTube):
Rust Crash Course | Rustlang (YouTube):