c++ - 挂钩函数
问题描述
我正在使用 VS2019,我想在加载到进程中的模块中挂钩函数这是函数代码
void C::GetDrawPosition(float* pX, float* pY, bool* pbBehindCamera, QAngle angleCrosshairOffset)
{
...
* pX = x;
* pY = y;
*pbBehindCamera = bBehindCamera;
}
...
class C
{
public:
static void GetDrawPosition ( float *pX, float *pY, bool *pbBehindCamera, QAngle angleCrosshairOffset = vec3_angle );
};
这是函数原型以及我如何挂钩它
typedef void(__cdecl *GetDrawPosition_t) (float*, float*, bool*, QAngle);
extern GetDrawPosition_t GetDrawPosition_s;
...
GetDrawPosition_t GetDrawPosition_s = nullptr;
DWORD GetDrawPosition_adr = GetClientSig("55 8B EC ...");
XASSERT(GetDrawPosition_adr);
GetDrawPosition_s = (GetDrawPosition_t)DetourFunction((LPBYTE)GetDrawPosition_adr,(LPBYTE)&Hooked_GetDrawPosition);
和我的钩子
void __cdecl Hooked_GetDrawPosition(float* pX, float* pY, bool* pbBehindCamera, QAngle angleCrosshairOffset)
{
*pX = *pX - 400;
*pY = *pY - 101;
GetDrawPosition_s(pX, pY, pbBehindCamera, angleCrosshairOffset);
}
问题是它没有做任何改变,我尝试使用不同的约定类型,我不知道我做错了什么,签名是正确的 100%
提前感谢您的帮助
解决方案
如果C
是类且GetDrawPosition
不是静态成员函数,则类型C::GetDrawPosition(float* pX, float* pY, bool* pbBehindCamera, QAngle angleCrosshairOffset)
is not void(__cdecl *GetDrawPosition_t) (float*, float*, bool*, QAngle)
,其类型为
void(__cdecl C::*GetDrawPosition_t) (float*, float*, bool*, QAngle)
它期望您必须以C
某种方式传递指向类型对象实例的指针。
你不能直接绕过非静态方法,至少在 Detour 1.0 中是这样。我看到了 2.0\ 3.0 Express 的例子(你可以在网上找到)
推荐阅读
- node.js - 无法在 Node.js express 中获取传入请求的 IP 地址
- sql - oracle sql中如何将列转换为行
- elasticsearch - ElasticSearch 查询返回错误的结果
- javascript - 羽毛笔编辑器字母列表
- authentication - 使用 RIO 在 Servant.Auth 中拒绝身份验证
- javascript - 从父组件传递道具后组件未更新
- javascript - 空间和时间的优化解决方案
- c# - .net在文本字段中输入货币格式(从右到左)使用angularJS
- mysql - 如何将mysql上的其他行表GROUP_CONCAT到PHP中的关联数组中
- c# - 由于错误类型“...”未标记为可序列化,C# 无法调整控件大小