Korrekte Benutzung von Microsoft Research Detours 2.1?



  • Warum funktioniert folgendes Beispiel bei mir nicht? Nach Injektion der DLL-Datei (oberer Quelltext) wird die Funktion MyPrint nicht aufgerufen 😞

    /* Evil DLL-File */
    
    #include <windows.h>
    #include <detours.h>
    #include <cstdio>
    
    #pragma comment(lib, "detours.lib")
    #pragma comment(lib, "detoured.lib")
    
    static int (__cdecl *TruePrint) (const char *Format, ...) = printf;
    
    void MyPrint(const char *Format, ...)
    {
        printf("MyPrint :D\r\n");
    }
    
    int __stdcall DllMain(int argc, char **argv)
    {
        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());
        DetourAttach((void **) TruePrint, MyPrint);
    }
    
    /* Poor EXE-File */
    
    #include <windows.h>
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        while(true)
        {
            if(GetAsyncKeyState('E') & 1)
                break;
            else if(GetAsyncKeyState('K') & 1)
                printf("Hello World!\r\n");
    
            Sleep(50);
        }
    
        return 0;
    }
    


  • Oh, so konnte das ja nichts werden.

    Leider funktioniert es so auch nicht...

    /* Evil DLL-File */
    
    #include <windows.h>
    #include <detours.h>
    #include <cstdio>
    
    #pragma comment(lib, "detours.lib")
    #pragma comment(lib, "detoured.lib")
    
    static int (__cdecl *TruePrint) (const char *Format, ...) = printf;
    
    void MyPrint(const char *Format, ...)
    {
    	printf("MyPrint :D\r\n");
    	fflush(stdout);
    }
    
    int __stdcall DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
    {
    	switch(dwReason)
    	{
    		case DLL_PROCESS_ATTACH:
    			DetourTransactionBegin();
    			DetourUpdateThread(GetCurrentThread());
    			DetourAttach((void **) TruePrint, MyPrint);
    			break;
    
    		default:
    			break;
    	}
    
    	return 1;
    }
    


  • Niemand?



  • DetourTransactionCommit() fehlt nach DetourAttach().
    Und schreibe dort: (void**)**&**TruePrint...



  • Amboss der Rabiator schrieb:

    DetourTransactionCommit() fehlt nach DetourAttach().
    Und schreibe dort: (void**)**&**TruePrint...

    Ich danke dir 😃 😮



  • Vor der nächsten Frage bitte noch hier lesen!


Anmelden zum Antworten