Hpmason / retour-rs

A cross-platform detour library written in Rust
Other
99 stars 18 forks source link

`thiscall` abi does not work on functions #33

Closed bananasov closed 10 months ago

bananasov commented 10 months ago

As the title says, the thiscall ABI has been stable on nightly (version rustc 1.73.0-nightly (0bdb00d55 2023-08-15)) since last week (in this commit).

Using the thiscall abi on retour 0.3.1 fails.

Example code:

Using retour-utils crate (v0.2.1)

#[hook_module("OpenSpades.exe")]
#[allow(non_snake_case)]
pub mod OpenSpades {
    type NetClient = *mut ();

    /// DoEvents(void* ecx, void* edx, int timeout);
    #[hook(unsafe extern "thiscall" NetClient_DoEvents, offset = 0x3878)]
    pub fn netclient_doevents(this: NetClient, dt: i32) {
        println!("Hey it got called");

        unsafe {
            NetClient_DoEvents.call(this, dt);
        }
    }
}

Error message

error[E0277]: the trait bound `unsafe extern "thiscall" fn(*mut (), i32): Function` is not satisfied
  --> src\hook.rs:9:37
   |
9  |     #[hook(unsafe extern "thiscall" NetClient_DoEvents, offset = 0x3878)]
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Function` is not implemented for `unsafe extern "thiscall" fn(*mut (), i32)`
   |
   = help: the following other types implement trait `Function`:
             unsafe fn() -> Ret
             unsafe extern "C" fn() -> Ret
             unsafe extern "cdecl" fn() -> Ret
             unsafe extern "stdcall" fn() -> Ret
             unsafe extern "fastcall" fn() -> Ret
             unsafe extern "win64" fn() -> Ret
             unsafe extern "system" fn() -> Ret
             fn() -> Ret
           and 202 others
note: required by a bound in `StaticDetour`
  --> C:\Users\geo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\retour-0.3.1\src\detours\statik.rs:65:28
   |
65 | pub struct StaticDetour<T: Function> {
   |                            ^^^^^^^^ required by this bound in `StaticDetour`
bananasov commented 10 months ago

I did not notice the thiscall-abi feature, woops