Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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;
                sorry, but thats exactly what i do, just a other format... when i use this format with the error code analysis then it always call the error
– Joscha Kern
                Dec 1, 2019 at 12:59
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);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.