[#] Revolutionary: CreateMove Hook (Coded in RUST!!)

Discussion in 'Hawk Freedom Squadron Accounts - Buy Sell Trade' started by verideth_01, 6/28/17.

Thread Status:
Not open for further replies.
  1. verideth_01

    verideth_01
    Expand Collapse
    High Risk Status: This user has been flagged as high risk due to one or more reasons

    0   0   0

    Offline
    Yo guys, I'm releasing this as a project to learn Rust. The programming language. Its actually been quite great, and I must say, its really interesting!!! The way they handle pointers, the way they manage memory, gives me a whole different feel from programming in C++.

    Too much people coding in C++ is the reason I gave rust a go.


    Anyways heres the code:

    Code:
    /*
    Rust code explaining how direct function detours work
    Copyright: 6-27-2017
    credits: UC for teaching me how hooks work
    */

    #![feature(const_fn)]
    #![feature(libc)]

    extern crate winapi;
    extern crate kernel32;
    #[macro_use] extern crate detour;
    #[macro_use] extern crate lazy_static;
    extern crate libc;

    use detour::*;
    use winapi::{HWND, LPCSTR, UINT, c_int};

    type createmove_fn = fn(f32, *mut UserCmd) -> bool;

    struct UserCmd {
    /* dscode here */
    }

    struct FunctionPtrAddress {
    addy: createmove_fn
    }

    lazy_static! {
    static ref fn_ptrs: FunctionPtrAddress = FunctionPtrAddress {
    addy: unsafe {
    std::mem::transmute::<usize, createmove_fn>(0xFFFF) // createmove address here
    // I would reverse it, but the game I reversed was gmod :{
    }
    };
    }

    static_detours! {
    struct CreateMoveDetour: fn(f32, *mut UserCmd) -> bool;
    }

    // entry point
    #[no_mangle]
    #[allow(non_snake_case, unused_variables)]
    pub extern "system" fn DllMain(
    dll_module: winapi::HINSTANCE,
    call_reason: winapi::DWORD,
    reserved: winapi::LPVOID)
    -> winapi::BOOL
    {
    const DLL_PROCESS_ATTACH: winapi::DWORD = 1;
    const DLL_PROCESS_DETACH: winapi::DWORD = 0;

    match call_reason {
    DLL_PROCESS_ATTACH => init(),
    DLL_PROCESS_DETACH => (),
    _ => ()
    }

    return winapi::TRUE;
    }

    // init
    fn init() {
    unsafe {
    kernel32::AllocConsole()
    };

    println!("Initializing...");

    let closure_for_createmove = |input_sample_time, cmd| {
    println!("love you weebs, heres the detour. put your code in here");

    return (fn_ptrs.addy)(input_sample_time, cmd);
    };

    let mut hook = unsafe {
    CreateMoveDetour.initialize(createmove_hook, closure_for_createmove).unwrap()
    };

    unsafe {
    hook.enable().unwrap();
    }

    createmove_hook(1.0, std::ptr::null_mut()); // call this so hook.call works
    hook.call(100.0, std::ptr::null_mut());
    }

    fn createmove_hook(input_sample_time: f32, cmd: *mut UserCmd) -> bool {
    println!("original function");

    return (fn_ptrs.addy)(input_sample_time, cmd);
    }
    Honestly, one of the more fun projects I've done.

    Shouts out to snip

    Enjoy, thank me, and reply what you think!! :)'

    Add me on steam!! If you need any reversing or coding help: id/probablycoding/
     
    • This user is inactive. Hasn't logged into their account in over 60 days.
Thread Status:
Not open for further replies.