首页 > 解决方案 > C++ 这段代码是否修改了指向 this 的任何数据指针,还是只返回它?

问题描述

似乎每次我调用这个函数。就像这样,它实际上是正确的。但我想避免调用函数,因为如果参数错误,这有时会崩溃,所以我想仅仅依靠修改内存地址/值来避免这个问题。

这是工作挂钩 CALL。

DWORD thisPointer = 0xABCDEF;
typedef int(__thiscall* dwordHookFunction )(DWORD a1, DWORD a2);
dwordHookFunction testCall;
testCall = (dwordHookFunction)0x5E0280; //Address matches ForceSlectionFunction offset.

testCall(thisPointer, 1);

这是反编译的函数。

int __thiscall ForceSelectionFunction(int this, int a2)
{
  int result; // eax

  if ( a2 > 0 && a2 < *(_DWORD *)(this + 4) )
    result = *(_DWORD *)this + 0x1E9B8 * a2;
  else
    result = 0;
  return result;
}

这个函数如何修改this指针的内存它甚至修改它?它甚至修改任何东西还是只返回数据?..它必须修改一些东西,否则我认为它不会工作..

我将如何调用更改?

*(unsigned int*)(0xABCDEF + 0x1E9B8 * 1) = ???

或者是

*(unsigned int*)(0xABCDEF) = 0x1E9B8 * 1 //???

PS> 任何人都想看看这里的 ASM 代码。

seg000:005E0280 ; =============== S U B R O U T I N E =======================================
seg000:005E0280
seg000:005E0280 ; Attributes: bp-based frame
seg000:005E0280
seg000:005E0280 ; int __thiscall ForceSelectionFunction(_DWORD this, int a2)
seg000:005E0280 ForceSelectionFunction proc near    ; CODE XREF: sub_412260+618↑p
seg000:005E0280                                         ; sub_415240+F6↑p ...
seg000:005E0280
seg000:005E0280 var_4           = dword ptr -4
seg000:005E0280 a2              = dword ptr  8
seg000:005E0280
seg000:005E0280                 push    ebp
seg000:005E0281                 mov     ebp, esp
seg000:005E0283                 push    ecx
seg000:005E0284                 mov     [ebp+var_4], ecx
seg000:005E0287                 cmp     [ebp+a2], 0
seg000:005E028B                 jle     short loc_5E0298
seg000:005E028D                 mov     eax, [ebp+var_4]
seg000:005E0290                 mov     ecx, [ebp+a2]
seg000:005E0293                 cmp     ecx, [eax+4]
seg000:005E0296                 jl      short loc_5E029C
seg000:005E0298
seg000:005E0298 loc_5E0298:                             ; CODE XREF: ForceSelectionFunction+B↑j
seg000:005E0298                 xor     eax, eax
seg000:005E029A                 jmp     short loc_5E02AA
seg000:005E029C ; ---------------------------------------------------------------------------
seg000:005E029C
seg000:005E029C loc_5E029C:                             ; CODE XREF: ForceSelectionFunction+16↑j
seg000:005E029C                 mov     eax, [ebp+a2]
seg000:005E029F                 imul    eax, 1E9B8h
seg000:005E02A5                 mov     edx, [ebp+var_4]
seg000:005E02A8                 add     eax, [edx]
seg000:005E02AA
seg000:005E02AA loc_5E02AA:                             ; CODE XREF: ForceSelectionFunction+1A↑j
seg000:005E02AA                 mov     esp, ebp
seg000:005E02AC                 pop     ebp
seg000:005E02AD                 retn    4
seg000:005E02AD ForceSelectionFunction endp

在这个游戏的旧版本中,它会像这样反编译......这几乎是相同的事情,只是完成了一些结构工作。

int __thiscall ForceSelectionFunction(_DWORD *this, int a2)
{
  int result; // eax

  if ( a2 <= 0 || a2 >= this[1] )
    result = 0;
  else
    result = *this + 0x1FB50 * a2;
  return result;
}

标签: c++

解决方案


推荐阅读