Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: BlackZeroX en 18 Enero 2011, 22:32 pm



Título: [Hook] WH_CBT
Publicado por: BlackZeroX en 18 Enero 2011, 22:32 pm
.
Tengo un problema al realizar el hook al mensaje WH_CBT de forma global mas no por Theard y es que no se instala dicho hook, obtube el error y su descripción pero ni idea a que se refiere  :(.

Código
  1.  
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. HHOOK hHRes;
  6.  
  7. LRESULT CALLBACK CBTProc( int , WPARAM , LPARAM );
  8. void ErrorExit(LPTSTR lpszFunction);
  9.  
  10. int main()
  11. {
  12.    char s[500] ={};
  13.    hHRes = ::SetWindowsHookExA( WH_CBT , &CBTProc , GetModuleHandle( NULL ) , 0 );
  14.    if ( hHRes == NULL ) {
  15.       /* le resto 2 para establecer un caracter nulo en formato WCHAR */
  16.       ::FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM , NULL , ::GetLastError() , NULL , (WCHAR*)&s , (DWORD) strlen(&s[0])/2 - 2 , NULL );
  17.       ::MessageBoxExW(NULL,(WCHAR*)&s,NULL,0,NULL);
  18.    }
  19.    return 0;
  20. }
  21.  
  22. LRESULT CALLBACK CBTProc( int nCode, WPARAM wParam, LPARAM lParam )
  23. {
  24.    ::UnhookWindowsHookEx( hHRes );
  25.    return ::CallNextHookEx( hHRes , nCode , wParam , lParam );
  26. }
  27.  
  28.  

Edito: Lei por hay que se debe hacer esto en una dll, que tan cierto es?...

Temibles Lunas!¡.
.


Título: Re: [Hook] WH_CBT
Publicado por: Eternal Idol en 18 Enero 2011, 23:31 pm
Asi es:

Cita de: MSDN
The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.


Título: Re: [Hook] WH_CBT
Publicado por: BlackZeroX en 19 Enero 2011, 00:29 am
.
Perfecto no estaba tan lejos entonces gracias!ˇ.

Dulce sLunas!ˇ.