diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ef829ca..0d1ea40 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -16,10 +16,7 @@
-
-
-
-
+
@@ -121,7 +118,7 @@
-
+
@@ -153,7 +150,8 @@
-
+
+
diff --git a/src/drivers_and_interrupts.h b/src/drivers_and_interrupts.h
index 3171d96..19d5976 100644
--- a/src/drivers_and_interrupts.h
+++ b/src/drivers_and_interrupts.h
@@ -23,10 +23,17 @@ struct KeyboardCaptureData {
};
struct linked_list_node {
- struct KeyboardCaptureData data;
+ struct KeyboardCaptureData key;
+ struct timespec64 when;
+ size_t size;
struct list_head list;
};
+struct logger {
+ char shifted;
+ char capslocked;
+};
+
#ifndef EXTERN
# define EXTERN extern
@@ -36,5 +43,6 @@ extern struct mutex lock;
void print_keyboard_line(struct KeyboardCaptureData data);
+size_t calc_node_size(struct linked_list_node *node);
#endif
diff --git a/src/keyboard_logger.c b/src/keyboard_logger.c
index 29fda7c..f314000 100644
--- a/src/keyboard_logger.c
+++ b/src/keyboard_logger.c
@@ -26,41 +26,41 @@ const struct KeyboardCaptureData KEY_DICTIONARY[DICT_SIZE] = {
{ 0xd, "=", PRESSED, '=' },
{ 0xe, "Backspace", PRESSED, 0 },
{ 0xf, "Tab", PRESSED, '\t' },
- { 0x10, "Q", PRESSED, 'q' },
- { 0x11, "W", PRESSED, 'w' },
- { 0x12, "E", PRESSED, 'e' },
- { 0x13, "R", PRESSED, 'r' },
- { 0x14, "T", PRESSED, 't' },
- { 0x15, "Y", PRESSED, 'y' },
- { 0x16, "U", PRESSED, 'u' },
- { 0x17, "I", PRESSED, 'i' },
- { 0x18, "O", PRESSED, 'o' },
- { 0x19, "P", PRESSED, 'p' },
+ { 0x10, "q", PRESSED, 'q' },
+ { 0x11, "w", PRESSED, 'w' },
+ { 0x12, "e", PRESSED, 'e' },
+ { 0x13, "r", PRESSED, 'r' },
+ { 0x14, "t", PRESSED, 't' },
+ { 0x15, "y", PRESSED, 'y' },
+ { 0x16, "u", PRESSED, 'u' },
+ { 0x17, "i", PRESSED, 'i' },
+ { 0x18, "o", PRESSED, 'o' },
+ { 0x19, "p", PRESSED, 'p' },
{ 0x1a, "[", PRESSED, '[' },
{ 0x1b, "]", PRESSED, ']' },
{ 0x1c, "Enter", PRESSED, '\n' },
{ 0x1d, "Control", PRESSED, 0 },
- { 0x1e, "A", PRESSED, 'a' },
- { 0x1f, "S", PRESSED, 's' },
- { 0x20, "D", PRESSED, 'd' },
- { 0x21, "F", PRESSED, 'f' },
- { 0x22, "G", PRESSED, 'g' },
- { 0x23, "H", PRESSED, 'h' },
- { 0x24, "J", PRESSED, 'j' },
- { 0x25, "K", PRESSED, 'k' },
- { 0x26, "L", PRESSED, 'l' },
+ { 0x1e, "a", PRESSED, 'a' },
+ { 0x1f, "s", PRESSED, 's' },
+ { 0x20, "d", PRESSED, 'd' },
+ { 0x21, "f", PRESSED, 'f' },
+ { 0x22, "g", PRESSED, 'g' },
+ { 0x23, "h", PRESSED, 'h' },
+ { 0x24, "j", PRESSED, 'j' },
+ { 0x25, "k", PRESSED, 'k' },
+ { 0x26, "l", PRESSED, 'l' },
{ 0x27, ";", PRESSED, ';' },
{ 0x28, "'", PRESSED, '\'' },
{ 0x29, "`", PRESSED, '`' },
{ 0x2a, "Shift", PRESSED, 0 },
{ 0x2b, "\\", PRESSED, '\\' },
- { 0x2c, "Z", PRESSED, 'z' },
- { 0x2d, "X", PRESSED, 'x' },
- { 0x2e, "C", PRESSED, 'c' },
- { 0x2f, "V", PRESSED, 'v' },
- { 0x30, "B", PRESSED, 'b' },
- { 0x31, "N", PRESSED, 'n' },
- { 0x32, "M", PRESSED, 'm' },
+ { 0x2c, "z", PRESSED, 'z' },
+ { 0x2d, "x", PRESSED, 'x' },
+ { 0x2e, "c", PRESSED, 'c' },
+ { 0x2f, "v", PRESSED, 'v' },
+ { 0x30, "b", PRESSED, 'b' },
+ { 0x31, "n", PRESSED, 'n' },
+ { 0x32, "m", PRESSED, 'm' },
{ 0x33, ",", PRESSED, ',' },
{ 0x34, ".", PRESSED, '.' },
{ 0x35, "/", PRESSED, '/' },
@@ -111,41 +111,41 @@ const struct KeyboardCaptureData KEY_DICTIONARY[DICT_SIZE] = {
{ 0x8d, "=", RELEASED, '=' },
{ 0x8e, "Backspace", RELEASED, 0 },
{ 0x8f, "Tab", RELEASED, '\t' },
- { 0x90, "Q", RELEASED, 'q' },
- { 0x91, "W", RELEASED, 'w' },
- { 0x92, "E", RELEASED, 'e' },
- { 0x93, "R", RELEASED, 'r' },
- { 0x94, "T", RELEASED, 't' },
- { 0x95, "Y", RELEASED, 'y' },
- { 0x96, "U", RELEASED, 'u' },
- { 0x97, "I", RELEASED, 'i' },
- { 0x98, "O", RELEASED, 'o' },
- { 0x99, "P", RELEASED, 'p' },
+ { 0x90, "q", RELEASED, 'q' },
+ { 0x91, "w", RELEASED, 'w' },
+ { 0x92, "e", RELEASED, 'e' },
+ { 0x93, "r", RELEASED, 'r' },
+ { 0x94, "t", RELEASED, 't' },
+ { 0x95, "y", RELEASED, 'y' },
+ { 0x96, "u", RELEASED, 'u' },
+ { 0x97, "i", RELEASED, 'i' },
+ { 0x98, "o", RELEASED, 'o' },
+ { 0x99, "p", RELEASED, 'p' },
{ 0x9a, "[", RELEASED, '[' },
{ 0x9b, "]", RELEASED, ']' },
{ 0x9c, "Enter", RELEASED, '\n' },
{ 0x9d, "Control", RELEASED, 0 },
- { 0x9e, "A", RELEASED, 'a' },
- { 0x9f, "S", RELEASED, 's' },
- { 0xa0, "D", RELEASED, 'd' },
- { 0xa1, "F", RELEASED, 'f' },
- { 0xa2, "G", RELEASED, 'g' },
- { 0xa3, "H", RELEASED, 'h' },
- { 0xa4, "J", RELEASED, 'j' },
- { 0xa5, "K", RELEASED, 'k' },
- { 0xa6, "L", RELEASED, 'l' },
+ { 0x9e, "a", RELEASED, 'a' },
+ { 0x9f, "s", RELEASED, 's' },
+ { 0xa0, "d", RELEASED, 'd' },
+ { 0xa1, "f", RELEASED, 'f' },
+ { 0xa2, "g", RELEASED, 'g' },
+ { 0xa3, "h", RELEASED, 'h' },
+ { 0xa4, "j", RELEASED, 'j' },
+ { 0xa5, "k", RELEASED, 'k' },
+ { 0xa6, "l", RELEASED, 'l' },
{ 0xa7, ";", RELEASED, ';' },
{ 0xa8, "'", RELEASED, '\'' },
{ 0xa9, "`", RELEASED, '`' },
{ 0xaa, "Shift", RELEASED, 0 },
{ 0xab, "\\", RELEASED, '\\' },
- { 0xac, "Z", RELEASED, 'z' },
- { 0xad, "X", RELEASED, 'x' },
- { 0xae, "C", RELEASED, 'c' },
- { 0xaf, "V", RELEASED, 'v' },
- { 0xb0, "B", RELEASED, 'b' },
- { 0xb1, "N", RELEASED, 'n' },
- { 0xb2, "M", RELEASED, 'm' },
+ { 0xac, "z", RELEASED, 'z' },
+ { 0xad, "x", RELEASED, 'x' },
+ { 0xae, "c", RELEASED, 'c' },
+ { 0xaf, "v", RELEASED, 'v' },
+ { 0xb0, "b", RELEASED, 'b' },
+ { 0xb1, "n", RELEASED, 'n' },
+ { 0xb2, "m", RELEASED, 'm' },
{ 0xb3, ",", RELEASED, ',' },
{ 0xb4, ".", RELEASED, '.' },
{ 0xb5, "/", RELEASED, '/' },
@@ -262,25 +262,287 @@ const struct KeyboardCaptureData KEY_DICTIONARY[DICT_SIZE] = {
{ 0xe11d45e19dc5, "Pause", PRESSED, 0 },
};
-struct KeyboardCaptureData find_key_from_code(uint64_t code) {
+const struct KeyboardCaptureData KEY_DICTIONARY_SHIFTED[DICT_SIZE] = {
+ { 0x1, "Escape", PRESSED, 0 },
+ { 0x2, "!", PRESSED, '!' },
+ { 0x3, "@", PRESSED, '@' },
+ { 0x4, "#", PRESSED, '#' },
+ { 0x5, "$", PRESSED, '$' },
+ { 0x6, "%", PRESSED, '%' },
+ { 0x7, "^", PRESSED, '^' },
+ { 0x8, "&", PRESSED, '&' },
+ { 0x9, "*", PRESSED, '*' },
+ { 0xa, "(", PRESSED, '(' },
+ { 0xb, ")", PRESSED, ')' },
+ { 0xc, "_", PRESSED, '_' },
+ { 0xd, "+", PRESSED, '+' },
+ { 0xe, "Backspace", PRESSED, 0 },
+ { 0xf, "Tab", PRESSED, '\t' },
+ { 0x10, "Q", PRESSED, 'Q' },
+ { 0x11, "W", PRESSED, 'W' },
+ { 0x12, "E", PRESSED, 'E' },
+ { 0x13, "R", PRESSED, 'R' },
+ { 0x14, "T", PRESSED, 'T' },
+ { 0x15, "Y", PRESSED, 'Y' },
+ { 0x16, "U", PRESSED, 'U' },
+ { 0x17, "I", PRESSED, 'I' },
+ { 0x18, "O", PRESSED, 'O' },
+ { 0x19, "P", PRESSED, 'P' },
+ { 0x1a, "{", PRESSED, '{' },
+ { 0x1b, "}", PRESSED, '}' },
+ { 0x1c, "Enter", PRESSED, '\n' },
+ { 0x1d, "Control", PRESSED, 0 },
+ { 0x1e, "A", PRESSED, 'A' },
+ { 0x1f, "S", PRESSED, 'S' },
+ { 0x20, "D", PRESSED, 'D' },
+ { 0x21, "F", PRESSED, 'F' },
+ { 0x22, "G", PRESSED, 'G' },
+ { 0x23, "H", PRESSED, 'H' },
+ { 0x24, "J", PRESSED, 'J' },
+ { 0x25, "K", PRESSED, 'K' },
+ { 0x26, "L", PRESSED, 'L' },
+ { 0x27, ":", PRESSED, ':' },
+ { 0x28, "\"", PRESSED, '"' },
+ { 0x29, "~", PRESSED, '~' },
+ { 0x2a, "Shift", PRESSED, 0 },
+ { 0x2b, "|", PRESSED, '|' },
+ { 0x2c, "Z", PRESSED, 'Z' },
+ { 0x2d, "X", PRESSED, 'X' },
+ { 0x2e, "C", PRESSED, 'C' },
+ { 0x2f, "V", PRESSED, 'V' },
+ { 0x30, "B", PRESSED, 'B' },
+ { 0x31, "N", PRESSED, 'N' },
+ { 0x32, "M", PRESSED, 'M' },
+ { 0x33, "<", PRESSED, '<' },
+ { 0x34, ">", PRESSED, '>' },
+ { 0x35, "?", PRESSED, '?' },
+ { 0x36, "Right Shift", PRESSED, 0 },
+ { 0x37, "* (Keypad)", PRESSED, '*' },
+ { 0x38, "Alt", PRESSED, 0 },
+ { 0x39, "Space", PRESSED, ' ' },
+ { 0x3a, "CapsLock", PRESSED, 0 },
+ { 0x3b, "F1", PRESSED, 0 },
+ { 0x3c, "F2", PRESSED, 0 },
+ { 0x3d, "F3", PRESSED, 0 },
+ { 0x3e, "F4", PRESSED, 0 },
+ { 0x3f, "F5", PRESSED, 0 },
+ { 0x40, "F6", PRESSED, 0 },
+ { 0x41, "F7", PRESSED, 0 },
+ { 0x42, "F8", PRESSED, 0 },
+ { 0x43, "F9", PRESSED, 0 },
+ { 0x44, "F10", PRESSED, 0 },
+ { 0x45, "NumberLock", PRESSED, 0 },
+ { 0x46, "ScrollLock", PRESSED, 0 },
+ { 0x47, "7 (Keypad)", PRESSED, '7' },
+ { 0x48, "8 (Keypad)", PRESSED, '8' },
+ { 0x49, "9 (Keypad)", PRESSED, '9' },
+ { 0x4a, "- (Keypad)", PRESSED, '-' },
+ { 0x4b, "4 (Keypad)", PRESSED, '4' },
+ { 0x4c, "5 (Keypad)", PRESSED, '5' },
+ { 0x4d, "6 (Keypad)", PRESSED, '6' },
+ { 0x4e, "+ (Keypad)", PRESSED, '+' },
+ { 0x4f, "1 (Keypad)", PRESSED, '1' },
+ { 0x50, "2 (Keypad)", PRESSED, '2' },
+ { 0x51, "3 (Keypad)", PRESSED, '3' },
+ { 0x52, "0 (Keypad)", PRESSED, '0' },
+ { 0x53, ". (Keypad)", PRESSED, '.' },
+ { 0x57, "F11", PRESSED, 0 },
+ { 0x58, "F12", PRESSED, 0 },
+ { 0x81, "Escape", RELEASED, 0 },
+ { 0x82, "!", RELEASED, '!' },
+ { 0x83, "@", RELEASED, '@' },
+ { 0x84, "#", RELEASED, '#' },
+ { 0x85, "$", RELEASED, '$' },
+ { 0x86, "%", RELEASED, '%' },
+ { 0x87, "^", RELEASED, '^' },
+ { 0x88, "&", RELEASED, '&' },
+ { 0x89, "*", RELEASED, '*' },
+ { 0x8a, "(", RELEASED, '(' },
+ { 0x8b, ")", RELEASED, ')' },
+ { 0x8c, "_", RELEASED, '_' },
+ { 0x8d, "+", RELEASED, '+' },
+ { 0x8e, "Backspace", RELEASED, 0 },
+ { 0x8f, "Tab", RELEASED, '\t' },
+ { 0x90, "Q", RELEASED, 'Q' },
+ { 0x91, "W", RELEASED, 'W' },
+ { 0x92, "E", RELEASED, 'E' },
+ { 0x93, "R", RELEASED, 'R' },
+ { 0x94, "T", RELEASED, 'T' },
+ { 0x95, "Y", RELEASED, 'Y' },
+ { 0x96, "U", RELEASED, 'U' },
+ { 0x97, "I", RELEASED, 'I' },
+ { 0x98, "O", RELEASED, 'O' },
+ { 0x99, "P", RELEASED, 'P' },
+ { 0x9a, "[", RELEASED, '{' },
+ { 0x9b, "]", RELEASED, '}' },
+ { 0x9c, "Enter", RELEASED, '\n' },
+ { 0x9d, "Control", RELEASED, 0 },
+ { 0x9e, "A", RELEASED, 'A' },
+ { 0x9f, "S", RELEASED, 'S' },
+ { 0xa0, "D", RELEASED, 'D' },
+ { 0xa1, "F", RELEASED, 'F' },
+ { 0xa2, "G", RELEASED, 'G' },
+ { 0xa3, "H", RELEASED, 'H' },
+ { 0xa4, "J", RELEASED, 'J' },
+ { 0xa5, "K", RELEASED, 'K' },
+ { 0xa6, "L", RELEASED, 'L' },
+ { 0xa7, ":", RELEASED, ':' },
+ { 0xa8, "\"", RELEASED, '"' },
+ { 0xa9, "~", RELEASED, '~' },
+ { 0xaa, "Shift", RELEASED, 0 },
+ { 0xab, "\\", RELEASED, '\\' },
+ { 0xac, "Z", RELEASED, 'Z' },
+ { 0xad, "X", RELEASED, 'X' },
+ { 0xae, "C", RELEASED, 'C' },
+ { 0xaf, "V", RELEASED, 'V' },
+ { 0xb0, "B", RELEASED, 'B' },
+ { 0xb1, "N", RELEASED, 'N' },
+ { 0xb2, "M", RELEASED, 'M' },
+ { 0xb3, "<", RELEASED, '<' },
+ { 0xb4, ">", RELEASED, '>' },
+ { 0xb5, "?", RELEASED, '?' },
+ { 0xb6, "Right Shift", RELEASED, 0 },
+ { 0xb7, "* (Keypad)", RELEASED, '*' },
+ { 0xb8, "Alt", RELEASED, 0 },
+ { 0xb9, "Space", RELEASED, ' ' },
+ { 0xba, "CapsLock", RELEASED, 0 },
+ { 0xbb, "F1", RELEASED, 0 },
+ { 0xbc, "F2", RELEASED, 0 },
+ { 0xbd, "F3", RELEASED, 0 },
+ { 0xbe, "F4", RELEASED, 0 },
+ { 0xbf, "F5", RELEASED, 0 },
+ { 0xc0, "F6", RELEASED, 0 },
+ { 0xc1, "F7", RELEASED, 0 },
+ { 0xc2, "F8", RELEASED, 0 },
+ { 0xc3, "F9", RELEASED, 0 },
+ { 0xc4, "F10", RELEASED, 0 },
+ { 0xc5, "NumberLock", RELEASED, 0 },
+ { 0xc6, "ScrollLock", RELEASED, 0 },
+ { 0xc7, "7 (Keypad)", RELEASED, '7' },
+ { 0xc8, "8 (Keypad)", RELEASED, '8' },
+ { 0xc9, "9 (Keypad)", RELEASED, '9' },
+ { 0xca, "- (Keypad)", RELEASED, '-' },
+ { 0xcb, "4 (Keypad)", RELEASED, '4' },
+ { 0xcc, "5 (Keypad)", RELEASED, '5' },
+ { 0xcd, "6 (Keypad)", RELEASED, '6' },
+ { 0xce, "+ (Keypad)", RELEASED, '+' },
+ { 0xcf, "1 (Keypad)", RELEASED, '1' },
+ { 0xd0, "2 (Keypad)", RELEASED, '2' },
+ { 0xd1, "3 (Keypad)", RELEASED, '4' },
+ { 0xd2, "0 (Keypad)", RELEASED, '0' },
+ { 0xd3, ". (Keypad)", RELEASED, '.' },
+ { 0xd7, "F11", RELEASED, 0 },
+ { 0xd8, "F12", RELEASED, 0 },
+ { 0xe010, "Previous Track", PRESSED, 0 },
+ { 0xe019, "Next Track", PRESSED, 0 },
+ { 0xe01c, "Enter (Keypad)", PRESSED, '\n' },
+ { 0xe01d, "Right Control", PRESSED, 0 },
+ { 0xe020, "Mute", PRESSED, 0 },
+ { 0xe021, "Calculator", PRESSED, 0 },
+ { 0xe022, "Play", PRESSED, 0 },
+ { 0xe024, "Stop", PRESSED, 0 },
+ { 0xe02e, "Volume Down", PRESSED, 0 },
+ { 0xe030, "Volume Up", PRESSED, 0 },
+ { 0xe032, "Home", PRESSED, 0 },
+ { 0xe035, "/ (Keypad)", PRESSED, '/' },
+ { 0xe038, "AltGr", PRESSED, 0 },
+ { 0xe047, "Home", PRESSED, 0 },
+ { 0xe048, "Up", PRESSED, 0 },
+ { 0xe049, "Page Up", PRESSED, 0 },
+ { 0xe04b, "Left", PRESSED, 0 },
+ { 0xe04d, "Right", PRESSED, 0 },
+ { 0xe04f, "End", PRESSED, 0 },
+ { 0xe050, "Down", PRESSED, 0 },
+ { 0xe051, "Page Down", PRESSED, 0 },
+ { 0xe052, "Insert", PRESSED, 0 },
+ { 0xe053, "Delete", PRESSED, 0 },
+ { 0xe05b, "Left GUI", PRESSED, 0 },
+ { 0xe05c, "Right GUI", PRESSED, 0 },
+ { 0xe05d, "\"Apps\"", PRESSED, 0 },
+ { 0xe05e, "Power", PRESSED, 0 },
+ { 0xe05f, "Sleep", PRESSED, 0 },
+ { 0xe063, "Wake", PRESSED, 0 },
+ { 0xe065, "Search", PRESSED, 0 },
+ { 0xe066, "Favorites", PRESSED, 0 },
+ { 0xe067, "Refresh", PRESSED, 0 },
+ { 0xe068, "Stop", PRESSED, 0 },
+ { 0xe069, "Forward", PRESSED, 0 },
+ { 0xe06a, "Back", PRESSED, 0 },
+ { 0xe06b, "My Computer", PRESSED, 0 },
+ { 0xe06c, "Email", PRESSED, 0 },
+ { 0xe06d, "Media Select", PRESSED, 0 },
+ { 0xe090, "Previous Track", RELEASED, 0 },
+ { 0xe099, "Next Track", RELEASED, 0 },
+ { 0xe09c, "Enter", RELEASED, '\n' },
+ { 0xe09d, "Right Control", RELEASED, 0 },
+ { 0xe0a0, "Mute", RELEASED, 0 },
+ { 0xe0a1, "Calculator", RELEASED, 0 },
+ { 0xe0a2, "Play", RELEASED, 0 },
+ { 0xe0a4, "Stop", RELEASED, 0 },
+ { 0xe0ae, "Volume Down", RELEASED, 0 },
+ { 0xe0b0, "Volume Up", RELEASED, 0 },
+ { 0xe0b2, "Home", RELEASED, 0 },
+ { 0xe0b5, "/ (Keypad)", RELEASED, '/' },
+ { 0xe0b8, "AltGr", RELEASED, 0 },
+ { 0xe0c7, "Home", RELEASED, 0 },
+ { 0xe0c8, "Up", RELEASED, 0 },
+ { 0xe0c9, "Page Up", RELEASED, 0 },
+ { 0xe0cb, "Left", RELEASED, 0 },
+ { 0xe0cd, "Right", RELEASED, 0 },
+ { 0xe0cf, "End", RELEASED, 0 },
+ { 0xe0d0, "Down", RELEASED, 0 },
+ { 0xe0d1, "Page Down", RELEASED, 0 },
+ { 0xe0d2, "Insert", RELEASED, 0 },
+ { 0xe0d3, "Delete", RELEASED, 0 },
+ { 0xe0db, "Left GUI", RELEASED, 0 },
+ { 0xe0dc, "Right GUI", RELEASED, 0 },
+ { 0xe0dd, "\"Apps\"", RELEASED, 0 },
+ { 0xe0de, "Power", RELEASED, 0 },
+ { 0xe0df, "Sleep", RELEASED, 0 },
+ { 0xe0e3, "Wake", RELEASED, 0 },
+ { 0xe0e5, "Search", RELEASED, 0 },
+ { 0xe0e6, "Favorites", RELEASED, 0 },
+ { 0xe0e7, "Refresh", RELEASED, 0 },
+ { 0xe0e8, "Stop", RELEASED, 0 },
+ { 0xe0e9, "Forward", RELEASED, 0 },
+ { 0xe0ea, "Back", RELEASED, 0 },
+ { 0xe0eb, "My Computer", RELEASED, 0 },
+ { 0xe0ec, "Email", RELEASED, 0 },
+ { 0xe0ed, "Media Select", RELEASED, 0 },
+ { 0xe02ae037, "Print Screen", PRESSED, 0 },
+ { 0xe0b7e0aa, "Print Screen", RELEASED, 0 },
+ { 0xe11d45e19dc5, "Pause", PRESSED, 0 },
+};
+
+struct KeyboardCaptureData find_key_from_code(uint64_t code, char is_shifted, char is_capslocked) {
for (size_t i = 0; i < DICT_SIZE; i++) {
if (KEY_DICTIONARY[i].code == code) {
- return KEY_DICTIONARY[i];
+ if (is_capslocked && is_shifted) {
+ return KEY_DICTIONARY_SHIFTED[i];
+ } else if (is_capslocked && !is_shifted) {
+ if ((code >= 0x2 && code <= 0xd) || (code >= 0x82 && code <= 0x8d)) {
+ return KEY_DICTIONARY[i];
+ } else {
+ return KEY_DICTIONARY_SHIFTED[i];
+ }
+ } else if (!is_capslocked && is_shifted) {
+ return KEY_DICTIONARY_SHIFTED[i];
+ } else {
+ return KEY_DICTIONARY[i];
+ }
}
}
struct KeyboardCaptureData dummy = { 0, "", PRESSED, 0 };
return dummy;
}
-void printk_key_event(struct KeyboardCaptureData key) {
- struct timespec64 now;
- ktime_get_real_ts64(&now);
+void printk_key_event(struct KeyboardCaptureData key, struct timespec64 now) {
char sec = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) % 60;
char min = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 % 60;
char hour = (now.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 / 60 % 24;
- printk(KERN_INFO "%d:%d:%d \"%s\" ", hour, min, sec, key.key_name);
+ printk(KERN_INFO "%02d:%02d:%02d \"%s\" ", hour, min, sec, key.key_name);
if (key.ascii_value) {
- printk(KERN_CONT "(0x%x) ", key.ascii_value);
+ printk(KERN_CONT "(0x%02x) ", key.ascii_value);
}
if (key.state == PRESSED) {
printk(KERN_CONT "PRESSED\n");
@@ -289,24 +551,44 @@ void printk_key_event(struct KeyboardCaptureData key) {
}
}
+int append_node(struct list_head *list, struct KeyboardCaptureData key, struct timespec64 when) {
+ struct linked_list_node *entry;
+ entry = kmalloc(sizeof *entry, GFP_KERNEL);
+ if (!entry)
+ return -ENOMEM;
+ entry->key = key;
+ entry->when = when;
+ calc_node_size(entry);
+ INIT_LIST_HEAD(&entry->list);
+ list_add_tail(&entry->list, list);
+ return 0;
+}
+
irqreturn_t key_logger_isr(int i, void *dummy) {
+ struct logger* key_logger = (struct logger *) dummy;
uint64_t code = inb(0x60);
- struct KeyboardCaptureData key = find_key_from_code(code);
+ mutex_lock(&lock);
+ struct timespec64 now;
+ ktime_get_real_ts64(&now);
+ struct KeyboardCaptureData key = find_key_from_code(code, key_logger->shifted, key_logger->capslocked);
if (!key.code) {
return IRQ_NONE;
}
- mutex_lock(&lock);
- printk_key_event(key);
+ if (key.code == 0x2a || key.code == 0x36) {
+ key_logger->shifted += 1;
+ } else if (key.code == 0xaa || key.code == 0xb6) {
+ key_logger->shifted -= 1;
+ } else if (key.code == 0x3a) {
+ key_logger->capslocked = 1;
+ } else if (key.code == 0xba) {
+ key_logger->capslocked = 0;
+ }
+ if (append_node(&keyboard_log, key, now)) {
+ return IRQ_NONE;
+ }
+ printk_key_event(key, now);
mutex_unlock(&lock);
return IRQ_HANDLED;
}
-//static int keyboard_cb(struct notifier_block *nblock, unsigned long code, void *_param) {
-// struct keyboard_notifier_param *param = _param;
-//
-// printk("code: 0x%lx, down: 0x%x, shift: 0x%x, value: 0x%x\n", code, param->down, param->shift, param->value);
-// return NOTIFY_OK;
-//}
-
-
diff --git a/src/main.c b/src/main.c
index 6a9fcb5..aec100c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,19 +23,14 @@ static struct miscdevice device = {
.mode = 0444,
};
-struct logger {
- char code;
-} key_logger;
-
-
struct mutex lock = __MUTEX_INITIALIZER(lock);
+static struct logger key_logger = { 0, 0 };
static int __init m_init(void) {
struct linked_list_node *ptr, *tmp;
int err = 0;
printk(KERN_INFO "Drivers and Interrupts (init)\n");
-
if (request_irq(1, key_logger_isr, IRQF_SHARED, "i8042", &key_logger)) {
err = -EBUSY;
goto err_free_linked_list;
@@ -48,7 +43,7 @@ static int __init m_init(void) {
return 0;
err_free_keyboard_notifier:
- free_irq(1,&key_logger);
+ free_irq(1, &key_logger);
err_free_linked_list:
list_for_each_entry_safe(ptr, tmp, &keyboard_log, list) {
list_del(&ptr->list);
diff --git a/src/misc_device_fops.c b/src/misc_device_fops.c
index e7d600b..965cd42 100644
--- a/src/misc_device_fops.c
+++ b/src/misc_device_fops.c
@@ -4,6 +4,25 @@
#include "drivers_and_interrupts.h"
+
+// 17:06:43 "d" (0x64) PRESSED
+//
+size_t calc_node_size(struct linked_list_node *node) {
+ size_t size = 14;
+ if (node->key.state == PRESSED) {
+ size += 7;
+ } else {
+ size += 8;
+ }
+ if (node->key.ascii_value) {
+ size += 6;
+ }
+ size += strlen(node->key.key_name);
+ node->size = size;
+ return size;
+}
+
+
ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t count, loff_t *ppos) {
return simple_read_from_buffer(buf, count, ppos, "jrathelo", strlen("jrathelo"));
}
\ No newline at end of file