我有以下问题:我有一个旧的 DetourFunction 这些工作正常..现在想使用新的 DetourAttach 但我的 Hook 不再工作了......也许有人知道我做错了什么。
老一:
#include <windows.h>
#include <detours.h>
DWORD score_adr = 0x01013C89;
typedef DWORD *(__stdcall *score)(DWORD *a1, int a2);
score o_score;
DWORD *__stdcall h_score(DWORD *a1, int a2)
{
static int new_score;
new_score += 1;
a1[1] = 1;
return o_score(a1, new_score);
}
BOOL __stdcall DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpcReserved)
{
switch (fdwReason){
case DLL_PROCESS_ATTACH:
o_score = (score)DetourFunction((PBYTE)score_adr, (PBYTE)&h_score);
break;}
return TRUE;
}
新的一个:
#include <windows.h>
#include <detours.h>
DWORD score_adr = 0x01013C89;
typedef DWORD* (__stdcall* o_score)(DWORD* a1, int a2);
o_score score;
DWORD* __stdcall h_score(DWORD* a1, int a2)
{
static int new_score;
new_score += 1;
a1[1] = 1;
return score(a1, new_score);
}
BOOL __stdcall DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpcReserved)
{
switch (fdwReason){
case DLL_PROCESS_ATTACH:
score = (o_score)(score_adr);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread);
DetourAttach((PVOID*)(&score), (PVOID)h_score);
DetourTransactionCommit();
}
return TRUE;
}