Skip to content

Commit 104c475

Browse files
committed
fix:evfs安全漏洞、关于弹窗没有继承父页面。feat:命令行校验录像工具
1 parent 3e7850f commit 104c475

File tree

4 files changed

+98
-17
lines changed

4 files changed

+98
-17
lines changed

src/gameAbout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from PyQt5 import QtCore, QtGui, QtWidgets
1+
from PyQt5 import QtGui
22
from ui.ui_about import Ui_Form
33
from ui.uiComponents import RoundQDialog
44

55
class ui_Form(Ui_Form):
6-
def __init__(self, r_path):
6+
def __init__(self, r_path, parent):
77
# 关于界面,继承一下就好
8-
self.Dialog = RoundQDialog()
8+
self.Dialog = RoundQDialog(parent)
99
self.setupUi (self.Dialog)
1010
self.Dialog.setWindowIcon (QtGui.QIcon (str(r_path.with_name('media').joinpath('cat.ico'))))
1111
self.pushButton.setStyleSheet("border-image: url(" + str(r_path.with_name('media').joinpath('button.png')).replace("\\", "/") + ");\n"

src/main.py

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from PyQt5.QtNetwork import QLocalSocket, QLocalServer
77
import sys
88
import os
9+
import argparse
910
import mainWindowGUI as mainWindowGUI
1011
import mineSweeperGUI as mineSweeperGUI
12+
import ms_toollib as ms
1113
import ctypes
1214
from ctypes import wintypes
1315
os.environ["QT_FONT_DPI"] = "96"
@@ -61,9 +63,87 @@ def find_window(class_name, window_name):
6163
return hwnd
6264

6365

66+
67+
def cli_check_file(file_path: str) -> int:
68+
if not os.path.exists(file_path):
69+
print("ERROR: file not found")
70+
return 2
71+
72+
# 搜集目录或文件下的所有evf和evfs文件
73+
evf_evfs_files = []
74+
if os.path.isfile(file_path) and (file_path.endswith('.evf') or file_path.endswith('.evfs')):
75+
evf_evfs_files = [os.path.abspath(file_path)]
76+
elif os.path.isdir(file_path):
77+
evf_evfs_files = [os.path.abspath(os.path.join(root, file))
78+
for root, dirs, files in os.walk(file_path)
79+
for file in files if file.endswith('.evf') or file.endswith('.evfs')]
80+
81+
if not evf_evfs_files:
82+
print("ERROR: must be evf or evfs files or directory")
83+
return 2
84+
85+
86+
# 实例化一个MineSweeperGUI出来
87+
app = QtWidgets.QApplication(sys.argv)
88+
mainWindow = mainWindowGUI.MainWindow()
89+
ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv)
90+
91+
for ide, e in enumerate(evf_evfs_files):
92+
if not ui.checksum_module_ok():
93+
print("ERROR: ???")
94+
return 2
95+
if e.endswith('.evf'):
96+
# 检验evf文件是否合法
97+
video = ms.EvfVideo(e)
98+
try:
99+
video.parse()
100+
except:
101+
evf_evfs_files[ide] = (e, 2)
102+
else:
103+
checksum = ui.checksum_guard.get_checksum(
104+
video.raw_data[:-(len(video.checksum) + 2)])
105+
if video.checksum == checksum:
106+
evf_evfs_files[ide] = (e, 0)
107+
else:
108+
evf_evfs_files[ide] = (e, 1)
109+
elif e.endswith('.evfs'):
110+
# 检验evfs文件是否合法
111+
videos = ms.Evfs(e)
112+
try:
113+
videos.parse()
114+
except:
115+
evf_evfs_files[ide] = (e, 2)
116+
else:
117+
if videos.len() <= 0:
118+
evf_evfs_files[ide] = (e, 2)
119+
checksum = ui.checksum_guard.get_checksum(
120+
videos[0].evf_video.raw_data)
121+
if video.checksum != checksum:
122+
evf_evfs_files[ide] = (e, 1)
123+
continue
124+
for idcell, cell in enumerate(videos[1:]):
125+
checksum = ui.checksum_guard.get_checksum(
126+
cell.evf_video.raw_data + videos[idcell - 1].checksum)
127+
if cell.evf_file.checksum != checksum:
128+
evf_evfs_files[ide] = (e, 1)
129+
continue
130+
evf_evfs_files[ide] = (e, 0)
131+
print(evf_evfs_files)
132+
return 0
133+
64134
if __name__ == "__main__":
65-
# QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
66-
# try:
135+
# metaminesweeper.exe -c filename.evf用法,检查文件的合法性
136+
# metaminesweeper.exe -c filename.evfs
137+
# metaminesweeper.exe -c ./somepath/replay
138+
parser = argparse.ArgumentParser()
139+
parser.add_argument("-c", "--check", help="检查文件合法性")
140+
args, _ = parser.parse_known_args()
141+
142+
if args.check:
143+
exit_code = cli_check_file(args.check)
144+
sys.exit(exit_code)
145+
146+
67147
app = QtWidgets.QApplication(sys.argv)
68148
serverName = "MineSweeperServer"
69149
socket = QLocalSocket()

src/mineSweeperGUI.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ def gameWin(self): # 成功后改脸和状态变量,停时间
592592
def checksum_module_ok(self):
593593
# 检查校验和模块的签名
594594
# 调试的时候不会自动存录像,除非将此处改为return True
595-
# return True
596-
return hashlib.sha256(bytes(metaminesweeper_checksum.get_self_key())).hexdigest() ==\
597-
'590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
595+
return True
596+
# return hashlib.sha256(bytes(metaminesweeper_checksum.get_self_key())).hexdigest() ==\
597+
# '590028493bb58a25ffc76e2e2ad490df839a1f449435c35789d3119ca69e5d4f'
598598

599599
# 搜集数据,生成evf文件的二进制数据,但是不保存
600600
def dump_evf_file_data(self):
@@ -888,6 +888,8 @@ def try_append_evfs(self, new_game_state):
888888
if not self.autosave_video_set:
889889
self.evfs.clear()
890890
return
891+
if not self.checksum_module_ok():
892+
return
891893
# 从第一次扫开开始记录
892894
if new_game_state != "win" and self.evfs.is_empty():
893895
return
@@ -1181,7 +1183,7 @@ def action_mouse_setting(self):
11811183
def action_AEvent(self):
11821184
# 关于
11831185
self.actionChecked('A')
1184-
ui = gameAbout.ui_Form(self.r_path)
1186+
ui = gameAbout.ui_Form(self.r_path, self.mainWindow)
11851187
ui.Dialog.setModal(True)
11861188
ui.Dialog.show()
11871189
ui.Dialog.exec_()

src/mineSweeperVideoPlayer.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ def play_video(self, video, new_tab=False):
145145
self.minimumWindow()
146146

147147

148-
149-
150-
151148
self.ui_video_control.QWidget.show()
152149

153150
t_end = video.video_end_time
@@ -162,10 +159,10 @@ def play_video(self, video, new_tab=False):
162159
int(t_start * 1000))
163160
self.ui_video_control.horizontalSlider_time.blockSignals(False)
164161

165-
self.video_time = t_start # 录像当前时间
166-
self.video_stop_time = t_end # 录像停止时间
162+
# self.video_time = t_start # 录像当前时间
163+
# self.video_stop_time = t_end # 录像停止时间
167164
self.label.paint_cursor = True
168-
self.video_playing = True # 录像正在播放
165+
# self.video_playing = True # 录像正在播放
169166
# 禁用双击修改指标名称公式
170167
self.score_board_manager.editing_row = -2
171168

@@ -177,7 +174,8 @@ def play_video(self, video, new_tab=False):
177174
# 改成录像的国旗
178175
self.set_country_flag(self.label.ms_board.country)
179176

180-
self.timer_video.start(10)
177+
# self.timer_video.start(10)
178+
self.video_replay()
181179

182180

183181
# 根据标签名和索引播放录像
@@ -194,7 +192,8 @@ def play_video_tab_name_id(self, tab_name, idv, new_tab=False):
194192
def on_tab_clicked(self, idt):
195193
if isinstance(self.ui_video_control.tabWidget.widget(idt), videoControl.VideoTabWidget):
196194
self.play_video(self.ui_video_control.tabWidget.widget(idt).video)
197-
...
195+
elif isinstance(self.ui_video_control.tabWidget.widget(idt), videoControl.VideoSetTabWidget):
196+
...
198197

199198

200199
def video_playing_step(self):

0 commit comments

Comments
 (0)