-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClut-Injector.py
More file actions
1655 lines (1417 loc) · 61.6 KB
/
Clut-Injector.py
File metadata and controls
1655 lines (1417 loc) · 61.6 KB
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
import sys
import ctypes
from datetime import datetime
import time
import psutil
# pywin32
import win32process
import win32gui
import win32con
import win32api
from PyQt5.QtWidgets import (
QApplication, QWidget, QLabel, QPushButton, QVBoxLayout,
QMessageBox, QListWidget, QFileDialog, QFormLayout, QHBoxLayout,
QDialog, QDialogButtonBox, QProgressBar, QTextEdit, QListWidgetItem,
QSpinBox, QLineEdit, QCheckBox, QFileIconProvider, QComboBox, QListWidget
)
from PyQt5.QtCore import (
Qt, QThread, pyqtSignal, QRect, QPoint, QSize, QTimer,
QSettings, QFileInfo, QMetaType
)
from PyQt5.QtGui import (
QPainter, QBrush, QColor, QRegion, QIcon, QPalette,
QPixmap, QImage,QTextCursor
)
from PyQt5.QtWidgets import (
QApplication, QWidget, QLabel, QPushButton, QVBoxLayout,
QMessageBox, QListWidget, QFileDialog, QFormLayout, QHBoxLayout,
QDialog, QDialogButtonBox, QProgressBar, QTextEdit, QListWidgetItem,
QSpinBox, QLineEdit, QCheckBox, QMenu
)
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QRect, QPoint, QSize, QTimer, QSettings
from PyQt5.QtGui import QPainter, QBrush, QColor, QRegion, QIcon
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtGui import QPixmap, QImage
from PIL import Image
import io
import win32ui
from win32gui import GetWindowDC
from PyQt5.QtGui import QPixmap, QImage
from win32con import (
GWL_EXSTYLE, WS_EX_LAYERED, LWA_ALPHA, LWA_COLORKEY,
SRCCOPY
)
from win32com.client import GetObject
from concurrent.futures import ThreadPoolExecutor
from queue import Queue, Empty
import threading
ScrollBar = ("""
/* 垂直滚动条 */
QScrollBar:vertical {
background: transparent;
width: 8px;
margin: 0px;
border-radius: 4px;
}
QScrollBar::handle:vertical {
background: rgba(74, 144, 217, 0.6);
min-height: 30px;
border-radius: 4px;
margin: 1px;
}
QScrollBar::handle:vertical:hover {
background: rgba(74, 144, 217, 0.8);
}
QScrollBar::handle:vertical:pressed {
background: rgba(74, 144, 217, 1.0);
}
QScrollBar::add-line:vertical,
QScrollBar::sub-line:vertical {
height: 0px;
background: transparent;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: transparent;
}
/* 水平滚动条 */
QScrollBar:horizontal {
background: transparent;
height: 8px;
margin: 0px;
border-radius: 4px;
}
QScrollBar::handle:horizontal {
background: rgba(74, 144, 217, 0.6);
min-width: 30px;
border-radius: 4px;
margin: 1px;
}
QScrollBar::handle:horizontal:hover {
background: rgba(74, 144, 217, 0.8);
}
QScrollBar::handle:horizontal:pressed {
background: rgba(74, 144, 217, 1.0);
}
QScrollBar::add-line:horizontal,
QScrollBar::sub-line:horizontal {
width: 0px;
background: transparent;
}
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: transparent;
}
/* 当滚动条处于非活动状态时的样式 */
QScrollBar::handle:vertical:disabled,
QScrollBar::handle:horizontal:disabled {
background: rgba(128, 128, 128, 0.3);
}
/* 当鼠标不在窗口上时,滚动条半透明 */
QScrollBar:vertical:!hover,
QScrollBar:horizontal:!hover {
background: transparent;
}
/* 当滚动条处于活动状态时显示阴影效果 */
QScrollBar::handle:vertical:hover,
QScrollBar::handle:horizontal:hover {
border: 1px solid rgba(74, 144, 217, 0.8);
}
""")
class CustomTitleBar(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setFixedHeight(60) # 设置标题栏高度
# 初始化按钮
self.minimize_button = QPushButton('-', self)
self.maximize_button = QPushButton('□', self)
self.close_button = QPushButton(' × ', self)
self.minimize_button.clicked.connect(self.minimize)
self.maximize_button.clicked.connect(self.toggle_maximize_restore)
self.close_button.clicked.connect(self.close)
layout = QHBoxLayout()
layout.addWidget(self.minimize_button)
layout.addWidget(self.maximize_button)
layout.addWidget(self.close_button, alignment=Qt.AlignRight)
self.setLayout(layout)
self.setAutoFillBackground(True)
self.is_maximized = False
self.old_pos = None
def minimize(self):
self.window().showMinimized()
def toggle_maximize_restore(self):
if self.is_maximized:
self.window().showNormal()
self.is_maximized = False
self.maximize_button.setText('□')
else:
self.window().showMaximized()
self.is_maximized = True
self.maximize_button.setText('❐')
def close(self):
if QMessageBox.question(self,"Tips","You Will Close The Program! \n Are You Sure?") == QMessageBox.Yes:
self.window().close()
else:
pass
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
try:
# 尝试新版本的方法
self.old_pos = event.globalPosition().toPoint()
except AttributeError:
# 如果失败,使用旧版本的方法
self.old_pos = event.globalPos()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton and self.old_pos is not None:
try:
# 尝试新版本的方法
delta = event.globalPosition().toPoint() - self.old_pos
self.window().move(self.window().pos() + delta)
self.old_pos = event.globalPosition().toPoint()
except AttributeError:
# 如果失败,使用旧版本的方法
delta = event.globalPos() - self.old_pos
self.window().move(self.window().pos() + delta)
self.old_pos = event.globalPos()
def mouseReleaseEvent(self, event):
self.old_pos = None
from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QListWidget, QPushButton, QLineEdit, QDialogButtonBox
)
import psutil
class ProcessSelectionDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("选择进程")
self.setModal(True)
# 设置对话框的大小
self.setFixedSize(600, 400) # 设置为你希望的大小
self.process_list = QListWidget(self)
self.search_box = QLineEdit(self)
self.search_box.setPlaceholderText("搜索进程名或PID...")
self.process_list.setStyleSheet(ScrollBar + self.process_list.styleSheet() + """
QListWidget::item {
padding: 5px;
border-bottom: 1px solid rgba(74, 74, 74, 100);
}
QListWidget::item:selected {
background: rgba(74, 144, 217, 180);
color: white;
}
QListWidget::item:hover {
background: rgba(74, 144, 217, 100);
}
""")
self.search_box.textChanged.connect(self.filter_processes)
self.select_button = QPushButton('选择', self)
self.cancel_button = QPushButton('取消', self)
self.button_box = QDialogButtonBox(self)
self.button_box.addButton(self.select_button, QDialogButtonBox.AcceptRole)
self.button_box.addButton(self.cancel_button, QDialogButtonBox.RejectRole)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
layout = QVBoxLayout()
layout.addWidget(self.search_box)
layout.addWidget(self.process_list)
layout.addWidget(self.button_box)
self.setLayout(layout)
self.processes = []
# 初始填充所有进程
self.populate_processes([(proc.pid, proc.name()) for proc in psutil.process_iter(['pid', 'name'])])
def populate_processes(self, processes):
self.process_list.clear()
self.processes = processes
self.update_process_list()
def update_process_list(self):
search_text = self.search_box.text().lower()
self.process_list.clear()
for pid, name in self.processes:
if search_text in str(pid) or search_text in name.lower():
self.process_list.addItem(f"PID: {pid} - {name}")
def filter_processes(self):
self.update_process_list()
def get_selected_pid(self):
selected_item = self.process_list.currentItem()
if selected_item:
pid_str = selected_item.text().split()[1]
return int(pid_str)
return None
current_dir = os.path.dirname(os.path.abspath(__file__))
dll_path = os.path.join(current_dir, "ClutInject_Kernel.dll")
try:
inject_dll = ctypes.CDLL(dll_path)
inject_dll.InjectDLL.argtypes = [ctypes.c_uint, ctypes.c_char_p]
inject_dll.InjectDLL.restype = ctypes.c_bool
print("ClutInject_Kernel.dll 载入成功")
except Exception as e:
print(f"ClutInject_Kernel.dll加载失败: {e}")
def inject_dll_into_process(process_id, dll_path):
try:
success = inject_dll.InjectDLL(process_id, dll_path.encode('utf-8'))
return success
except Exception as e:
print(f"调用 DLL 函数时发生错误: {e}")
QMessageBox.critical(None, "错误", f"调用 DLL 函数时发生错误: {e}")
return False
class InjectorWorker(QThread):
progress = pyqtSignal(int)
finished = pyqtSignal(bool)
def __init__(self, process_id, dll_files, parent_widget=None):
super().__init__()
self.process_id = process_id
self.dll_files = dll_files
self.parent_widget = parent_widget
self.success_count = 0
def run(self):
success = True
for index, dll_path in enumerate(self.dll_files):
if not self.perform_injection(dll_path):
success = False
break
self.progress.emit(int((index + 1) / len(self.dll_files) * 100))
self.finished.emit(success)
def perform_injection(self, dll_path):
max_retries = 3
for attempt in range(max_retries):
try:
result = inject_dll_into_process(self.process_id, dll_path)
if result:
self.success_count += 1
if self.parent_widget:
self.parent_widget.log_message(f"DLL {dll_path} 注入成功!", level="INFO")
return True
else:
if self.parent_widget:
self.parent_widget.log_message(f"第 {attempt + 1} 次注入失败,正在重试...", level="WARNING")
if attempt < max_retries - 1:
time.sleep(3)
except Exception as e:
if self.parent_widget:
self.parent_widget.log_message(f"注入失败 错误信息: {e}", level="ERROR")
return False
class ProcessListItem(QListWidgetItem):
def __init__(self, pid, name, icon=None, show_pid=True):
super().__init__()
self.pid = pid
self.process_name = name # 保存原始进程名
# 根据设置决定显格式
if show_pid:
self.setText(f"PID: {pid} - {name}")
else:
self.setText(name)
if icon and not icon.isNull():
self.setIcon(icon)
def clone(self):
show_pid = QSettings('ClutInject', 'Settings').value('show_pid', True, bool)
new_item = ProcessListItem(self.pid, self.process_name, show_pid=show_pid)
if self.icon():
new_item.setIcon(self.icon())
return new_item
class IconWorker(QThread):
icon_ready = pyqtSignal(int, QIcon)
def __init__(self, pid_queue):
super().__init__()
self.pid_queue = pid_queue
self.running = True
def get_process_icon(self, pid):
try:
process = psutil.Process(pid)
try:
exe_path = process.exe()
except (psutil.NoSuchProcess, psutil.AccessDenied):
return None
if not exe_path or not os.path.exists(exe_path):
return None
try:
# 使用QFileInfo直接获取图标
file_info = QFileInfo(exe_path)
provider = QFileIconProvider()
icon = provider.icon(file_info)
if not icon.isNull():
return icon
# 如果QFileIconProvider失败,尝试使用系统API
import win32gui
import win32con
# 获取小图标
large, small = win32gui.ExtractIconEx(exe_path, 0)
try:
if small:
# 获取第一个小图标的句柄
handle = small[0]
# 获取图标信息
icon_info = win32gui.GetIconInfo(handle)
hbmColor = icon_info[3] # 彩色位图句柄
# 创建临时文件保存图标
temp_path = os.path.join(os.environ['TEMP'], f'icon_{pid}.png')
# 使用GDI+保存位图
from PIL import ImageGrab
img = ImageGrab.grab((0, 0, 16, 16)) # 创建空白图像
img.save(temp_path)
# 加载为QIcon
icon = QIcon(temp_path)
# 清理临时文件
try:
os.remove(temp_path)
except:
pass
return icon if not icon.isNull() else None
finally:
# 清理图标句柄
if large:
for handle in large:
try:
win32gui.DestroyIcon(handle)
except:
pass
if small:
for handle in small:
try:
win32gui.DestroyIcon(handle)
except:
pass
except Exception as e:
return None
except Exception as e:
return None
return None
def run(self):
while self.running:
try:
pid = self.pid_queue.get_nowait()
try:
icon = self.get_process_icon(pid)
if icon and not icon.isNull():
self.icon_ready.emit(pid, icon)
finally:
self.pid_queue.task_done()
except Empty:
self.running = False
break
def stop(self):
self.running = False
self.wait()
class SettingsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.settings = QSettings('ClutInject', 'Settings')
self.initUI()
def initUI(self):
self.setWindowTitle("设置")
layout = QVBoxLayout()
# 线程数设置
thread_layout = QHBoxLayout()
thread_label = QLabel("图标加载线程数:")
self.thread_spinbox = QSpinBox()
self.thread_spinbox.setRange(1, 16)
self.thread_spinbox.setValue(self.settings.value('icon_threads', 8, int))
thread_layout.addWidget(thread_label)
thread_layout.addWidget(self.thread_spinbox)
layout.addLayout(thread_layout)
# 进程过滤设置
filter_layout = QHBoxLayout()
filter_label = QLabel("进程过滤名称:")
self.filter_edit = QLineEdit()
self.filter_edit.setText(self.settings.value('process_filter', 'javaw.exe,java.exe', str))
filter_layout.addWidget(filter_label)
filter_layout.addWidget(self.filter_edit)
layout.addLayout(filter_layout)
# 显示设置
self.show_pid = QCheckBox("显示进程PID")
self.show_pid.setChecked(self.settings.value('show_pid', True, bool))
self.show_icon = QCheckBox("显示进程图标")
self.show_icon.setChecked(self.settings.value('show_icon', True, bool))
# 修改图标位置设置
icon_pos_layout = QHBoxLayout()
icon_pos_label = QLabel("按钮图标位置:")
self.icon_pos_combo = QComboBox()
self.icon_pos_combo.addItems(["左侧", "居中", "右侧"])
current_pos = self.settings.value('icon_position', 'left', str)
if current_pos == 'left':
self.icon_pos_combo.setCurrentText("左侧")
elif current_pos == 'center':
self.icon_pos_combo.setCurrentText("居中")
else:
self.icon_pos_combo.setCurrentText("右侧")
icon_pos_layout.addWidget(icon_pos_label)
icon_pos_layout.addWidget(self.icon_pos_combo)
layout.addWidget(self.show_pid)
layout.addWidget(self.show_icon)
layout.addLayout(icon_pos_layout)
# 按钮
buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
)
buttons.accepted.connect(self.save_settings)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
self.setLayout(layout)
def save_settings(self):
self.settings.setValue('icon_threads', self.thread_spinbox.value())
self.settings.setValue('process_filter', self.filter_edit.text())
self.settings.setValue('show_pid', self.show_pid.isChecked())
self.settings.setValue('show_icon', self.show_icon.isChecked())
# 保存图标位置设置
pos_map = {"左侧": "left", "居中": "center", "右侧": "right"}
self.settings.setValue('icon_position', pos_map[self.icon_pos_combo.currentText()])
self.accept()
class ProcessLoaderThread(QThread):
finished = pyqtSignal(list)
def run(self):
processes = []
try:
for proc in psutil.process_iter(['pid', 'name']):
try:
processes.append((proc.info['pid'], proc.info['name']))
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
except Exception as e:
print(f"获取进程列表失败: {e}")
self.finished.emit(sorted(processes, key=lambda x: x[1].lower()))
class InjectorGUI(QWidget):
def __init__(self):
super().__init__()
self.settings = QSettings('ClutInject', 'Settings')
self._cursor_warning_shown = False
self.injected_dlls = {}
self.highlighted_windows = {}
self.icon_workers = []
self.initUI()
self.update_button_styles()
self.setWindowIcon(QIcon('./icons/logo.png'))
self.log_message("程序图标加载完成", level="DEBUG")
self.log_welcome()
self.log_message("GUI初始化完成", level="INFO")
def log_message(self, message, level="INFO"):
# 获取当前时间戳
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 定义日志级别对应的颜色
color_map = {
"DEBUG": "#800080", # 紫色
"INFO": "#00FF00", # 绿色
"WARNING": "#FFA500", # 橙色
"ERROR": "#FF0000" # 红色
}
# 获取对应级别的颜色
color = color_map.get(level, "#FFFFFF") # 默认白色
# 格式化消息
formatted_message = f"│ [{level}/{current_time}] {message}"
html_message = f"<span style='color: {color};'>{formatted_message}</span><br>"
# 保存当前内容
current_html = self.log_box.toHtml()
# 在标题div后插入新消息
if "</div>" in current_html:
new_html = current_html.replace("</div>", "</div>" + html_message, 1)
self.log_box.setHtml(new_html)
else:
self.log_box.insertHtml(html_message)
# 滚动到底部
self.log_box.verticalScrollBar().setValue(
self.log_box.verticalScrollBar().maximum()
)
def log_welcome(self):
# 修改标题HTML,移除position:fixed相关样式
title_html = """
<div style="
background-color: rgba(30, 30, 30, 0);
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
text-align: center;
font-size: 24px;
font-weight: bold;
color: #00ff00;
border-bottom: 2px solid rgba(74, 144, 217, 0.5);
">
Clut Injector V3.0.0 Release
</div>
"""
# 将标题HTML插入到日志框的顶部
self.log_box.setHtml(title_html)
def initUI(self):
layout = QHBoxLayout()
main_layout = QVBoxLayout()
self.title_bar = CustomTitleBar(self)
main_layout.addWidget(self.title_bar)
form_layout = QFormLayout()
self.process_label = QLabel('目标进程:', self)
self.process_label.setStyleSheet("background: transparent;") # 加上透明效果
self.process_list = QListWidget(self)
self.detect_button = QPushButton('自动检测设置的相关进程', self)
self.detect_button.setIcon(QIcon('icons/detect.png'))
self.detect_button.setIconSize(QSize(20, 20)) # 设置图标大小
self.detect_button.clicked.connect(self.detect_game_process)
self.select_process_button = QPushButton('手动选择进程', self)
self.select_process_button.setIcon(QIcon('icons/select.png'))
self.select_process_button.setIconSize(QSize(20, 20))
self.select_process_button.clicked.connect(self.select_process)
form_layout.addRow(self.process_label, self.process_list)
form_layout.addRow(self.detect_button, self.select_process_button)
self.dll_label = QLabel('选择DLL文件:', self)
self.dll_label.setStyleSheet("background: transparent;")
self.dll_list = QListWidget(self)
self.dll_list.setSelectionMode(QListWidget.ExtendedSelection) # 允许多选
self.dll_list.setContextMenuPolicy(Qt.CustomContextMenu) # 允许自定义右键菜单
self.dll_list.setStyleSheet(ScrollBar + self.dll_list.styleSheet() + """
QListWidget::item {
padding: 5px;
border-bottom: 1px solid rgba(74, 74, 74, 100);
}
QListWidget::item:selected {
background: rgba(74, 144, 217, 180);
color: white;
}
QListWidget::item:hover {
background: rgba(74, 144, 217, 100);
}
""")
self.browse_button = QPushButton('浏览文件夹', self)
self.browse_button.setIcon(QIcon('icons/browse.png'))
self.browse_button.setIconSize(QSize(20, 20))
self.browse_button.clicked.connect(self.browseDLL)
form_layout.addRow(self.dll_label, self.dll_list)
form_layout.addRow(self.browse_button)
self.inject_button = QPushButton('注入DLL', self)
self.inject_button.setIcon(QIcon('icons/inject.png'))
self.inject_button.setIconSize(QSize(20, 20))
self.inject_button.clicked.connect(self.injectDLL)
self.uninject_button = QPushButton('取消注入DLL', self)
self.uninject_button.setIcon(QIcon('icons/uninject.png'))
self.uninject_button.setIconSize(QSize(20, 20))
self.uninject_button.clicked.connect(self.uninjectDLL)
self.hint_button = QPushButton('选中窗口置顶', self)
self.hint_button.setIcon(QIcon('icons/hint.png'))
self.hint_button.setIconSize(QSize(20, 20))
self.hint_button.clicked.connect(self.toggle_window_highlight)
self.about_button = QPushButton('关于', self)
self.about_button.setIcon(QIcon('icons/about.png'))
self.about_button.setIconSize(QSize(20, 20))
self.about_button.clicked.connect(self.show_about_dialog)
self.progress_bar = QProgressBar(self)
self.progress_bar.setTextVisible(True)
self.progress_bar.setRange(0, 100)
button_layout = QVBoxLayout()
button_layout.addWidget(self.inject_button)
button_layout.addWidget(self.uninject_button)
button_layout.addWidget(self.hint_button)
button_layout.addWidget(self.about_button)
self.settings_button = QPushButton('设置', self)
self.settings_button.setIcon(QIcon('icons/settings.png'))
self.settings_button.setIconSize(QSize(20, 20))
self.settings_button.clicked.connect(self.show_settings)
button_layout.addWidget(self.settings_button)
button_layout.addWidget(self.progress_bar)
main_layout.addLayout(form_layout)
main_layout.addLayout(button_layout)
# 创建日志框
self.log_box = QTextEdit(self)
self.log_box.setReadOnly(True)
self.log_box.setStyleSheet("""
QTextEdit {
background-color: transparent;
font-family: 'Microsoft YaHei';
font-size: 11px;
color: #dcdcdc; /* 设置文本颜色以确保可见性 */
border: none; /* 可选:移除边框 */
}
""")
layout.addLayout(main_layout)
layout.addWidget(self.log_box)
self.setLayout(layout)
self.setWindowTitle('Clut Injector Build 20250111 | Stable Release DEV: ZZBuAoYe | Base: ClutUI-Fork_V1')
self.setGeometry(400, 400, 900, 500)
# 设置QSS样式
self.setStyleSheet("""
QWidget {
font-family: 'Microsoft YaHei', sans-serif;
background-color: rgba(30, 30, 30, 150);
color: #dcdcdc;
}
QLabel {
font-size: 14px;
padding: 5px;
color: #dcdcdc;
}
QPushButton {
font-size: 14px;
padding: 8px;
margin: 5px;
border: 1px solid #4a4a4a;
border-radius: 8px;
background-color: #333;
color: #dcdcdc;
}
QPushButton:hover {
background-color: #555;
border-color: #666;
}
QPushButton:pressed {
background-color: #777;
border-color: #888;
}
QListWidget {
font-size: 12px;
padding: 5px;
background-color: #2e2e2e;
border: 1px solid #4a4a4a;
border-radius: 8px;
}
QProgressBar {
border: 1px solid #4a4a4a;
border-radius: 8px;
text-align: center;
background-color: #2e2e2e;
padding: 2px;
}
QProgressBar::chunk {
background-color: #4a90d9;
border-radius: 8px;
}
QScrollBar:horizontal {
border: 1px solid #4a4a4a;
background: #2e2e2e;
height: 15px;
border-radius: 8px;
}
QScrollBar:vertical {
border: 1px solid #4a4a4a;
background: #2e2e2e;
width: 15px;
border-radius: 8px;
}
QScrollBar::handle:horizontal {
background: #4a90d9;
border-radius: 8px;
}
QScrollBar::handle:vertical {
background: #4a90d9;
border-radius: 8px;
}
QScrollBar::add-line:horizontal {
border: 1px solid #4a4a4a;
background: #2e2e2e;
border-radius: 8px;
height: 15px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::add-line:vertical {
border: 1px solid #4a4a4a;
background: #2e2e2e;
border-radius: 8px;
width: 15px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal {
border: 1px solid #4a4a4a;
background: #2e2e2e;
border-radius: 8px;
height: 15px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical {
border: 1px solid #4a4a4a;
background: #2e2e2e;
border-radius: 8px;
width: 15px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical, QScrollBar::left-arrow:horizontal, QScrollBar::right-arrow:horizontal {
border: 1px solid #4a4a4a;
background: #2e2e2e;
border-radius: 5px;
}
""")
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.radius = 15
# 添加统一的按钮样式
button_style = """
QPushButton {
text-align: left; /* 文本左对齐 */
padding-left: 30px; /* 为图标留出空间 */
font-size: 14px;
padding: 8px 8px 8px 30px; /* 上右下左内边距 */
margin: 5px;
border: 1px solid #4a4a4a;
border-radius: 8px;
background-color: #333;
color: #dcdcdc;
}
QPushButton:hover {
background-color: #555;
border-color: #666;
}
QPushButton:pressed {
background-color: #777;
border-color: #888;
}
"""
# 应用样式到所有按钮
for button in [self.detect_button, self.select_process_button,
self.browse_button, self.inject_button,
self.uninject_button, self.hint_button,
self.about_button, self.settings_button]:
button.setStyleSheet(button_style)
self.log_message("按钮图标加载完成", level="DEBUG")
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
# 画出圆角矩形
painter.setBrush(QBrush(QColor(30, 30, 30, 200)))
painter.drawRoundedRect(self.rect(), self.radius, self.radius)
def detect_game_process(self):
# 清理之前的线程
self.cleanup_workers()
current_selection = None
if self.process_list.currentItem():
current_pid = self.process_list.currentItem().pid
self.process_list.clear()
try:
process_filter = self.settings.value('process_filter', 'javaw.exe,java.exe', str)
filter_list = [name.strip().lower() for name in process_filter.split(',')]
processes = [(proc.pid, proc.name()) for proc in psutil.process_iter(['pid', 'name'])
if proc.name().lower() in filter_list]
show_pid = self.settings.value('show_pid', True, bool)
show_icon = self.settings.value('show_icon', True, bool)
if show_icon:
pid_queue = Queue()
thread_count = min(self.settings.value('icon_threads', 8, int), len(processes))
for pid, _ in processes:
pid_queue.put(pid)
for _ in range(thread_count):
worker = IconWorker(pid_queue)
worker.icon_ready.connect(self.update_process_icon)
self.icon_workers.append(worker)
worker.start()
for pid, name in processes:
item = ProcessListItem(pid, name, show_pid=show_pid)
self.process_list.addItem(item)
if current_selection and pid == current_pid: # 使用pid匹配
self.process_list.setCurrentItem(item)
if self.process_list.count() == 1:
# 如果只检测到一个进程,自动选择它
self.process_list.setCurrentItem(self.process_list.item(0))
self.log_message(f"自动选择唯一检测到的进程: {self.process_list.item(0).process_name}", level="INFO")
elif self.process_list.count() == 0:
QMessageBox.warning(self, "提示", "没有检测到相关进程")
self.log_message("没有检测到相关进程", level="WARNING")
except Exception as e:
self.log_message(f"检测进程失败: {e}", level="ERROR")
def cleanup_workers(self):
self.log_message("开始清理工作线程", level="DEBUG")
worker_count = len(self.icon_workers)
if hasattr(self, 'icon_workers'):
for worker in self.icon_workers:
worker.stop()
worker.wait()
self.icon_workers.clear()
self.log_message(f"已清理 {worker_count} 个工作线程", level="INFO")
def closeEvent(self, event):
"""窗口关闭时的处理"""
try:
self.cleanup_workers() # 清理线程
event.accept()
except Exception as e:
self.log_message(f"关闭窗口时出错: {e}", level="ERROR")
event.accept()
def update_process_icon(self, pid, icon):
try:
for i in range(self.process_list.count()):
item = self.process_list.item(i)
# 通过pid匹配,而不是文本匹配
if item.pid == pid and self.settings.value('show_icon', True, bool):
item.setIcon(icon)
break
except Exception as e:
self.log_message(f"更新进程图标失败: {e}", level="ERROR")
def browseDLL(self):
self.log_message("开始浏览DLL文件", level="DEBUG")
options = QFileDialog.Options()
dll_files, _ = QFileDialog.getOpenFileNames(self, "选择DLL文件", "", "DLL Files (*.dll)", options=options)
if dll_files:
existing_files = set(self.dll_list.item(i).text() for i in range(self.dll_list.count()))
for dll in dll_files:
if dll not in existing_files:
formatted_path = self.format_file_path(dll)
item = QListWidgetItem(formatted_path)
item.setToolTip(dll) # 添加完整路径作为提示
self.dll_list.addItem(item)
self.log_message(f"已添加 {len(dll_files)} 个DLL文件", level="INFO")
else:
self.log_message("未选择任何DLL文件", level="WARNING")
def show_dll_context_menu(self, position):
menu = QMenu()
remove_action = menu.addAction("移除选中的DLL")
clear_action = menu.addAction("清空所有DLL")
action = menu.exec_(self.dll_list.mapToGlobal(position))
if action == remove_action:
self.remove_selected_dlls()
elif action == clear_action:
self.clear_all_dlls()
def remove_selected_dlls(self):
selected_items = self.dll_list.selectedItems()
if not selected_items: