我有以下问题: 我有一个旧的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;
}
答案 0 :(得分:0)
它现在正在工作...
#include <cstdio>
#include <windows.h>
#include <detours.h>
typedef void (WINAPI *score)(DWORD* a1, int a2);
void WINAPI h_score(DWORD* a1, int a2);
score Nscore = (score)(0x01013C89); //Set it at address to detour in
//the process
INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
{
DisableThreadLibraryCalls(hDLL);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Nscore, h_score);
DetourTransactionCommit();
}
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Nscore, h_score);
DetourTransactionCommit();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
void WINAPI h_score(DWORD* a1, int a2)
{
static int new_score;
new_score += 1;
a1[1] = 1;
return Nscore(a1, new_score);
}