Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

c++ - C ++ DetourAttach(C++ DetourAttach)

i have the following Problem: i have a old DetourFunction these are working fine.. Now a want to use the new DetourAttach but my Hook is not working anymore... Maybe anyone has an Idea what i'am doing wrong.

(我有以下问题:我有一个旧的DetourFunction,它们工作正常。.现在想使用新的DetourAttach,但我的挂钩不再工作了……也许有人知道我在做什么错。)

OLD ONE:

(老一:)

#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;
}

NEW One:

(新的一个:)

#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;
}
  ask by Joscha Kern translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...