Logger excercise

Another semester over, another random project I feel like attempting. I've been in the mood to make a key logger of sorts (No, not for malicious intent, just for the sake of learning). I'm not sure what all I will need for this, though. I know I will need to capture input of course. And I will also need to make sure this program remains hidden. But, this is about all I know about this. I realize it will likely be a challenge for me, but what's life without challenge right?

I'm thinking about implementing it like so:
Program is installed and runs at start up

Whenever a key is hit, it is captured and written onto a file, along with the window name that this key was pressed into.

I would like a way to send this file to my email after x amount of time inactive, but that may be for another day. Really, all I wanna do is capture user input and store it somewhere. Whether that be a file or a container.

If you all could steer me in the right direction, that would be much appreciated. I do not want any answers on how to do this, just the right direction.

Thanks ahead of time!
To make something that runs completely in the background, perhaps try creating a windows service:
http://msdn.microsoft.com/en-us/library/y817hyb6(v=VS.80).aspx

To actually capture each key, check out "event handling".

To figure out which window the event belongs to, you'll need to check out some HINSTANCE stuff in win32.

A good tutorial for this stuff may be here:
http://www.winprog.org/tutorial/
Oh and for the email part. That shouldn't be too hard to get the timing and stuff sent. But you'll need to fill up a buffer with your key logs and then implement an SMPT handle in c++ to send that buffer.
Cool thanks for your fast reply! I don't know much about filling the buffer, got a good link for that one too :D
Is there any reason that I couldn't store the log onto a file, and then just send a copy of the file. Or at least the contents?
I suppose you could do that. For that you'd just need to use #include <ofstream> like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <ofstream>

...
ofstream fout("output.txt"); // Create file output.txt
int Event;

while ( getEvent( &Event )) // Enter your main loop that will run until the process is killed.
{
    // getEvent is a function that will "block" then return true if an event is caught
    // or false if an event is faulty.  "blocking" means that it will pause until the event is 
    // caught, preventing the program from continuing.
   
    // getEvent will modify Event, setting it equal to a value dictated by an enum containing a 
    // list of all of the keys on a keyboard.  That enum is in namespace "key"

    switch (Event) // Check which event we are capturing
    {
    case key::a:
        fout << 'a' << flush; // Output to the stream and then flush the stream to the file.
    case key::b:
        fout << 'b' << flush;
    case key::Esc : 
        fout << " [Escape] " << flush; // We can capture any key, not just letters.
    ... // Put the rest of the keys here.
    }
}


Now you just need to write your getEvent() function.
look you're not fooling anyone, you want to learn h4x!

...try playing around with WinAPI's ::FindWindow command. It will give you a handle to any process that is running's window (if you can find it) and then you can do fun stuff to it using the handle. Or you could just use it to find all windows and kill them all, or you could find all windows and make each one keep forking...

don't bother thanking me!
I can really just use key::x? All the research ive done has said to get the ascii value of each key and use that
Topic archived. No new replies allowed.