summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-07-21 23:30:15 +0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-07-21 23:30:15 +0200
commitf4698fb41e56383c77afd5ab775c71b07e4da9c8 (patch)
tree5c04d5d19303bedceb5be6157a0916b14ee438c8
inital code stuff
uhm, ehm, i meant "wip" of corse!
-rw-r--r--src/e_mod_main.c185
-rw-r--r--src/keylogger.c101
2 files changed, 286 insertions, 0 deletions
diff --git a/src/e_mod_main.c b/src/e_mod_main.c
new file mode 100644
index 0000000..fd7d5d0
--- /dev/null
+++ b/src/e_mod_main.c
@@ -0,0 +1,185 @@
1#include "e.h"
2
3/* module setup */
4E_API E_Module_Api e_modapi =
5{
6 E_MODULE_API_VERSION,
7 "Presentator helper tool"
8};
9
10static Evas_Object *notify, *bx;
11static Eina_Hash *string_hash;
12static int entry_counter = 0;
13
14static Ecore_Exe *keylogger;
15
16typedef struct {
17 unsigned int ref;
18 char *name;
19 Evas_Object *vis;
20 Ecore_Timer *timer;
21} Entry;
22
23static void
24_del_key(const char *name)
25{
26 Evas_Object *o;
27 Eina_List *list;
28
29 Entry *e = eina_hash_find(string_hash, name);
30
31 //something fishy is going on sometimes, then we dont even have a entry
32 if (!e)
33 {
34 ERR("What the fuck?!");
35 return;
36 }
37
38 //deref the entry
39 e->ref --;
40 //free if null
41 if (e->ref == 0)
42 {
43
44 //if ref is 0 nuke out that entry
45 eina_hash_del_by_key(string_hash, name);
46 entry_counter --;
47 //we need to update the notify visuals depending on the state of the box
48 if (entry_counter <= 0)
49 evas_object_hide(notify);
50 }
51}
52
53static Eina_Bool
54_timed_del(void *data)
55{
56 Entry *e = data;
57 _del_key(e->name);
58
59 return 0;
60}
61
62static void
63_add_key(const char *name)
64{
65 Eina_Strbuf *buf;
66 Evas_Object *o;
67
68 Entry *e = eina_hash_find(string_hash, name);
69
70 //first if we have already displayed that string do not display it again
71 if (e)
72 {
73 e->ref ++;
74 ecore_timer_reset(e->timer);
75 return;
76 }
77
78 //find a considerable text to display
79 buf = eina_strbuf_new();
80 if (entry_counter == 0)
81 eina_strbuf_append_printf(buf, "%s", name);
82 else
83 eina_strbuf_append_printf(buf, " + %s", name);
84
85 //create a label and attach to the box
86 o = elm_label_add(bx);
87 elm_object_text_set(o, eina_strbuf_string_get(buf));
88 evas_object_show(o);
89 elm_box_pack_end(bx, o);
90 evas_object_show(notify);
91
92 //save as entry somewhere
93 e = calloc(1, sizeof(Entry));
94 e->ref = 2; //one for beeing used and one for the minimum time
95 e->vis = o;
96 e->name = strdup(name);
97 entry_counter ++;
98 eina_hash_add(string_hash, name, e);
99 e->timer = ecore_timer_add(0.5, _timed_del, e);
100}
101
102static void
103_entry_free(Entry *e)
104{
105 evas_object_del(e->vis);
106 free(e->name);
107 free(e);
108}
109
110static Eina_Bool
111_msg_from_child_handler(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
112{
113 Ecore_Exe_Event_Data *dataFromProcess = (Ecore_Exe_Event_Data *)event;
114
115 for (int i = 0; dataFromProcess->lines[i].line; ++i)
116 {
117 char first = dataFromProcess->lines[i].line[0];
118 char *key = &dataFromProcess->lines[i].line[1];
119 if (first == ',')
120 {
121 _del_key(key);
122 }
123 else if (first == '.')
124 {
125 _add_key(key);
126 }
127 else
128 {
129 printf("WHAT THE FUCK\n");
130 }
131 }
132 return ECORE_CALLBACK_PASS_ON;
133}
134
135static Eina_Bool
136_msg_from_child_handler_error(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
137{
138
139 printf("ERROR!!!!!!!\n");
140
141 return ECORE_CALLBACK_PASS_ON;
142}
143
144E_API void *
145e_modapi_init(E_Module *m)
146{
147 ecore_init();
148
149 string_hash = eina_hash_string_small_new(_entry_free);
150
151 notify = elm_notify_add(e_comp->elm);
152 elm_notify_allow_events_set(notify, EINA_TRUE);
153 evas_object_layer_set(notify, E_LAYER_POPUP);
154 elm_notify_align_set(notify, 0.5, 1.0);
155
156 bx = elm_box_add(notify);
157 elm_box_horizontal_set(bx, EINA_TRUE);
158 elm_object_content_set(notify, bx);
159 evas_object_show(bx);
160
161 {
162 keylogger = ecore_exe_pipe_run("/usr/local/bin/keylogger", ECORE_EXE_PIPE_WRITE |
163 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
164 ECORE_EXE_PIPE_READ, notify);
165 EINA_SAFETY_ON_NULL_RETURN_VAL(keylogger, NULL);
166 ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _msg_from_child_handler, NULL);
167 ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, _msg_from_child_handler_error, NULL);
168 }
169
170 return m;
171}
172
173E_API int
174e_modapi_shutdown(E_Module *m EINA_UNUSED)
175{
176
177 ecore_shutdown();
178 return 1;
179}
180
181E_API int
182e_modapi_save(E_Module *m EINA_UNUSED)
183{
184 return 1;
185}
diff --git a/src/keylogger.c b/src/keylogger.c
new file mode 100644
index 0000000..dae2177
--- /dev/null
+++ b/src/keylogger.c
@@ -0,0 +1,101 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <X11/Xlib.h>
4#include <X11/Xutil.h>
5#include <X11/extensions/XInput.h>
6
7#define INVALID_EVENT_TYPE -1
8
9static int key_press_type = INVALID_EVENT_TYPE;
10static int key_release_type = INVALID_EVENT_TYPE;
11
12static void
13_press(const char *symbol)
14{
15 fprintf(stdout, ".%s\n", symbol);
16 fflush(stdout);
17}
18
19static void
20_release(const char *symbol)
21{
22 fprintf(stdout, ",%s\n", symbol);
23 fflush(stdout);
24}
25
26int main(void) {
27
28 int i;
29 int number = 0;
30 int run = 1;
31 int default_screen;
32
33 Display * default_display;
34 Window root_window;
35 XEvent e;
36 XDeviceKeyEvent * key;
37 XInputClassInfo *ip;
38 XEventClass event_list[20];
39
40 default_display = XOpenDisplay(getenv("DISPLAY"));
41 default_screen = DefaultScreen(default_display);
42 root_window = RootWindow(default_display, default_screen);
43
44 int num = 0;
45
46 XDeviceInfo *infos = XListInputDevices(default_display, &num);
47
48 //find all devices that are doing input
49 for (int i = 0; i < num; ++i) {
50 XDevice * device;
51
52 if (infos[i].id == IsXKeyboard) continue;
53 if (infos[i].id == IsXPointer) continue;
54 if (infos[i].id == IsXExtensionKeyboard) continue;
55 if (infos[i].id == IsXExtensionPointer) continue;
56
57
58 switch(infos[i].inputclassinfo->class) {
59 case KeyClass:
60 device = XOpenDevice(default_display, infos[i].id);
61
62 if(!device){
63 fprintf(stderr, "unable to open device\n");
64 return 0;
65 }
66
67 DeviceKeyPress(device, key_press_type, event_list[number]); number++;
68 DeviceKeyRelease(device, key_release_type, event_list[number]); number++;
69
70 break;
71 }
72 }
73
74 /* important */
75 if(XSelectExtensionEvent(default_display, root_window, event_list, number)) {
76 fprintf(stderr, "error selecting extended events\n");
77 return 0;
78 }
79
80 while(run) {
81 XNextEvent(default_display, &e);
82 key = (XDeviceKeyEvent *) &e;
83 const char *symbol;
84
85 symbol = XKeysymToString(XKeycodeToKeysym(default_display, key->keycode, 0));
86
87 if (key->type == key_press_type)
88 {
89 _press(symbol);
90 }
91 else if (key->type == key_release_type)
92 {
93 _release(symbol);
94 }
95 }
96
97 /* Close the connection to the X server */
98 XCloseDisplay(default_display);
99
100 return 0;
101}