Skip to content

Commit 31fb295

Browse files
committed
哈希计算会异步进行
1 parent 4d182e7 commit 31fb295

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

main.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
)
3131
)
3232
m_ui.hash_start.clicked.connect(
33-
lambda: m_ui.hash_res_view.setText(
34-
fun_bind.hash_col(m_ui.hash_file_path.text()
35-
)
36-
)
33+
34+
lambda: fun_bind.a3.start()
35+
3736
)
37+
fun_bind.a3.finished.connect(lambda: m_ui.hash_res_view.setText(fun_bind.res3))
3838

3939

4040
def fu_k(e):
@@ -43,8 +43,7 @@ def fu_k(e):
4343
for aa in e.mimeData().text().split('\n'):
4444
if aa != '':
4545
ans.append(aa[8:])
46-
m_ui.hash_res_view.setText(
47-
fun_bind.hash_col(fun_bind.file_tostring(ans)))
46+
fun_bind.files = ans
4847

4948

5049
m_ui.hash_w.dropEvent = fu_k

ui/fun_bind.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
algo_list = [SHA224(), SHA256(), SHA384(), SHA512(), SHA512_224(), SHA512_256(),
1313
BLAKE2b(64), BLAKE2s(32), SHA3_224(), SHA3_256(), SHA3_384(),
1414
SHA3_512(), SHAKE128(16), SHAKE256(32), SM3(), SHA1(), MD5()]
15-
(res, ip_g, min_p, max_p, res2,
16-
start_ip, end_ip, temp_res) = (None, None, None,
17-
None, None, None, None, None,)
15+
(res, ip_g, min_p, max_p, res2, res3,
16+
start_ip, end_ip, temp_res, files) = (None, None, None, None, None,
17+
None, None, None, None, None,)
1818

1919

2020
class T(QThread):
@@ -28,6 +28,18 @@ def run(self):
2828
pass
2929

3030

31+
class T3(QThread):
32+
def run(self):
33+
hash_col()
34+
35+
36+
a = T()
37+
38+
a2 = T2()
39+
40+
a3 = T3()
41+
42+
3143
async def scan_port(ip, port, aa):
3244
async with aa:
3345
global res
@@ -67,11 +79,6 @@ def port_scan_async():
6779
res = f'{type(e).__name__}:{e.__str__()}'
6880

6981

70-
a = T()
71-
72-
a2 = T2()
73-
74-
7582
async def ip_scan2(ip, aa):
7683
async with aa:
7784

@@ -166,45 +173,47 @@ def chose_file():
166173

167174

168175
def file_tostring(r):
169-
res = ''
176+
global files
177+
files = ''
170178
for aa in range(len(r)):
171179
if aa:
172-
res += ','
173-
res += r[aa]
174-
175-
return res
176-
177-
178-
def hash_col(file_list: str):
179-
res = ''
180-
files = file_list.split(sep=',')
181-
print(files)
182-
for bb in files:
180+
files += ','
181+
files += r[aa]
182+
# print(files)
183+
return files
184+
185+
186+
def hash_col():
187+
global files, res3
188+
res3 = ''
189+
# print(files)
190+
if (not files) or files == '':
191+
return
192+
for bb in files.split(sep=','):
183193
try:
184194

185195
cc = QFile(bb)
186-
res += f'{bb} '
196+
res3 += f'{bb} '
187197

188198
if not cc.exists():
189199
raise OSError('文件不存在')
190200
if not QFileInfo(cc).isFile():
191201
raise OSError('需要文件而不是目录')
192202

193203
cc.open(QFile.ReadOnly)
194-
res += f" 文件大小:{cc.size()}字节\n"
204+
res3 += f" 文件大小:{cc.size()}字节\n"
195205
# cc.readAll()
196206
s = QByteArray(cc.readAll())
197207

198208
# print(s.data())
199209
for aa in algo_list:
200210
b = Hash(aa)
201211
b.update(s.data())
202-
res += f'{aa.name}:{b.finalize().hex()}\n'
212+
res3 += f'{aa.name}:{b.finalize().hex()}\n'
203213

204214
except Exception as e:
205-
res += f'{type(e).__name__}:{e.__str__()}\n'
206-
res += '\n'
207-
return res
215+
res3 += f'{type(e).__name__}:{e.__str__()}\n'
216+
res3 += '\n'
208217

209218
# def show_info(title='提示', word=''):
210219
# QMessageBox().information(QWidget(), title, word, QMessageBox.StandardButton.Ok)

0 commit comments

Comments
 (0)