我正在使用 MinHook 挂钩具有以下签名的静态函数:
float __usercall RadarManager::Add_Blip@<xmm0>(int position@<ecx>, int shape@<edx>, int colorId, float intensity@<xmm3>, bool isBracket, bool isSmall)
我已经使用 IDA 确认寄存器/堆栈的使用是正确的。我还确认我使用 Visual Studio 获得了正确的地址来调试我的代码。它首先进入 MinHook 生成的蹦床,执行前几个操作码,然后跳过被覆盖的字节跳转到原始函数。
我让我的钩子函数完全空了,但程序仍然在其他任意地址上崩溃。
我的钩子函数如下:
float __declspec(naked) radarAddBlip(const Vector3 &position, int shape, int colorId, float intensity, bool isBracket, bool isSmall)
{
__asm
{
call originalRadarManager_Add_Blip;
ret;
}
}
被钩住的函数的序言:
.text : 1181F4C0 push ebp
.text : 1181F4C1 mov ebp, esp
.text : 1181F4C3 and esp, 0FFFFFFF8h
.text : 1181F4C6 sub esp, 34h
.text : 1181F4C9 movss xmm2, dword ptr[ecx + 4]
.text : 1181F4CE movss xmm1, dword ptr[ecx + 8]
.text : 1181F4D3 movss dword ptr[esp + 34h + var_20], xmm3
.text : 1181F4D9 movss xmm3, dword ptr[ecx]
.text : 1181F4DD movaps xmm0, xmm2
.text : 1181F4E0 mulss xmm0, dword_11A6D7AC
.text : 1181F4E8 mulss xmm2, dword_11A6D7BC
.text : 1181F4F0 movaps xmm4, xmm3
.text : 1181F4F3 mulss xmm4, dword_11A6D7A8
.text : 1181F4FB mulss xmm3, dword_11A6D7B8
.text : 1181F503 addss xmm4, xmm0
.text : 1181F507 movaps xmm0, xmm1
.text : 1181F50A mulss xmm0, dword_11A6D7B0
.text : 1181F512 mulss xmm1, dword_11A6D7C0
.text : 1181F51A addss xmm3, xmm2
.text : 1181F51E addss xmm4, xmm0
.text : 1181F522 push ebx
.text : 1181F523 push esi
.text : 1181F524 mov esi, edx
.text : 1181F526 addss xmm3, xmm1
.text : 1181F52A addss xmm4, dword_11A6D7B4
.text : 1181F532 movss xmm1, ds : dword_11A419F0
.text : 1181F53A push edi
.text : 1181F53B mov[esp + 40h + var_14], esi
.text : 1181F53F addss xmm3, dword_11A6D7C4
.text : 1181F547 mulss xmm4, xmm1
.text : 1181F54B mulss xmm3, xmm1
.text : 1181F54F mulss xmm1, ds : dword_11A3ED98
.text : 1181F557 movaps xmm0, xmm3
.text : 1181F55A mulss xmm0, xmm3
.text : 1181F55E movaps xmm2, xmm4
.text : 1181F561 mulss xmm2, xmm4
.text : 1181F565 movss[esp + 40h + var_30], xmm4
.text : 1181F56B movss[esp + 40h + var_2C], xmm3
.text : 1181F571 addss xmm2, xmm0
.text : 1181F575 movaps xmm0, xmm1
.text : 1181F578 mulss xmm0, xmm1
.text : 1181F57C movss[esp + 40h + var_28], xmm1
.text : 1181F582 addss xmm2, xmm0
.text : 1181F586 cvtps2pd xmm0, xmm2
.text : 1181F589 movss[esp + 40h + var_24], xmm2
.text : 1181F58F call _libm_sse2_sqrt_precise
.text : 1181F594 movss xmm1, ds : dword_11A41A30
.text : 1181F59C cvtsd2ss xmm0, xmm0
.text : 1181F5A0 comiss xmm0, ds : dword_11A41E10
.text : 1181F5A7 jb loc_1181F62E
.text : 1181F5AD cmp esi, 4
.text : 1181F5B0 jnz short loc_1181F621
.text : 1181F5B2 movss xmm0, [esp + 34h + var_18]
.text : 1181F5B8 addss xmm0, ds : dword_11A41828
.text : 1181F5C0 cvtps2pd xmm0, xmm0
.text : 1181F5C3 call _libm_sse2_sqrt_precise
函数被钩住的结尾:
.text : 1181F7B7 cmp[ebp + isBracket], 0
.text : 1181F7BB jz short loc_1181F7F8
.text : 1181F7BD mov esi, dword_11A5F400
.text : 1181F7C3 push 0
.text : 1181F7C5 push dword ptr[esi + 0C4h]
.text : 1181F7CB mov ecx, esi
.text : 1181F7CD call sub_11822750
.text : 1181F7D2 lea eax, [esp + 34h + var_4]
.text : 1181F7D6 push eax
.text : 1181F7D7 mov ecx, esi
.text : 1181F7D9 call sub_11822330
.text : 1181F7DE push offset dword_11A6D8B0
.text : 1181F7E3 mov ecx, esi
.text : 1181F7E5 call sub_11822B00
.text : 1181F7EA or edi, 0FF00h
.text : 1181F7F0 push edi
.text : 1181F7F1 mov ecx, esi
.text : 1181F7F3 call sub_11822660
.text : 1181F7F8
.text : 1181F7F8 loc_1181F7F8 : ; CODE XREF : RadarManager__Add_Blip + 2FBj
.text : 1181F7F8 movss xmm0, ds : dword_11A41A30
.text : 1181F800 pop edi
.text : 1181F801 pop esi
.text : 1181F802 pop ebx
.text : 1181F803 mov esp, ebp
.text : 1181F805 pop ebp
.text : 1181F806 retn
调用原始函数的示例(留在一些额外的操作码中):
.text : 11820270 mov eax, [ecx + 4]
.text : 11820273 mov esi, [eax + edi * 4]
.text : 11820276 cmp byte ptr[esi + 24h], 0
.text : 1182027A jz short loc_118202C8
.text : 1182027C cmp dword ptr[esi + 8], 0
.text : 11820280 jnz short loc_118202C8
.text : 11820282 mov eax, [esi + 4]
.text : 11820285 movss xmm3, dword ptr[esi + 34h]; a4
.text : 1182028A push 0; a5
.text : 1182028C add eax, 4
.text : 1182028F push 0; a5
.text : 11820291 push eax; a3
.text : 11820292 lea ecx, [esi + 28h]; a1
.text : 11820295 mov edx, 4; a2
.text : 1182029A call RadarManager__Add_Blip
.text : 1182029F movaps xmm1, xmm0
.text : 118202A2 xorps xmm0, xmm0
.text : 118202A5 add esp, 0Ch
.text : 118202A8 comiss xmm0, xmm1
.text : 118202AB ja short loc_118202BA
.text : 118202AD movss xmm0, ds : dword_11A41A30
.text : 118202B5 comiss xmm1, xmm0
.text : 118202B8 jbe short loc_118202BD
.text : 118202BA
.text : 118202BA loc_118202BA : ; CODE XREF : RadarManager__Update + A8Bj
.text : 118202BA movaps xmm1, xmm0
.text : 118202BD
.text : 118202BD loc_118202BD : ; CODE XREF : RadarManager__Update + A98j
.text : 118202BD mov ecx, dword_11A679C4
.text : 118202C3 movss dword ptr[esi + 34h], xmm1
复制到蹦床的操作码(在 jmp 之前)
.text : 1181F4C0 push ebp
.text : 1181F4C1 mov ebp, esp
.text : 1181F4C3 and esp, 0FFFFFFF8h
我尝试更改调用约定,使其成为 __declspec(naked) 并直接调用它,甚至手动编辑注册表,但无济于事。我已经筋疲力尽了,当它什么都不做时,我什至无法让它工作。
总结我的问题:如何通过钩子函数成功调用原始函数并在调用原始函数之前执行某些操作?我不需要使用 MinHook,但到目前为止它一直做得很好。