-
Notifications
You must be signed in to change notification settings - Fork 0
/
evb.h
140 lines (117 loc) · 3.5 KB
/
evb.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/jiffies.h>
#define GENERATOR_LENGTH 8
#define MSG_MAX 1024
static int j_temp = 0;
static char keyboard_pool[MSG_MAX];
static char mouse_pool[MSG_MAX];
static char mousemov_pool[MSG_MAX];
static char mousescr_pool[MSG_MAX];
static char tmp_buf[MSG_MAX];
unsigned mask = (1 >> GENERATOR_LENGTH) - 1;
int pow(int base, int exp)
{
if(exp < 0)
return -1;
int result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
if(!strcmp(dev_name(&handle->dev->dev), "input1") && type == 1 && value == 1){
// KEYBOARD POOL
j_temp = jiffies % pow(2, GENERATOR_LENGTH) & mask;
printk(KERN_DEBUG "KEYBOARD %lu\n", j_temp);
sprintf(tmp_buf, "%lu\n", j_temp);
strcat(keyboard_pool, tmp_buf);
strcpy(tmp_buf, "");
}
else if(!strcmp(dev_name(&handle->dev->dev), "input4") && type != 0 && code == 1 && value != 0 && (value % pow(2, GENERATOR_LENGTH) & mask - j_temp > 10)){
// MOUSE MOVEMENTS POOL
j_temp = value % pow(2, GENERATOR_LENGTH) & mask;
printk(KERN_DEBUG "MOUSE MOV %lu\n", j_temp);
sprintf(tmp_buf, "%lu\n", j_temp);
strcat(mousemov_pool, tmp_buf);
strcpy(tmp_buf, "");
}
else if(!strcmp(dev_name(&handle->dev->dev), "input4") && (code == 272 || code == 273 || code == 274) && value == 1){
// MOUSE PRESSES POOL
j_temp = jiffies % pow(2, GENERATOR_LENGTH) & mask;
printk(KERN_DEBUG "MOUSE PRESS %lu\n", j_temp);
sprintf(tmp_buf, "%lu\n", j_temp);
strcat(mouse_pool, tmp_buf);
strcpy(tmp_buf, "");
}
else if(!strcmp(dev_name(&handle->dev->dev), "input3") && value == 1){
// MOUSE SCROLLS POOL
j_temp = jiffies % pow(2, GENERATOR_LENGTH) & mask;
printk(KERN_DEBUG "MOUSE SCROLL %lu\n", j_temp);
sprintf(tmp_buf, "%lu\n", j_temp);
strcat(mousescr_pool, tmp_buf);
strcpy(tmp_buf, "");
}
/*
else {
printk(KERN_DEBUG "Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", dev_name(&handle->dev->dev), type, code, value);
}
*/
}
static int evbug_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 = "evbug";
error = input_register_handle(handle);
if (error)
goto err_free_handle;
error = input_open_device(handle);
if (error)
goto err_unregister_handle;
printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
dev_name(&dev->dev),
dev->name ?: "unknown",
dev->phys ?: "unknown");
return 0;
err_unregister_handle:
input_unregister_handle(handle);
err_free_handle:
kfree(handle);
return error;
}
static void evbug_disconnect(struct input_handle *handle)
{
printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
dev_name(&handle->dev->dev));
input_close_device(handle);
input_unregister_handle(handle);
kfree(handle);
}
static const struct input_device_id evbug_ids[] = {
{ .driver_info = 1 }, /* Matches all devices */
{ }, /* Terminating zero entry */
};
MODULE_DEVICE_TABLE(input, evbug_ids);
static struct input_handler evbug_handler = {
.event = evbug_event,
.connect = evbug_connect,
.disconnect = evbug_disconnect,
.name = "evbug",
.id_table = evbug_ids,
};