-
Notifications
You must be signed in to change notification settings - Fork 2
/
MouseExtract.py
77 lines (68 loc) · 2.18 KB
/
MouseExtract.py
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
import os
import matplotlib.pyplot as plt
def extract_data(types, choise, filename, output):
posX, posY = 0, 0
X, Y = [], []
type_dicts = {"capdata": "usb.capdata", "usbhid": "usbhid.data"}
mytype = type_dicts[types]
choise_dicts = {"左键": "L", "右键": "R", "无按键": "N", "所有": "ALL"}
mychoise = choise_dicts[choise]
f = os.popen(f'tshark.exe -r "{filename}" -T fields -e {mytype} > ./usb.dat', "r")
d = f.read()
output.append(d)
f.close()
data = []
result = open("./result.txt", "w")
with open("./usb.dat", "r") as f:
for line in f:
data.append(line[0:-1])
for i in data:
Bytes = bytes.fromhex(i)
if len(Bytes) == 8:
horizontal = 2
vertical = 4
key = 1
elif len(Bytes) == 6:
horizontal = 2
vertical = 3
key = 1
elif len(Bytes) == 4:
horizontal = 1
vertical = 2
key = 0
else:
continue
offsetX = Bytes[horizontal]
offsetY = Bytes[vertical]
if offsetX > 127:
offsetX -= 256
if offsetY > 127:
offsetY -= 256
posX += offsetX
posY += offsetY
if Bytes[key] == 1:
if mychoise == "L":
X.append(posX)
Y.append(-posY)
result.write(str(posX) + " " + str(-posY) + "\n")
elif Bytes[key] == 2:
if mychoise == "R":
X.append(posX)
Y.append(-posY)
result.write(str(posX) + " " + str(-posY) + "\n")
elif Bytes[key] == 0:
if mychoise == "N":
X.append(posX)
Y.append(-posY)
result.write(str(posX) + " " + str(-posY) + "\n")
else:
pass
if mychoise == "ALL":
X.append(posX)
Y.append(-posY)
result.write(str(posX) + " " + str(-posY) + "\n")
result.close()
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.scatter(X, Y, s=0.5, c="r", marker="o")
return plt