C++ 如何创建当前函数的typedef,但删除一个参数并更改调用约定?

C++ 如何创建当前函数的typedef,但删除一个参数并更改调用约定?,c++,hook,calling-convention,C++,Hook,Calling Convention,我想知道是否有一种方法可以为当前正在执行的函数创建一个typedef,但是删除第二个参数将其调用约定更改为uu thiscall?目前我正在这样做: // Some other part of the application code will set this value to something valid void* real_function_addr = (void*)0xdeadbeef; int __fastcall a_hooked_thiscall_function( voi

我想知道是否有一种方法可以为当前正在执行的函数创建一个typedef,但是删除第二个参数将其调用约定更改为uu thiscall?目前我正在这样做:

// Some other part of the application code will set this value to something valid
void* real_function_addr = (void*)0xdeadbeef;

int __fastcall a_hooked_thiscall_function( void *thisPtr, void* not_used, int param)
{
    // Cast a known address to the same signature as the current function, but change
    // the calling convention to __thiscall and remove the not_used param.
    typedef int (__thiscall* func_ptr_t)(void *thisPtr, int param);
    func_ptr_t real_function_addr_typed = reinterpret_cast< func_ptr_t >( real_function_addr );
    return real_function_addr_typed( thisPtr, param );
}

首先,修复
real\u function\u addr
的类型。该语言不赞成在对象(数据)指针和函数指针之间进行强制转换,并且
void*
属于“与对象指针兼容”类别。@BenVoigt但是如果他在POSIX环境中,它的定义是很好的。我能问一下到底是什么问题吗?你做的工作吗?它之所以有效,是因为它用于挂起C++成员函数,但是因为我需要勾出很多函数,所以我想一种方法来把锅炉板的“x”STDCALL(即“调用转换”代码写成一个宏,封装了这3行代码)。请注意,您的代码只适用于简单的情况。一旦你把虚拟函数/多重继承/虚拟继承混合在一起,你就可以把一个成员函数指针塞进
void*
中,然后逃之夭夭。
// Some other part of the application code will set this value to something valid
void* real_function_addr = (void*)0xdeadbeef;

int __fastcall a_hooked_thiscall_function( void *thisPtr, void* not_used, int param)
{
    // Where MAKE_THISCALL somehow fixes up real_function_addr to be a function pointer of type a_hooked_thiscall_function but with __fastcall replaced with __thiscall and the 2nd argument removed
    return MAKE_THISCALL(a_hooked_thiscall_function, real_function_addr)( thisPtr, param );
}