SetWindowsHookEx DLL injection.

On viernes, 28 de enero de 2011 1 comentarios

GetProcAddress fails with ERROR_PROC_NOT_FOUND.

What am I overlooking within the DLL?

Inject

Code:
void Injector::Inject(void){
   if(CheckProcess()){
      HMODULE dll  = LoadLibrary(dll_name);
      FARPROC proc = GetProcAddress(dll, "GetMsgProc");
      HHOOK   hh    = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)proc, dll, te.th32ThreadID);
      UnhookWindowsHookEx(hh);
   }
}


DLL
Code:
#include

extern "C" __declspec(dllexport)LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam){
   return CallNextHookEx(0, nCode, wParam, lParam);
}

BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
   UNREFERENCED_PARAMETER(hinstDLL);
   UNREFERENCED_PARAMETER(fdwReason);
   switch(fdwReason)
   {
   case DLL_PROCESS_ATTACH:
      MessageBox(0, "Hi", "Sup", MB_OK);
      return TRUE;
   case DLL_PROCESS_DETACH:
      return TRUE;
   }
   return ERROR_SUCCESS;
}

1 comentarios:

Unknown dijo...

Nice... but ¿why in english when you're sud-américan guy?

Publicar un comentario