Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   hooking send() and call the original (http://www.go4expert.com/forums/hooking-send-original-t7512/)

yoni1993 24Nov2007 23:57

hooking send() and call the original
 
i detoured the send() with success, and in my detoured function i want to call the ORIGINAL function !

How to do it if the original itself get hooked, its will go into a loop !

Code:

void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
        BYTE *jmp = (BYTE*)malloc(len+5);
        DWORD dwback;

        VirtualProtect(src, len, PAGE_READWRITE, &dwback);

        memcpy(jmp, src, len);        jmp += len;
       
        jmp[0] = 0xE9;
        *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;

        src[0] = 0xE9;
        *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;

        VirtualProtect(src, len, dwback, &dwback);

        return (jmp-len);
}

int WINAPI mysend(SOCKET s,        const char* buf, int len, int flags)
{
        MessageBox(NULL, buf, "I caught a packet :) !!!", NULL);
        send(s, buf, len, flags);
        return 1;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                      DWORD  ul_reason_for_call,
                      LPVOID lpReserved
                                        )
{
        DisableThreadLibraryCalls(hModule);

        hMod = LoadLibrary("ws2_32.dll");
               
        DetourFunc((BYTE*)GetProcAddress(hMod, "send"), (BYTE*)mysend,2);

    return TRUE;
}

im new here, i hope that members can help me.
thank you


All times are GMT +5.5. The time now is 14:04.