【发布时间】:2014-02-02 19:12:43
【问题描述】:
int CachedTag_NoCache_GetTagPos( CEntity* centity, int tag, Vector* worldpos )
{
void* funccall = (void*)0x7D5BD0;
__asm {
mov edi, worldpos
mov esi, centity
push tag
call funccall
add esp, 4
}
}
函数在 add esp, 4.... 时崩溃。
我知道它在清理这个内联程序集时会崩溃。我只是不知道如何解决它。
这就是 ida pro 里面的内容:
int __usercall sub_7A7D20<eax>(int a1<ecx>, int a2<edi>, int a3<esi>, int a4)
{
int v4; // eax@2
int result; // eax@2
char *v6; // eax@3
char v7; // al@5
int v8; // [sp+0h] [bp-4h]@1
v8 = a1;
if ( *(_WORD *)(a3 + 678) == 1 )
{
LOBYTE(v8) = sub_5BB6F0(*(_BYTE *)(a3 + 4), *(_DWORD *)(a3 + 0x1E8));
v4 = sub_7A7C40();
result = sub_4DA2F0(a3, a2, a4, v4, v8);
}
else
{
v6 = sub_615EA0(*(_DWORD *)(a3 + 0x1E8), *(_BYTE *)(a3 + 4));
result = sub_4B2F50(a3, v6, a2, a4);
}
if ( !result )
{
v7 = sub_624C70(a2, 0);
result = sub_627380(1, "AimTarget_GetTagPos: Cannot find tag [%s] on entity\n", v7);
}
return result;
}
来自 ida pro 的这个函数的汇编文本:
.text:007D5BD0 sub_7D5BD0 proc near ; CODE XREF: sub_4DA2F0+76p
.text:007D5BD0 ; sub_62AE20+18p
.text:007D5BD0
.text:007D5BD0 arg_0 = dword ptr 4
.text:007D5BD0
.text:007D5BD0 movzx eax, byte ptr [esi+4]
.text:007D5BD4 mov ecx, [esi+1E8h]
.text:007D5BDA push ebx
.text:007D5BDB mov ebx, [esp+4+arg_0]
.text:007D5BDF push eax
.text:007D5BE0 push ecx
.text:007D5BE1 call sub_615EA0
.text:007D5BE6 add esp, 8
.text:007D5BE9 test eax, eax
.text:007D5BEB jnz short loc_7D5C00
.text:007D5BED fld dword ptr [esi+30h]
.text:007D5BF0 pop ebx
.text:007D5BF1 fstp dword ptr [edi]
.text:007D5BF3 fld dword ptr [esi+34h]
.text:007D5BF6 fstp dword ptr [edi+4]
.text:007D5BF9 fld dword ptr [esi+38h]
.text:007D5BFC fstp dword ptr [edi+8]
.text:007D5BFF retn
.text:007D5C00 ; ---------------------------------------------------------------------------
.text:007D5C00
.text:007D5C00 loc_7D5C00: ; CODE XREF: sub_7D5BD0+1Bj
.text:007D5C00 push edi
.text:007D5C01 push ebx
.text:007D5C02 push eax
.text:007D5C03 push esi
.text:007D5C04 call sub_4B2F50
.text:007D5C09 add esp, 10h
.text:007D5C0C test eax, eax
.text:007D5C0E jnz short loc_7D5C2B
.text:007D5C10 push eax
.text:007D5C11 push ebx
.text:007D5C12 call sub_624C70
.text:007D5C17 push eax ; char
.text:007D5C18 push offset aCachedtag_noca ; "CachedTag_NoCache_GetTagPos: Cannot fin"...
.text:007D5C1D push 1 ; int
.text:007D5C1F call sub_627380
.text:007D5C24 add esp, 14h
.text:007D5C27 xor eax, eax
.text:007D5C29 pop ebx
.text:007D5C2A retn
.text:007D5C2B ; ---------------------------------------------------------------------------
.text:007D5C2B
.text:007D5C2B loc_7D5C2B: ; CODE XREF: sub_7D5BD0+3Ej
.text:007D5C2B mov edx, dword_D4F178
.text:007D5C31 mov eax, [edx+40688h]
.text:007D5C37 pop ebx
.text:007D5C38 retn
.text:007D5C38 sub_7D5BD0 endp
.text:007D5C38
.text:007D5C38 ; ---------------------------------------------------------------------------
.text:007D5C39 align 10h
.text:007D5C40
我拥有的程序集正在工作。我进入游戏,它向我展示了我想要的大约 3 分钟。然后它崩溃了。在将 Visual Studio 附加到该进程时,它总是说在我上面的 add esp, 4 函数上崩溃了。
现在,在使用 edi 和 esi 的用户调用中,我是否必须在调用我的函数后将它们弹出和/或我是否也必须保留某些内容?
它显然不是我的方式,因为它只能工作大约 3 分钟。我最长的代码工作时间大约是 3 场比赛。大约 10 分钟。
在这 3 场比赛之后,我开始出现致命错误。
感谢有知识回答这个问题的人。
我知道在内联程序集中调用该函数后进行清理有些愚蠢。
【问题讨论】:
标签: c++ c assembly hook calling-convention