Winsock Crash (c++)

c++ / delphi package - dll injection and api hooking
Post Reply
shizz
Posts: 1
Joined: Wed Nov 03, 2004 4:08 pm

Winsock Crash (c++)

Post by shizz »

Can someone help me out with this?
After I injected my dll, any program using winsock2's recv crashes. I'm using DllInjector.exe from the madCollection to inject this dll.

Code: Select all

#pragma comment(lib, "madCHook.lib")
#pragma comment(lib, "Ws2_32.lib")

#include <winsock2.h>
#include <windows.h>

#include <madCHook.h>

int (WINAPI *org_recv) (SOCKET s, char * buf, int len, int flags);


int hook_recv (SOCKET s, char * buf, int len, int flags)
{
  return org_recv(s, buf, len, flags);
}


BOOL APIENTRY DllMain(HMODULE hModule, DWORD callReason, LPVOID lpReserved) 
{
  if (callReason == DLL_PROCESS_ATTACH)
  {
    InitializeMadCHook();

    HookAPI("ws2_32.dll", "recv", hook_recv, (PVOID*) &org_recv);
  }
  else if (callReason == DLL_PROCESS_DETACH)
  {
    FinalizeMadCHook();
  }

  return true;
}
Tnx for any help.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

hook_recv needs WINAPI, too.
Post Reply