I am sorry if this is in any way against the rules; the code isn't intended to be malicious, though it could be. If it is that bad, please delete/lock the thread instead of banning me.
So, I'm creating a keylogger, and it's not working as expected. Currently the program reads directly into the keyboard port (0x64), and then prints out that character. It echo's my characters when I type into the program, but when I type in a different program, it doesn't detect them. It's not very functional yet, but here is the code:
#include <stdio.h>
#include <sys/io.h>
#define KEYBOARD 0x64
main()
{
unsigned char c;
iopl(3);
ioperm(KEYBOARD, 0, 1);
while (c = inb(KEYBOARD))
if (c != '4' && c != '5') /* mouse related stuff */
printf("%c", c);
ioperm(KEYBOARD, 0, 0);
}
Sounds like the kind of thing you would put in a DOS TSR program but in UNIX this would either go into a driver, or as part of a pseudo-terminal wrapper program.
I would expect if you want to provide this kind of functionality it should be provided in either the
(a) keyboard driver,
(b) terminal protocol handlers
(c) the X windows keyboard handler
Do you understand how a keypress/scan codes come from a physical keyboard and finally end up converted into ascii characters in an input stream to a logical console?
I'm looking at some of the code (on my system: /usr/src/linux-2.6.21.5/drivers/char/keyboard.c), and I just seem lost in the code. Do you have any documents on this subject that I should read?