-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc
executable file
·140 lines (116 loc) · 3.13 KB
/
poc
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
#!/usr/bin/env python3
import time
import re
from uinput import UInput
import keys
def char2keys(c):
"""
Keymap for German nodeadkeys layout
"""
result = []
if c.isupper() or c in r'''°!"§$%&/()=?`*'>;:_''':
result.append(keys.KEY_LEFTSHIFT)
if c in r'''²³{[]}\@€~|''':
result.append(keys.KEY_RIGHTALT)
kmap = {
'^': keys.KEY_GRAVE,
'°': keys.KEY_GRAVE,
'!': keys.KEY_1,
'"': keys.KEY_2,
'²': keys.KEY_2,
'§': keys.KEY_3,
'³': keys.KEY_3,
'$': keys.KEY_4,
'%': keys.KEY_5,
'&': keys.KEY_6,
'/': keys.KEY_7,
'{': keys.KEY_7,
'(': keys.KEY_8,
'[': keys.KEY_8,
')': keys.KEY_9,
']': keys.KEY_9,
'=': keys.KEY_0,
'}': keys.KEY_0,
'ß': keys.KEY_MINUS,
'?': keys.KEY_MINUS,
'\\': keys.KEY_MINUS,
'´': keys.KEY_EQUAL,
'`': keys.KEY_EQUAL,
'@': keys.KEY_Q,
'€': keys.KEY_E,
'z': keys.KEY_Y,
'Z': keys.KEY_Y,
'ü': keys.KEY_LEFTBRACE,
'Ü': keys.KEY_LEFTBRACE,
'+': keys.KEY_RIGHTBRACE,
'*': keys.KEY_RIGHTBRACE,
'~': keys.KEY_RIGHTBRACE,
'ö': keys.KEY_SEMICOLON,
'Ö': keys.KEY_SEMICOLON,
'ä': keys.KEY_APOSTROPHE,
'Ä': keys.KEY_APOSTROPHE,
'#': keys.KEY_BACKSLASH,
"'": keys.KEY_BACKSLASH,
'<': keys.KEY_102ND,
'>': keys.KEY_102ND,
'|': keys.KEY_102ND,
'y': keys.KEY_Z,
'Y': keys.KEY_Z,
',': keys.KEY_COMMA,
';': keys.KEY_COMMA,
'.': keys.KEY_DOT,
':': keys.KEY_DOT,
'-': keys.KEY_SLASH,
'_': keys.KEY_SLASH,
' ': keys.KEY_SPACE,
'\n': keys.KEY_ENTER,
}
if re.match('[a-xA-X0-9]', c):
result.append(getattr(keys, 'KEY_' + c.upper()))
elif c in kmap:
result.append(kmap[c])
else:
raise Exception('Unknown char: {}'.format(c))
return result
text = ('# Meine Oma fährt im Hühnerstall Motorrad! #\n' +
'# ^1234567890ß´°!"§$%&/()=?`²³{[]}\\' +
'qwertzuiopü+QWERTZUIOPÜ*@€~' +
'asdfghjklöä#ASDFGHJKLÖÄ\'' +
'<yxcvbnm,.->YXCVBNM;:_ #\n')
# Set of keys we're going to press; they need to be activated.
kset = set()
# List of events
evs = []
# Fill above structs
for c in text:
ev = char2keys(c)
evs.append(ev)
kset |= set(ev)
ui = UInput()
print('UInput API version: {}'.format(ui.version))
# Register each key
for k in kset:
ui.set_keybit(k)
# Create the fake keyboard
ui.dev_setup(0, 0, 0, 0, 'fake keyboard device', 0)
ui.create_dev()
print('Device name: {}'.format(ui.get_sysname(65)))
# Give userspace some time to detect the device
time.sleep(2)
for ev in evs:
# Press keys
for k in ev:
ui.key_press(k)
# Report events
ui.syn()
# Release keys
for k in ev:
ui.key_release(k)
# Report events
ui.syn()
# Some delay so we can watch it.
time.sleep(0.15)
# Give userspace time to read the events before we destroy the keyboard
time.sleep(2)
# Cleanup
ui.destroy_dev()