-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathPYAS.py
1738 lines (1621 loc) · 88 KB
/
PYAS.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os, gc, sys, time, json
import ctypes, ctypes.wintypes
import requests, msvcrt, pyperclip
from PYAS_Engine import YRScan, DLScan
from PYAS_Suffixes import file_types
from PYAS_Language import translate_dict
from PYAS_Interface import Ui_MainWindow
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from subprocess import *
from threading import *
class PROCESSENTRY32(ctypes.Structure): # 初始化定義
_fields_ = [
("dwSize", ctypes.wintypes.DWORD),
("cntUsage", ctypes.wintypes.DWORD),
("th32ProcessID", ctypes.wintypes.DWORD),
("th32DefaultHeapID", ctypes.wintypes.LPVOID),
("th32ModuleID", ctypes.wintypes.DWORD),
("cntThreads", ctypes.wintypes.DWORD),
("th32ParentProcessID", ctypes.wintypes.DWORD),
("dwFlags", ctypes.wintypes.DWORD),
("szExeFile", ctypes.wintypes.CHAR * 260)]
class MIB_TCPROW_OWNER_PID(ctypes.Structure):
_fields_ = [
("dwState", ctypes.wintypes.DWORD),
("dwLocalAddr", ctypes.wintypes.DWORD),
("dwLocalPort", ctypes.wintypes.DWORD),
("dwRemoteAddr", ctypes.wintypes.DWORD),
("dwRemotePort", ctypes.wintypes.DWORD),
("dwOwningPid", ctypes.wintypes.DWORD)]
class MIB_TCPTABLE_OWNER_PID(ctypes.Structure):
_fields_ = [
("dwNumEntries", ctypes.wintypes.DWORD),
("table", MIB_TCPROW_OWNER_PID * 1)]
class FILE_NOTIFY_INFORMATION(ctypes.Structure):
_fields_ = [
("NextEntryOffset", ctypes.wintypes.DWORD),
("Action", ctypes.wintypes.DWORD),
("FileNameLength", ctypes.wintypes.DWORD),
("FileName", ctypes.wintypes.WCHAR * 1024)]
class MainWindow_Controller(QMainWindow): # 初始化主程式
def __init__(self): # 初始化調用
super(MainWindow_Controller, self).__init__()
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowFlags(Qt.FramelessWindowHint)
self.init_config_pyas() # 初始化程式
def init_config_pyas(self):
self.init_config_vars() # 初始化變數
self.init_config_path() # 初始化路徑
self.init_config_read() # 初始化配置
self.init_config_wdll() # 初始化系統
self.init_config_boot() # 初始化引導
self.init_config_list() # 初始化列表
self.init_config_data() # 初始化引擎
self.init_config_icon() # 初始化圖標
self.init_config_qtui() # 初始化介面
self.init_config_color() # 初始化顏色
self.init_config_conn() # 初始化交互
self.init_config_lang() # 初始化語言
self.init_config_func() # 初始化功能
self.init_config_done() # 初始化完畢
self.init_config_theme() # 初始化主題
def init_config_vars(self): # 初始化變數
self.pyae_version = "AI Engine"
self.pyas_version = "3.3.0"
self.mbr_value = None
self.track_proc = None
self.first_startup = 1
self.pyas_opacity = 0
self.gc_collect = 0
self.block_window = 0
self.total_scan = 0
self.scan_time = 0
self.virus_lock = {}
self.virus_list_ui = []
self.Process_quantity = 0
self.Process_list_all_pid = []
self.default_json = {
"language_ui": "en_US", # "en_US", "zh_TW", "zh_CN"
"theme_color": "White", # "Solid color" or "./Theme/Path"
"product_key": "None", # "None" or "XXXXX-X..."
"service_url": "None", # "None" or "http://..."
"proc_protect": 1, # "0" (Close), "1" (Open)
"file_protect": 1, # "0" (Close), "1" (Open)
"sys_protect": 1, # "0" (Close), "1" (Open)
"net_protect": 1, # "0" (Close), "1" (Open)
"cus_protect": 0, # "0" (Close), "1" (Open)
"sensitivity": 0, # "0" (Medium), "1" (High)
"extend_mode": 0, # "0" (False), "1" (True)
"white_lists": [],
"block_lists": []}
self.pass_windows = [
{'': ''}, {'PYAS': 'Qt5152QWindowIcon'},
{'': 'Shell_TrayWnd'}, {'': 'WorkerW'}]
def init_config_path(self): # 初始化路徑
try:
self.path_conf = r"C:/ProgramData/PYAS"
self.path_pyas = sys.argv[0].replace("\\", "/")
self.path_dirs = os.path.dirname(self.path_pyas)
self.file_conf = os.path.join(self.path_conf, "PYAS.json")
self.path_model = os.path.join(self.path_dirs, "Engine/Model")
self.path_rules = os.path.join(self.path_dirs, "Engine/Rules")
self.path_driver = os.path.join(self.path_dirs, "Driver/Protect")
except Exception as e:
print(e)
def reset_options(self): # 重置所有設定
if self.question_event("您確定要重置所有設定嗎?"):
self.clean_function()
self.config_json = self.default_json
self.init_config_write(self.config_json)
self.init_config_pyas()
def clean_function(self): # 清理運行函數
self.first_startup = 1
self.block_window = 0
self.config_json["proc_protect"] = 0
self.config_json["file_protect"] = 0
self.config_json["sys_protect"] = 0
self.config_json["net_protect"] = 0
self.virus_scan_break()
self.protect_drv_init()
self.gc_collect = 0
def init_config_read(self): # 初始化配置
try:
self.config_json = {}
if not os.path.exists(self.path_conf):
os.makedirs(self.path_conf)
if not os.path.exists(self.file_conf):
self.init_config_write(self.config_json)
with open(self.file_conf, "r") as f:
self.config_json = json.load(f)
self.config_json["language_ui"] = self.config_json.get("language_ui", "en_US")
self.config_json["theme_color"] = self.config_json.get("theme_color", "White")
self.config_json["product_key"] = self.config_json.get("product_key", "None")
self.config_json["service_url"] = self.config_json.get("service_url", "None")
self.config_json["proc_protect"] = self.config_json.get("proc_protect", 1)
self.config_json["file_protect"] = self.config_json.get("file_protect", 1)
self.config_json["sys_protect"] = self.config_json.get("sys_protect", 1)
self.config_json["net_protect"] = self.config_json.get("net_protect", 1)
self.config_json["sensitivity"] = self.config_json.get("sensitivity", 0)
self.config_json["extend_mode"] = self.config_json.get("extend_mode", 0)
self.config_json["white_lists"] = self.config_json.get("white_lists", [])
self.config_json["block_lists"] = self.config_json.get("block_lists", [])
except Exception as e:
print(e)
def init_config_write(self, config): # 寫入配置
try:
with open(self.file_conf, "w") as f:
f.write(json.dumps(config, indent=4, ensure_ascii=False))
except Exception as e:
print(e)
def init_config_wdll(self): # 初始化系統
try:
self.ntdll = ctypes.WinDLL('ntdll', use_last_error=True)
self.psapi = ctypes.WinDLL('Psapi', use_last_error=True)
self.user32 = ctypes.WinDLL('user32', use_last_error=True)
self.kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
self.advapi32 = ctypes.WinDLL('advapi32', use_last_error=True)
self.iphlpapi = ctypes.WinDLL('iphlpapi', use_last_error=True)
except Exception as e:
print(e)
def init_config_boot(self): # 初始化引導
try:
with open(r"\\.\PhysicalDrive0", "r+b") as f:
self.mbr_value = f.read(512)
if self.mbr_value[510:512] != b'\x55\xAA':
self.mbr_value = None
except Exception as e:
print(e)
def init_config_list(self): # 初始化列表
try:
self.exist_process = self.get_process_list()
self.exist_connections = self.get_connections_list()
except Exception as e:
print(e)
def init_config_data(self): # 初始化引擎
try:
self.model = DLScan()
for root, dirs, files in os.walk(self.path_model):
for file in files:
file_path = os.path.join(root, file)
self.model.load_model(file_path)
except Exception as e:
print(e)
try:
self.rules = YRScan()
for root, dirs, files in os.walk(self.path_rules):
for file in files:
file_path = os.path.join(root, file)
self.rules.load_rules(file_path)
except Exception as e:
print(e)
def init_config_icon(self): # 初始化圖標
self.tray_icon = QSystemTrayIcon(self)
self.tray_icon.activated.connect(self.init_config_show)
self.tray_icon.setIcon(QFileIconProvider().icon(QFileInfo(self.path_pyas)))
self.tray_icon.show()
def init_config_qtui(self): # 初始化介面
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.Process_sim = QStringListModel()
self.Process_Timer = QTimer()
self.Process_Timer.timeout.connect(self.process_list)
self.ui.widget_2.lower()
self.ui.Navigation_Bar.raise_()
self.ui.Window_widget.raise_()
self.ui.Virus_Scan_choose_widget.raise_()
self.effect_shadow = QGraphicsDropShadowEffect(self)
self.effect_shadow.setOffset(0,0)
self.effect_shadow.setBlurRadius(10)
self.effect_shadow.setColor(Qt.gray)
self.ui.widget_2.setGraphicsEffect(self.effect_shadow)
self.effect_shadow2 = QGraphicsDropShadowEffect(self)
self.effect_shadow2.setOffset(0,0)
self.effect_shadow2.setBlurRadius(10)
self.effect_shadow2.setColor(Qt.gray)
self.ui.Navigation_Bar.setGraphicsEffect(self.effect_shadow2)
self.effect_shadow3 = QGraphicsDropShadowEffect(self)
self.effect_shadow3.setOffset(0,0)
self.effect_shadow3.setBlurRadius(7)
self.effect_shadow3.setColor(Qt.gray)
self.ui.Window_widget.setGraphicsEffect(self.effect_shadow3)
self.ui.Virus_Scan_choose_widget.hide()
self.ui.Virus_Scan_widget.hide()
self.ui.Tools_widget.hide()
self.ui.Protection_widget.hide()
self.ui.Virus_Scan_Solve_Button.hide()
self.ui.Virus_Scan_Break_Button.hide()
self.ui.Process_widget.hide()
self.ui.Setting_widget.hide()
self.ui.About_widget.hide()
self.ui.State_output.style().polish(self.ui.State_output.verticalScrollBar())
self.ui.Virus_Scan_output.style().polish(self.ui.Virus_Scan_output.verticalScrollBar())
self.ui.License_terms.setText('''MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.''')
def init_config_conn(self): # 初始化交互
self.ui.Close_Button.clicked.connect(self.close)
self.ui.Minimize_Button.clicked.connect(self.showMinimized)
self.ui.Menu_Button.clicked.connect(self.show_menu)
self.ui.State_Button.clicked.connect(self.change_state_widget)
self.ui.Tools_Button.clicked.connect(self.change_tools_widget)
self.ui.Virus_Scan_Button.clicked.connect(self.change_scan_widget)
self.ui.Protection_Button.clicked.connect(self.change_protect_widget)
self.ui.Setting_Button.clicked.connect(self.change_setting_widget)
self.ui.Virus_Scan_output.setContextMenuPolicy(Qt.CustomContextMenu)
self.ui.Virus_Scan_output.customContextMenuRequested.connect(self.Virus_Scan_output_menu)
self.ui.Virus_Scan_Solve_Button.clicked.connect(self.virus_solve)
self.ui.Virus_Scan_choose_Button.clicked.connect(self.virus_scan_menu)
self.ui.Virus_Scan_Break_Button.clicked.connect(self.virus_scan_break)
self.ui.File_Scan_Button.clicked.connect(self.file_scan)
self.ui.Path_Scan_Button.clicked.connect(self.path_scan)
self.ui.Disk_Scan_Button.clicked.connect(self.disk_scan)
self.ui.System_Process_Manage_Button.clicked.connect(lambda:self.change_tools(self.ui.Process_widget))
self.ui.Repair_System_Files_Button.clicked.connect(self.repair_system)
self.ui.Clean_System_Files_Button.clicked.connect(self.clean_system)
self.ui.Window_Block_Button.clicked.connect(self.add_software_window)
self.ui.Window_Block_Button_2.clicked.connect(self.remove_software_window)
self.ui.Repair_System_Network_Button.clicked.connect(self.repair_network)
self.ui.Reset_Options_Button.clicked.connect(self.reset_options)
self.ui.Process_list.setContextMenuPolicy(Qt.CustomContextMenu)
self.ui.Process_list.customContextMenuRequested.connect(self.process_list_menu)
self.ui.Protection_switch_Button.clicked.connect(self.protect_proc_init)
self.ui.Protection_switch_Button_2.clicked.connect(self.protect_file_init)
self.ui.Protection_switch_Button_3.clicked.connect(self.protect_sys_init)
self.ui.Protection_switch_Button_4.clicked.connect(self.protect_drv_init)
self.ui.Protection_switch_Button_5.clicked.connect(self.protect_net_init)
self.ui.Protection_switch_Button_8.clicked.connect(self.protect_cus_init)
self.ui.high_sensitivity_switch_Button.clicked.connect(self.change_sensitive)
self.ui.extension_kit_switch_Button.clicked.connect(self.extension_kit)
self.ui.cloud_services_switch_Button.clicked.connect(self.cloud_services)
self.ui.Add_White_list_Button.clicked.connect(self.add_white_list)
self.ui.Add_White_list_Button_3.clicked.connect(self.remove_white_list)
self.ui.Language_Traditional_Chinese.clicked.connect(self.init_change_lang)
self.ui.Language_Simplified_Chinese.clicked.connect(self.init_change_lang)
self.ui.Language_English.clicked.connect(self.init_change_lang)
self.ui.Theme_White.clicked.connect(self.init_change_theme)
self.ui.Theme_Customize.clicked.connect(self.init_change_theme)
self.ui.Theme_Green.clicked.connect(self.init_change_theme)
self.ui.Theme_Yellow.clicked.connect(self.init_change_theme)
self.ui.Theme_Blue.clicked.connect(self.init_change_theme)
self.ui.Theme_Red.clicked.connect(self.init_change_theme)
def init_config_lang(self): # 初始化語言
try:
if self.config_json["language_ui"] == "zh_TW":
self.ui.Language_Traditional_Chinese.setChecked(True)
elif self.config_json["language_ui"] == "zh_CN":
self.ui.Language_Simplified_Chinese.setChecked(True)
elif self.config_json["language_ui"] == "en_US":
self.ui.Language_English.setChecked(True)
self.init_change_text()
except Exception as e:
print(e)
def init_change_lang(self): # 變更語言
try:
if self.ui.Language_Traditional_Chinese.isChecked():
self.config_json["language_ui"] = "zh_TW"
elif self.ui.Language_Simplified_Chinese.isChecked():
self.config_json["language_ui"] = "zh_CN"
elif self.ui.Language_English.isChecked():
self.config_json["language_ui"] = "en_US"
self.init_change_text()
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def trans(self, text):
for k, v in translate_dict.get(self.config_json["language_ui"], translate_dict).items():
text = text.replace(str(k), str(v))
return text
def init_change_text(self): # 變更文字
self.ui.State_title.setText(self.trans("此裝置已受到防護"))
self.ui.Window_title.setText(self.trans(f"PYAS Security"))
self.ui.PYAS_CopyRight.setText(self.trans(f"Copyright© 2020-{max(int(time.strftime('%Y')), 2020)} PYAS Security"))
self.ui.Virus_Scan_title.setText(self.trans("病毒掃描"))
self.ui.Virus_Scan_text.setText(self.trans("請選擇掃描方式"))
self.ui.Virus_Scan_choose_Button.setText(self.trans("病毒掃描"))
self.ui.File_Scan_Button.setText(self.trans("檔案掃描"))
self.ui.Path_Scan_Button.setText(self.trans("路徑掃描"))
self.ui.Disk_Scan_Button.setText(self.trans("全盤掃描"))
self.ui.Virus_Scan_Solve_Button.setText(self.trans("立即刪除"))
self.ui.Virus_Scan_Break_Button.setText(self.trans("停止掃描"))
self.ui.Process_Total_title.setText(self.trans("進程總數:"))
self.ui.Protection_title.setText(self.trans("進程防護"))
self.ui.Protection_illustrate.setText(self.trans("啟用此選項可以攔截進程病毒"))
self.ui.Protection_switch_Button.setText(self.trans(self.ui.Protection_switch_Button.text()))
self.ui.Protection_title_2.setText(self.trans("檔案防護"))
self.ui.Protection_illustrate_2.setText(self.trans("啟用此選項可以監控檔案變更"))
self.ui.Protection_switch_Button_2.setText(self.trans(self.ui.Protection_switch_Button_2.text()))
self.ui.Protection_title_3.setText(self.trans("系統防護"))
self.ui.Protection_illustrate_3.setText(self.trans("啟用此選項可以修復系統項目"))
self.ui.Protection_switch_Button_3.setText(self.trans(self.ui.Protection_switch_Button_3.text()))
self.ui.Protection_title_4.setText(self.trans("驅動防護"))
self.ui.Protection_illustrate_4.setText(self.trans("啟用此選項可以增強自身防護"))
self.ui.Protection_switch_Button_4.setText(self.trans(self.ui.Protection_switch_Button_4.text()))
self.ui.Protection_title_5.setText(self.trans("網路防護"))
self.ui.Protection_illustrate_5.setText(self.trans("啟用此選項可以監控網路通訊"))
self.ui.Protection_switch_Button_5.setText(self.trans(self.ui.Protection_switch_Button_5.text()))
self.ui.Protection_title_8.setText(self.trans("自訂防護"))
self.ui.Protection_illustrate_8.setText(self.trans("啟用此選項可以選擇自訂防護"))
self.ui.Protection_switch_Button_8.setText(self.trans(self.ui.Protection_switch_Button_8.text()))
self.ui.State_log.setText(self.trans("日誌:"))
self.ui.System_Process_Manage_title.setText(self.trans("進程管理"))
self.ui.System_Process_Manage_illustrate.setText(self.trans("此選項可以實時查看系統進程"))
self.ui.System_Process_Manage_Button.setText(self.trans("選擇"))
self.ui.Clean_System_Files_title.setText(self.trans("垃圾清理"))
self.ui.Clean_System_Files_illustrate.setText(self.trans("此選項可以清理暫存檔案"))
self.ui.Clean_System_Files_Button.setText(self.trans("選擇"))
self.ui.Repair_System_Files_title.setText(self.trans("系統修復"))
self.ui.Repair_System_Files_illustrate.setText(self.trans("此選項可以修復系統註冊表"))
self.ui.Repair_System_Files_Button.setText(self.trans("選擇"))
self.ui.Repair_System_Network_title.setText(self.trans("網路修復"))
self.ui.Repair_System_Network_illustrate.setText(self.trans("此選項可以重置系統網路連接"))
self.ui.Repair_System_Network_Button.setText(self.trans("選擇"))
self.ui.Reset_Options_title.setText(self.trans("重置選項"))
self.ui.Reset_Options_illustrate.setText(self.trans("此選項可以重置所有設定選項"))
self.ui.Reset_Options_Button.setText(self.trans("選擇"))
self.ui.Window_Block_title.setText(self.trans("彈窗攔截"))
self.ui.Window_Block_illustrate.setText(self.trans("此選項可以選擇指定窗口並攔截"))
self.ui.Window_Block_Button.setText(self.trans("增加"))
self.ui.Window_Block_Button_2.setText(self.trans("移除"))
self.ui.PYAS_Version.setText(self.trans(f"PYAS Security V{self.pyas_version} ({self.pyae_version})"))
self.ui.GUI_Made_title.setText(self.trans("介面製作:"))
self.ui.GUI_Made_Name.setText(self.trans("mtkiao"))
self.ui.Core_Made_title.setText(self.trans("核心製作:"))
self.ui.Core_Made_Name.setText(self.trans("87owo"))
self.ui.Testers_title.setText(self.trans("特別感謝:"))
self.ui.Testers_Name.setText(self.trans("0sha0"))
self.ui.PYAS_URL_title.setText(self.trans("官方網站:"))
self.ui.PYAS_URL.setText(self.trans("<html><head/><body><p><a href=\"https://github.com/87owo/PYAS\"><span style=\" text-decoration: underline; color:#000000;\">https://github.com/87owo/PYAS</span></a></p></body></html>"))
self.ui.high_sensitivity_title.setText(self.trans("高靈敏度模式"))
self.ui.high_sensitivity_illustrate.setText(self.trans("啟用此選項可以提高掃描引擎靈敏度"))
self.ui.high_sensitivity_switch_Button.setText(self.trans(self.ui.high_sensitivity_switch_Button.text()))
self.ui.extension_kit_title.setText(self.trans("擴展掃描引擎"))
self.ui.extension_kit_illustrate.setText(self.trans("啟用此選項可以使用第三方擴展套件"))
self.ui.extension_kit_switch_Button.setText(self.trans(self.ui.extension_kit_switch_Button.text()))
self.ui.cloud_services_title.setText(self.trans("雲端掃描服務"))
self.ui.cloud_services_illustrate.setText(self.trans("啟用此選項可以連接雲端掃描服務"))
self.ui.cloud_services_switch_Button.setText(self.trans(self.ui.cloud_services_switch_Button.text()))
self.ui.Add_White_list_title.setText(self.trans("增加到白名單"))
self.ui.Add_White_list_illustrate.setText(self.trans("此選項可以選擇檔案並增加到白名單"))
self.ui.Add_White_list_Button.setText(self.trans("增加"))
self.ui.Add_White_list_Button_3.setText(self.trans("移除"))
self.ui.Theme_title.setText(self.trans("顯色主題"))
self.ui.Theme_illustrate.setText(self.trans("請選擇主題"))
self.ui.Theme_Customize.setText(self.trans("自訂主題"))
self.ui.Theme_White.setText(self.trans("白色主題"))
self.ui.Theme_Yellow.setText(self.trans("黃色主題"))
self.ui.Theme_Red.setText(self.trans("紅色主題"))
self.ui.Theme_Green.setText(self.trans("綠色主題"))
self.ui.Theme_Blue.setText(self.trans("藍色主題"))
self.ui.Language_title.setText(self.trans("顯示語言"))
self.ui.Language_illustrate.setText(self.trans("請選擇語言"))
self.ui.License_terms_title.setText(self.trans("許可條款:"))
def init_config_color(self):
self.config_theme = {
"White": {"color": "White", "icon": ":/icon/Check.png",
"button_on": """QPushButton{border:none;
background-color:rgb(200,250,200);border-radius: 10px;}
QPushButton:hover{background-color:rgb(210,250,210);}""",
"button_off": """QPushButton{border:none;
background-color:rgb(230,230,230);border-radius: 10px;}
QPushButton:hover{background-color:rgb(220,220,220);}""",
"widget_style": "background-color:rgb(255,255,255);",
"window_style": "background-color:rgb(245,245,245);",
"navigation_style": "background-color:rgb(235,235,235);"},#
"Red": {"color": "Red", "icon": ":/icon/Check.png",
"button_on": """QPushButton{border:none;
background-color:rgb(250,200,200);border-radius: 10px;}
QPushButton:hover{background-color:rgb(250,210,210);}""",
"button_off": """QPushButton{border:none;
background-color:rgb(250,220,220);border-radius: 10px;}
QPushButton:hover{background-color:rgb(250,210,210);}""",
"widget_style": "background-color:rgb(250,240,240);",
"window_style": "background-color:rgb(250,230,230);",
"navigation_style": "background-color:rgb(250,220,220);"},#
"Green": {"color": "Green", "icon": ":/icon/Check.png",
"button_on": """QPushButton{border:none;
background-color:rgb(200,250,200);border-radius: 10px;}
QPushButton:hover{background-color:rgb(210,250,210);}""",
"button_off": """QPushButton{border:none;
background-color:rgb(220,250,220);border-radius: 10px;}
QPushButton:hover{background-color:rgb(210,250,210);}""",
"widget_style": "background-color:rgb(240,250,240);",
"window_style": "background-color:rgb(230,250,230);",
"navigation_style": "background-color:rgb(220,250,220);"},#
"Blue": {"color": "Blue", "icon": ":/icon/Check.png",
"button_on": """QPushButton{border:none;
background-color:rgb(200,250,250);border-radius: 10px;}
QPushButton:hover{background-color:rgb(210,250,250);}""",
"button_off": """QPushButton{border:none;
background-color:rgb(220,250,250);border-radius: 10px;}
QPushButton:hover{background-color:rgb(210,250,250);}""",
"widget_style": "background-color:rgb(240,250,250);",
"window_style": "background-color:rgb(230,250,250);",
"navigation_style": "background-color:rgb(220,250,250);"},#
"Yellow": {"color": "Yellow", "icon": ":/icon/Check.png",
"button_on": """QPushButton{border:none;
background-color:rgb(250,250,200);border-radius: 10px;}
QPushButton:hover{background-color:rgb(250,250,210);}""",
"button_off": """QPushButton{border:none;
background-color:rgb(250,250,220);border-radius: 10px;}
QPushButton:hover{background-color:rgb(250,250,210);}""",
"widget_style": "background-color:rgb(250,250,240);",
"window_style": "background-color:rgb(250,250,230);",
"navigation_style": "background-color:rgb(250,250,220);"}}
self.init_change_color()
def init_config_theme(self): # 初始化主題
try:
if self.config_json["theme_color"] == "White":
self.ui.Theme_White.setChecked(True)
elif self.config_json["theme_color"] == "Red":
self.ui.Theme_Red.setChecked(True)
elif self.config_json["theme_color"] == "Green":
self.ui.Theme_Green.setChecked(True)
elif self.config_json["theme_color"] == "Yellow":
self.ui.Theme_Yellow.setChecked(True)
elif self.config_json["theme_color"] == "Blue":
self.ui.Theme_Blue.setChecked(True)
elif os.path.exists(self.config_json["theme_color"]):
self.ui.Theme_Customize.setChecked(True)
self.init_change_color()
except Exception as e:
print(e)
def init_change_theme(self): # 變更主題
try:
if self.ui.Theme_White.isChecked():
self.config_json["theme_color"] = "White"
elif self.ui.Theme_Red.isChecked():
self.config_json["theme_color"] = "Red"
elif self.ui.Theme_Green.isChecked():
self.config_json["theme_color"] = "Green"
elif self.ui.Theme_Blue.isChecked():
self.config_json["theme_color"] = "Blue"
elif self.ui.Theme_Yellow.isChecked():
self.config_json["theme_color"] = "Yellow"
elif self.ui.Theme_Customize.isChecked():
self.config_json["theme_color"] = "Customize"
self.init_change_color()
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def init_change_color(self): # 變更色彩
try:
if self.config_json["theme_color"] in self.config_theme:
self.theme = self.config_theme[self.config_json["theme_color"]]
self.config_json["theme_color"] = self.theme["color"]
self.ui.State_icon.setPixmap(QPixmap(self.theme["icon"]))
else:
if not os.path.exists(os.path.join(self.config_json["theme_color"], "Color.json")):
path = str(QFileDialog.getExistingDirectory(self, self.trans("自訂主題"), ""))
if path and os.path.exists(os.path.join(path, "Color.json")):
self.config_json["theme_color"] = path
with open(os.path.join(self.config_json["theme_color"], "Color.json"), "r") as f:
self.theme = json.load(f)
icon_path = os.path.join(self.config_json["theme_color"], self.theme["icon"])
self.ui.State_icon.setPixmap(QPixmap(icon_path))
self.ui.Window_widget.setStyleSheet(self.theme["window_style"])
self.ui.Navigation_Bar.setStyleSheet(self.theme["navigation_style"])
self.ui.State_widget.setStyleSheet(self.theme["widget_style"])
self.ui.Virus_Scan_widget.setStyleSheet(self.theme["widget_style"])
self.ui.Tools_widget.setStyleSheet(self.theme["widget_style"])
self.ui.Process_widget.setStyleSheet(self.theme["widget_style"])
self.ui.Protection_widget.setStyleSheet(self.theme["widget_style"])
self.ui.Setting_widget.setStyleSheet(self.theme["widget_style"])
self.ui.About_widget.setStyleSheet(self.theme["widget_style"])
self.ui.widget_2.setStyleSheet(self.theme["widget_style"])
self.ui.Virus_Scan_choose_Button.setStyleSheet(self.theme["button_on"])
self.ui.Add_White_list_Button.setStyleSheet(self.theme["button_off"])
self.ui.Add_White_list_Button_3.setStyleSheet(self.theme["button_off"])
self.ui.System_Process_Manage_Button.setStyleSheet(self.theme["button_off"])
self.ui.Repair_System_Files_Button.setStyleSheet(self.theme["button_off"])
self.ui.Clean_System_Files_Button.setStyleSheet(self.theme["button_off"])
self.ui.Reset_Options_Button.setStyleSheet(self.theme["button_off"])
self.ui.Window_Block_Button.setStyleSheet(self.theme["button_off"])
self.ui.Window_Block_Button_2.setStyleSheet(self.theme["button_off"])
self.ui.Repair_System_Network_Button.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button_2.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_2.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button_2.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button_3.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_3.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button_3.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button_4.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_4.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button_4.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button_5.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_5.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button_5.setStyleSheet(self.theme["button_off"])
if self.ui.Protection_switch_Button_8.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_8.setStyleSheet(self.theme["button_on"])
else:
self.ui.Protection_switch_Button_8.setStyleSheet(self.theme["button_off"])
if self.ui.high_sensitivity_switch_Button.text() == self.trans("已開啟"):
self.ui.high_sensitivity_switch_Button.setStyleSheet(self.theme["button_on"])
else:
self.ui.high_sensitivity_switch_Button.setStyleSheet(self.theme["button_off"])
if self.ui.extension_kit_switch_Button.text() == self.trans("已開啟"):
self.ui.extension_kit_switch_Button.setStyleSheet(self.theme["button_on"])
else:
self.ui.extension_kit_switch_Button.setStyleSheet(self.theme["button_off"])
if self.ui.cloud_services_switch_Button.text() == self.trans("已開啟"):
self.ui.cloud_services_switch_Button.setStyleSheet(self.theme["button_on"])
else:
self.ui.cloud_services_switch_Button.setStyleSheet(self.theme["button_off"])
except Exception as e:
print(e)
self.config_json["theme_color"] = "White"
self.init_config_theme()
def init_config_done(self): # 初始化完畢
try:
if len(sys.argv) > 1:
param = sys.argv[1].replace("/", "-")
if "-h" not in param:
self.init_config_show()
elif len(sys.argv) <= 1:
self.init_config_show()
self.first_startup = 0
except Exception as e:
print(e)
def init_config_func(self): # 初始化功能
try:
if self.config_json["proc_protect"] == 1:
self.protect_proc_init()
if self.config_json["file_protect"] == 1:
self.protect_file_init()
if self.config_json["sys_protect"] == 1:
self.protect_sys_init()
if self.config_json["net_protect"] == 1:
self.protect_net_init()
#if self.config_json["cus_protect"] == 1:
#self.protect_cus_init()
if self.config_json["sensitivity"] == 1:
self.change_sensitive()
if self.config_json["extend_mode"] == 1:
self.extension_kit()
self.protect_drv_init()
self.block_window_init()
self.gc_collect_init()
except Exception as e:
print(e)
def protect_proc_init(self): # 初始化進程防護
try:
if self.ui.Protection_switch_Button.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button.setText(self.trans("已關閉"))
self.ui.Protection_switch_Button.setStyleSheet(self.theme["button_off"])
self.config_json["proc_protect"] = 0
else:
self.config_json["proc_protect"] = 1
Thread(target=self.protect_proc_thread, daemon=True).start()
self.ui.Protection_switch_Button.setText(self.trans("已開啟"))
self.ui.Protection_switch_Button.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def protect_file_init(self): # 初始化檔案防護
try:
if self.ui.Protection_switch_Button_2.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_2.setText(self.trans("已關閉"))
self.ui.Protection_switch_Button_2.setStyleSheet(self.theme["button_off"])
self.config_json["file_protect"] = 0
else:
self.config_json["file_protect"] = 1
Thread(target=self.protect_file_thread, daemon=True).start()
self.ui.Protection_switch_Button_2.setText(self.trans("已開啟"))
self.ui.Protection_switch_Button_2.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def protect_sys_init(self): # 初始化系統防護
try:
if self.ui.Protection_switch_Button_3.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_3.setText(self.trans("已關閉"))
self.ui.Protection_switch_Button_3.setStyleSheet(self.theme["button_off"])
self.config_json["sys_protect"] = 0
else:
self.config_json["sys_protect"] = 1
Thread(target=self.protect_boot_thread, daemon=True).start()
Thread(target=self.protect_reg_thread, daemon=True).start()
self.ui.Protection_switch_Button_3.setText(self.trans("已開啟"))
self.ui.Protection_switch_Button_3.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def protect_drv_init(self): # 初始化驅動防護
try:
file_path = self.path_driver.replace("\\", "/")
if os.path.exists(file_path):
if self.ui.Protection_switch_Button_4.text() == self.trans("已開啟"):
result = Popen("sc stop PYAS_Driver", shell=True, stdout=PIPE, stderr=PIPE).wait()
if not self.first_startup:
if result == 0 or result == 577:
if self.question_event("使用此選項需要重啟,您確定要重啟嗎?"):
Popen(f'"{file_path}/Uninstall_Driver.bat"', shell=True, stdout=PIPE, stderr=PIPE)
else:
Popen("sc start PYAS_Driver", shell=True, stdout=PIPE, stderr=PIPE).wait()
if result == 1062 or result == 1060:
self.ui.Protection_switch_Button_4.setText(self.trans("已關閉"))
self.ui.Protection_switch_Button_4.setStyleSheet(self.theme["button_off"])
else:
result = Popen("sc start PYAS_Driver", shell=True, stdout=PIPE, stderr=PIPE).wait()
if not self.first_startup:
if result == 1060 or result == 3 or result == 577:
if self.question_event("此選項可能會與其他軟體不兼容,您確定要開啟嗎?"):
Popen("sc delete PYAS_Driver", shell=True, stdout=PIPE, stderr=PIPE).wait()
Popen(f'"{file_path}/Install_Driver.bat"', shell=True, stdout=PIPE, stderr=PIPE)
else:
Popen("sc stop PYAS_Driver", shell=True, stdout=PIPE, stderr=PIPE).wait()
if result == 0 or result == 1056:
self.ui.Protection_switch_Button_4.setText(self.trans("已開啟"))
self.ui.Protection_switch_Button_4.setStyleSheet(self.theme["button_on"])
except Exception as e:
print(e)
def protect_net_init(self): # 初始化網路防護
try:
if self.ui.Protection_switch_Button_5.text() == self.trans("已開啟"):
self.ui.Protection_switch_Button_5.setText(self.trans("已關閉"))
self.ui.Protection_switch_Button_5.setStyleSheet(self.theme["button_off"])
self.config_json["net_protect"] = 0
else:
self.config_json["net_protect"] = 1
Thread(target=self.protect_net_thread, daemon=True).start()
self.ui.Protection_switch_Button_5.setText(self.trans("已開啟"))
self.ui.Protection_switch_Button_5.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def protect_cus_init(self): # 初始化自訂防護
self.info_event("此功能不支持使用")
#if self.ui.Protection_switch_Button_8.text() == self.trans("已開啟"):
#self.ui.Protection_switch_Button_8.setText(self.trans("已關閉"))
#self.ui.Protection_switch_Button_8.setStyleSheet(self.theme["button_off"])
#self.config_json["cus_protect"] = 0
#else:
#self.config_json["cus_protect"] = 1
#self.ui.Protection_switch_Button_8.setText(self.trans("已開啟"))
#self.ui.Protection_switch_Button_8.setStyleSheet(self.theme["button_on"])
#self.init_config_write(self.config_json)
def change_sensitive(self): # 初始化靈敏度
if self.ui.high_sensitivity_switch_Button.text() == self.trans("已開啟"):
self.ui.high_sensitivity_switch_Button.setText(self.trans("已關閉"))
self.ui.high_sensitivity_switch_Button.setStyleSheet(self.theme["button_off"])
self.config_json["sensitivity"] = 0
elif self.first_startup or self.question_event("此選項可能會誤報檔案,您確定要開啟嗎?"):
self.config_json["sensitivity"] = 1
self.ui.high_sensitivity_switch_Button.setText(self.trans("已開啟"))
self.ui.high_sensitivity_switch_Button.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
def extension_kit(self): # 初始化擴展引擎
if self.ui.extension_kit_switch_Button.text() == self.trans("已開啟"):
self.ui.extension_kit_switch_Button.setText(self.trans("已關閉"))
self.ui.extension_kit_switch_Button.setStyleSheet(self.theme["button_off"])
self.config_json["extend_mode"] = 0
else:
self.config_json["extend_mode"] = 1
self.ui.extension_kit_switch_Button.setText(self.trans("已開啟"))
self.ui.extension_kit_switch_Button.setStyleSheet(self.theme["button_on"])
self.init_config_write(self.config_json)
def cloud_services(self): # 初始化雲端掃描
self.info_event("此功能不支持使用")
#if self.ui.cloud_services_switch_Button.text() == self.trans("已開啟"):
#self.ui.cloud_services_switch_Button.setText(self.trans("已關閉"))
#self.ui.cloud_services_switch_Button.setStyleSheet(self.theme["button_off"])
#self.config_json["service_url"] = 0
#else:
#self.config_json["service_url"] = 1
#self.ui.cloud_services_switch_Button.setText(self.trans("已開啟"))
#self.ui.cloud_services_switch_Button.setStyleSheet(self.theme["button_on"])
#self.init_config_write(self.config_json)
def gc_collect_init(self): # 初始化程式回收
try:
self.gc_collect = 1
Thread(target=self.gc_collect_thread, daemon=True).start()
except Exception as e:
print(e)
def gc_collect_thread(self): # 程式回收線程
while self.gc_collect:
try:
time.sleep(0.2)
collected = gc.collect()
except:
pass
def block_window_init(self): # 初始化彈窗攔截
try:
self.block_window = 1
Thread(target=self.block_software_window, daemon=True).start()
except Exception as e:
print(e)
def add_white_list(self): # 添加白名單
try:
file = str(QFileDialog.getExistingDirectory(self,self.trans("增加到白名單"),"")).replace("\\", "/")
if file and self.question_event("您確定要增加到白名單嗎?"):
if file not in self.config_json["white_lists"]:
self.config_json["white_lists"].append(file)
self.info_event(f"成功增加到白名單: "+file)
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def remove_white_list(self):
try:
file = str(QFileDialog.getExistingDirectory(self,self.trans("移除白名單"),"")).replace("\\", "/")
if file and self.question_event("您確定要移除白名單嗎?"):
if file in self.config_json["white_lists"]:
self.config_json["white_lists"].remove(file)
self.info_event(f"成功移除白名單: "+file)
self.init_config_write(self.config_json)
except Exception as e:
print(e)
def add_software_window(self): # 添加彈窗攔截
try:
self.block_window = 0
if self.question_event("請選擇要攔截的軟體彈窗"):
while True:
QApplication.processEvents()
hWnd = self.user32.GetForegroundWindow()
window_info = self.get_window_info(hWnd)
if window_info not in self.pass_windows:
if self.question_event(f"您確定要攔截 {window_info} 嗎?"):
if window_info not in self.config_json["block_lists"]:
self.config_json["block_lists"].append(window_info)
self.info_event(f"成功增加到彈窗攔截: {window_info}")
break
self.init_config_write(self.config_json)
self.block_window_init()
except Exception as e:
print(e)
def remove_software_window(self):
try:
self.block_window = 0
if self.question_event("請選擇要取消攔截的軟體彈窗"):
while True:
QApplication.processEvents()
hWnd = self.user32.GetForegroundWindow()
window_info = self.get_window_info(hWnd)
if window_info not in self.pass_windows:
if self.question_event(f"您確定要取消攔截 {window_info} 嗎?"):
if window_info in self.config_json["block_lists"]:
self.config_json["block_lists"].remove(window_info)
self.info_event(f"成功取消彈窗攔截: {window_info}")
break
self.init_config_write(self.config_json)
self.block_window_init()
except Exception as e:
print(e)
def get_window_info(self, hWnd): # 取得窗口資訊
length = self.user32.GetWindowTextLengthW(hWnd)
title = ctypes.create_unicode_buffer(length + 1)
self.user32.GetWindowTextW(hWnd, title, length + 1)
window_title = str(title.value)
class_name = ctypes.create_unicode_buffer(256)
self.user32.GetClassNameW(hWnd, class_name, 256)
class_name = str(class_name.value)
return {window_title: class_name}
def enum_windows_callback(self, hWnd, lParam):
self.hwnd_list.append(hWnd)
return True
def get_all_windows(self):
self.hwnd_list = []
WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.c_int, ctypes.c_int)
self.user32.EnumWindows(WNDENUMPROC(self.enum_windows_callback), 0)
return self.hwnd_list
def block_software_window(self): # 彈窗攔截線程
while self.block_window:
try:
time.sleep(0.2)
if not self.config_json["block_lists"]:
continue
for hWnd in self.get_all_windows():
window_info = self.get_window_info(hWnd)
if window_info in self.config_json["block_lists"]:
self.user32.SendMessageW(hWnd, 0x0010, 0xF060, 0) # WM_CLOSE, SC_CLOSE
self.user32.SendMessageW(hWnd, 0x0002, 0xF060, 0) # WM_DESTROY, SC_CLOSE
self.user32.SendMessageW(hWnd, 0x0012, 0xF060, 0) # WM_QUIT, SC_CLOSE
self.user32.SendMessageW(hWnd, 0x0112, 0xF060, 0) # WM_SYSCOMMAND, SC_CLOSE
except Exception as e:
print(e)
def init_config_show(self): # 顯示畫面
def update_opacity():
if self.pyas_opacity <= 100:
self.pyas_opacity += 2
self.setWindowOpacity(self.pyas_opacity/100)
else:
self.timer.stop()
self.pyas_opacity = 0
self.show()
self.timer = QTimer()
self.timer.timeout.connect(update_opacity)
self.timer.start(2)
def init_config_hide(self): # 隱藏畫面
def update_opacity():
if self.pyas_opacity >= 0:
self.pyas_opacity -= 2
self.setWindowOpacity(self.pyas_opacity/100)
else:
self.timer.stop()
self.hide()
self.timer = QTimer()
self.timer.timeout.connect(update_opacity)
self.timer.start(2)
def showMinimized(self): # 最小化畫面
if self.block_window:
self.init_config_hide()
#self.send_notify(self.trans("PYAS 已最小化到系統托盤圖標"))
def nativeEvent(self, eventType, message):
msg = ctypes.wintypes.MSG.from_address(int(message))
if msg.message in [0x0010, 0x0002, 0x0012, 0x0112, 0x0212]:
return True, 0
return super(MainWindow_Controller, self).nativeEvent(eventType, message)
def closeEvent(self, event): # 退出程序
if self.question_event("您確定要退出 PYAS 和所有防護嗎?"):
self.init_config_write(self.config_json)
self.clean_function()
event.accept()
else:
event.ignore()
def show_menu(self): # 功能選單
#self.WindowMenu = QMenu()
#Main_Settings = QAction(self.trans("設定"),self)
#Main_Update = QAction(self.trans("更新"),self)
#Main_About = QAction(self.trans("關於"),self)
#self.WindowMenu.addAction(Main_Settings)
#self.WindowMenu.addAction(Main_Update)
#self.WindowMenu.addAction(Main_About)
#Qusetion = self.WindowMenu.exec_(self.ui.Menu_Button.mapToGlobal(QPoint(0, 30)))
#if Qusetion == Main_About and self.ui.About_widget.isHidden():
if self.ui.About_widget.isHidden():
self.ui.State_widget.hide()
self.ui.Virus_Scan_widget.hide()
self.ui.Tools_widget.hide()
self.ui.Protection_widget.hide()
self.ui.Process_widget.hide()
self.ui.About_widget.show()
self.ui.Setting_widget.hide()
self.Process_Timer.stop()
self.change_animation_3(self.ui.About_widget,0.5)
self.change_animation_5(self.ui.About_widget,80,50,761,481)
#if Qusetion == Main_Update:
#self.update_database()
def update_database(self): # 更新數據
try:
if self.question_event("您確定要更新數據庫嗎?"):
self.info_event(f"Not support this function")
pass
except Exception as e:
print(e)
def change_animation(self,widget): # 畫面動畫
x, y = 80, widget.pos().y()
self.anim = QPropertyAnimation(widget, b"geometry")
widget.setGeometry(QRect(x - 60,y, 761, 481))
self.anim.setKeyValueAt(0.2, QRect(x - 30,y,761,481))
self.anim.setKeyValueAt(0.3, QRect(x - 10,y,761,481))
self.anim.setKeyValueAt(0.4, QRect(x - 5,y,761,481))
self.anim.setKeyValueAt(1, QRect(x,y,761,481))
self.anim.start()
def change_animation_3(self,widget,time):
self.opacity = QGraphicsOpacityEffect()
self.opacity.setOpacity(0)
self.opacity.i = self.opacity.opacity()
widget.setGraphicsEffect(self.opacity)
widget.setAutoFillBackground(True)
self.timer = QTimer()
self.timer.timeout.connect(self.timeout)
self.timer.start(2)
def timeout(self): # 透明度動畫
if self.opacity.i <= 1:
self.opacity.i += 0.05
self.opacity.setOpacity(self.opacity.i)
else:
self.timer.stop()
def change_animation_4(self,widget,time,ny,ny2): # 掃描選單動畫
x, y = widget.pos().x(), widget.pos().y()
self.anim4 = QPropertyAnimation(widget, b"geometry")
self.anim4.setDuration(time)
self.anim4.setStartValue(QRect(x, y, 111, ny))
self.anim4.setEndValue(QRect(x, y, 111, ny2))
self.anim4.start()
def change_animation_5(self,widget,x,y,nx,ny): # 設置動畫
self.anim = QPropertyAnimation(widget, b"geometry")
widget.setGeometry(QRect(x,y - 45, nx,ny))
self.anim.setKeyValueAt(0.2, QRect(x,y - 30,nx,ny))
self.anim.setKeyValueAt(0.3, QRect(x,y - 10,nx,ny))
self.anim.setKeyValueAt(0.4, QRect(x,y - 5,nx,ny))
self.anim.setKeyValueAt(1, QRect(x,y,nx,ny))
self.anim.start()
def change_setting_widget(self): # 狀態動畫
if self.ui.Setting_widget.isHidden():
self.change_animation_3(self.ui.Setting_widget,0.5)
self.change_animation(self.ui.Setting_widget)
self.ui.State_widget.hide()
self.ui.Virus_Scan_widget.hide()
self.ui.Tools_widget.hide()
self.ui.Protection_widget.hide()
self.ui.Process_widget.hide()