-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMouseDecrypt.py
219 lines (179 loc) · 7.91 KB
/
MouseDecrypt.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from PySide6.QtWidgets import (
QApplication,
QPushButton,
QTextBrowser,
QVBoxLayout,
QWidget,
QLabel,
QHBoxLayout,
QRadioButton,
QButtonGroup,
)
from PySide6.QtCore import Signal
import os
from time import sleep
from datetime import datetime
from MouseExtract import extract_data
class MouseDecryptWindow(QWidget):
file_name = Signal(str) # 文件名信号
file_dropped = Signal(str)
def __init__(self):
# global base_path
super(MouseDecryptWindow, self).__init__()
self.layout = QVBoxLayout(self)
# 选择执行的类型
self.type_layout = QHBoxLayout()
self.type_label = QLabel("选择执行类型:")
self.type_layout.addWidget(self.type_label)
self.button_group_type = QButtonGroup(self)
self.select_type1 = QRadioButton("capdata")
self.select_type2 = QRadioButton("usbhid")
self.button_group_type.addButton(self.select_type1)
self.button_group_type.addButton(self.select_type2)
self.type_layout.addWidget(self.select_type1)
self.type_layout.addWidget(self.select_type2)
self.layout.addLayout(self.type_layout)
# 选择想要查看的鼠标按键
self.button_layout = QHBoxLayout()
self.button_label = QLabel("选择想要查看的鼠标按键:")
self.button_layout.addWidget(self.button_label)
self.button_group_button = QButtonGroup(self)
self.select_button1 = QRadioButton("左键")
self.select_button2 = QRadioButton("右键")
self.select_button3 = QRadioButton("无按键")
self.select_button4 = QRadioButton("所有")
self.button_group_button.addButton(self.select_button1)
self.button_group_button.addButton(self.select_button2)
self.button_group_button.addButton(self.select_button3)
self.button_group_button.addButton(self.select_button4)
self.button_layout.addWidget(self.select_button1)
self.button_layout.addWidget(self.select_button2)
self.button_layout.addWidget(self.select_button3)
self.button_layout.addWidget(self.select_button4)
self.layout.addLayout(self.button_layout)
# 执行按钮
self.button_layout = QHBoxLayout()
stylesheet = load_stylesheet("css/style.css")
self.run_button = QPushButton("保存并打开图片")
self.run_button.clicked.connect(self.run_command)
self.run_button.setFixedSize(120, 40) # 设置固定大小
self.button_layout.addWidget(self.run_button)
self.run_button.setStyleSheet(stylesheet)
# 保存图片按钮
self.save_button = QPushButton("仅保存图片")
self.save_button.clicked.connect(self.save_image)
self.save_button.setFixedSize(120, 40) # 设置固定大小
self.button_layout.addWidget(self.save_button)
self.save_button.setStyleSheet(stylesheet)
self.all_button = QPushButton("一键保存全部")
self.all_button.clicked.connect(self.all_command)
self.all_button.setFixedSize(120, 40) # 设置固定大小
self.button_layout.addWidget(self.all_button)
self.all_button.setStyleSheet(stylesheet)
self.layout.addLayout(self.button_layout)
# 输出窗口
self.output = QTextBrowser()
self.layout.addWidget(self.output)
self.setLayout(self.layout)
# 文件名变量
self.file = ""
# 接收文件名信号
self.file_name.connect(self.set_file)
self.setAcceptDrops(True)
def set_file(self, file):
self.file = file
def dragEnterEvent(self, event):
# accept the drag only if it contains files
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dropEvent(self, event):
# get the file URLs (a list of QUrls)
urls = event.mimeData().urls()
# assuming only one file is dropped, get the first URL
url = urls[0]
# get the file path (a string)
filePath = url.toLocalFile()
# 发送文件名信号
self.file_dropped.emit(filePath)
def save_image(self):
self.run_command(from_save_button=True)
def run_command(self, from_save_button=False):
self.output.clear()
# 输出当前时间
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
self.output.append(f"{current_time}")
# 获取当前选中的执行类型和鼠标按键
checked_button_type = self.button_group_type.checkedButton()
checked_button_key = self.button_group_button.checkedButton()
# 检查是否选择了执行类型和鼠标按键以及文件
if checked_button_type:
_type = checked_button_type.text()
else:
_type = None
if checked_button_key:
key = checked_button_key.text()
else:
key = None
if not self.file:
self.output.append("[-] 错误:没有选择文件。")
return
if not _type:
self.output.append("[-] 错误:没有选择执行类型。")
return
if not key:
self.output.append("[-] 错误:没有选择鼠标按键。")
return
self.output.append(f"[+] 执行的类型: {_type}")
self.output.append(f"[+] 选择的鼠标按键: {key}")
self.output.append("[+] 正在执行,若文件较大可能会出现无响应情况,请稍后……")
QApplication.processEvents()
try:
result = extract_data(_type, key, self.file, self.output)
except Exception as e:
self.output.append(f"[-] 执行出错:{e}")
else:
self.output.append("[+] 执行成功。")
self.output.append(
f"[+] 已将转换后的坐标写入{os.path.dirname(__file__)}\output_files\\result.txt,如有需要可自行利用"
)
self.output.append(
f"[+] 已将图片保存至{os.path.dirname(__file__)}\output_files\{_type}_{key}.png"
)
sleep(0.5)
if not os.path.exists("output_files"):
os.mkdir("output_files")
result.savefig(rf"./output_files/{_type}_{key}.png")
if not from_save_button:
result.show()
def all_command(self):
self.output.clear()
# 输出当前时间
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
self.output.append(f"{current_time}")
if not self.file:
self.output.append("[-] 错误:没有选择文件。")
return
self.output.append("[*] 正在执行,若文件较大可能会出现无响应情况,请稍后……")
QApplication.processEvents()
for _type in ["capdata", "usbhid"]:
for key in ["左键", "右键", "无按键", "所有"]:
try:
result = extract_data(_type, key, self.file, self.output)
except Exception as e:
self.output.append(f"[-] 执行出错:{e}")
else:
self.output.append("[+] 执行成功。")
self.output.append(
f"[+] 已将图片保存至{os.path.dirname(__file__)}\output_files\{_type}_{key}.png"
)
QApplication.processEvents()
sleep(0.1)
if not os.path.exists("output_files"):
os.mkdir("output_files")
result.savefig(f"./output_files/{_type}_{key}.png")
result.show()
def load_stylesheet(filename):
with open(filename, "r") as f:
return f.read()