-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb_keyboard_analyzer.lua
101 lines (91 loc) · 2.62 KB
/
usb_keyboard_analyzer.lua
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
local keys = {
[0x04] = {"a", "A"},
[0x05] = {"b", "B"},
[0x06] = {"c", "C"},
[0x07] = {"d", "D"},
[0x08] = {"e", "E"},
[0x09] = {"f", "F"},
[0x0a] = {"g", "G"},
[0x0b] = {"h", "H"},
[0x0c] = {"i", "I"},
[0x0d] = {"j", "J"},
[0x0e] = {"k", "K"},
[0x0f] = {"l", "L"},
[0x10] = {"m", "M"},
[0x11] = {"n", "N"},
[0x12] = {"o", "O"},
[0x13] = {"p", "P"},
[0x14] = {"q", "Q"},
[0x15] = {"r", "R"},
[0x16] = {"s", "S"},
[0x17] = {"t", "T"},
[0x18] = {"u", "U"},
[0x19] = {"v", "V"},
[0x1a] = {"w", "W"},
[0x1b] = {"x", "X"},
[0x1c] = {"y", "Y"},
[0x1d] = {"z", "Z"},
[0x1e] = {"1", "!"},
[0x1f] = {"2", "@"},
[0x20] = {"3", "#"},
[0x21] = {"4", "$"},
[0x22] = {"5", "%"},
[0x23] = {"6", "^"},
[0x24] = {"7", "&"},
[0x25] = {"8", "*"},
[0x26] = {"9", "("},
[0x27] = {"0", ")"},
[0x28] = {"【Enter】", "【Enter】"},
[0x2a] = {"【Backspace】", "【Backspace】"},
[0x2b] = {"【Tab】", "【Tab】"},
[0x2c] = {" ", " "},
[0x2d] = {"-", "_"},
[0x2e] = {"=", "+"},
[0x2f] = {"[", "{"},
[0x30] = {"]", "}"},
[0x31] = {"\\", "|"},
[0x33] = {";", ":"},
[0x34] = {"'", "\""},
[0x35] = {"`", "~"},
[0x36] = {",", "<"},
[0x37] = {".", ">"},
[0x38] = {"/", "?"},
[0x4f] = {"【→】", "【→】"},
[0x50] = {"【←】", "【←】"},
[0x51] = {"【↓】", "【↓】"},
[0x52] = {"【↑】", "【↑】"}
}
local function main()
window = TextWindow.new("USB Keyboard Analyzer")
listener = Listener.new(nil, "usb", false)
saved_key_count = 0
window:set_atclose(function ()
listener:remove()
end)
function listener.packet(pinfo, tvb, tapinfo)
if tvb:len() ~= 35 then
return
end
if tvb:bytes(22, 1):le_uint() ~= 0x01 then
return
end
current_key_count = 0
for i = 29, 34, 1 do
if tvb:bytes(i, 1):le_uint() ~= 0x00 then
current_key_count = current_key_count + 1
end
end
if saved_key_count < current_key_count then
modifier = tvb:bytes(27, 1):le_uint()
key_code = tvb:bytes(28 + current_key_count, 1):le_uint()
if (modifier & (1 << 1)) == 0x02 or (modifier & (1 << 5)) == 0x20 then
window:append(keys[key_code][2])
else
window:append(keys[key_code][1])
end
end
saved_key_count = current_key_count
end
retap_packets()
end
register_menu("USB Keyboard Analyzer", main, MENU_TOOLS_UNSORTED)