This commit is contained in:
恍兮惚兮 2024-08-03 17:46:50 +08:00
parent a7ba33ddf2
commit 205d967187
7 changed files with 44 additions and 46 deletions

View File

@ -807,11 +807,7 @@ class MAINUI:
uid = findgameuidofpath(name_, savehook_new_list)
if not uid:
return
lps = ListProcess(False)
for pids, _exe in lps:
if _exe != name_:
continue
pids = ListProcess(name_)
if self.textsource is not None:
return
if not globalconfig["sourcestatus2"]["texthook"]["use"]:

View File

@ -23,14 +23,7 @@ class AttachProcessDialog(saveposwindow):
if pid == os.getpid():
return
name = getpidexe(pid)
lps = ListProcess(False)
_pids = None
for pids, _exe in lps:
if _exe == name:
_pids = pids
break
if _pids is None:
_pids = [pid]
_pids = ListProcess(name)
self.processEdit.setText(name)
self.processIdEdit.setText(",".join([str(pid) for pid in _pids]))
self.windowtext.setText(windows.GetWindowText(hwnd))
@ -129,7 +122,7 @@ class AttachProcessDialog(saveposwindow):
self.model = QStandardItemModel(self.processList)
self.processlist = ListProcess()
self.processList.setModel(self.model)
for pid, pexe in self.processlist:
for pexe in self.processlist:
if pexe in self.iconcache:
icon = self.iconcache[pexe]
else:
@ -152,14 +145,19 @@ class AttachProcessDialog(saveposwindow):
def editpid(self, process):
pids = self.safesplit(process)
if len(pids) == 0:
self.windowtext.clear()
self.processEdit.clear()
return
self.selectedp = (pids, getpidexe(pids[0]), self.guesshwnd(pids))
self.windowtext.setText(windows.GetWindowText(self.selectedp[-1]))
self.processEdit.setText(self.selectedp[1])
self.windowtext.setCursorPosition(0)
self.processEdit.setCursorPosition(0)
def selectedfunc(self, index):
pids, pexe = self.processlist[index.row()]
def selectedfunc(self, index: QModelIndex):
pexe = self.model.itemFromIndex(index).text()
pids = self.processlist.get(pexe, [])
self.processEdit.setText(pexe)
self.processIdEdit.setText(",".join([str(pid) for pid in pids]))
self.selectedp = pids, pexe, self.guesshwnd(pids)

View File

@ -118,36 +118,34 @@ def test_injectable(pids):
return True
def ListProcess(filt=True):
ret = []
for pid in winsharedutils.Getprcesses():
def ListProcess(exe=None):
ret = {}
for pid, exebase in winsharedutils.Getprcesses():
if os.getpid() == pid:
continue
try:
if exe is not None:
if exebase.lower() != os.path.basename(exe).lower():
continue
name_ = getpidexe(pid)
if name_ is None:
continue
name = name_.lower()
if filt:
if exe is None:
if (
":\\windows\\" in name
or "\\microsoft\\" in name
or "\\windowsapps\\" in name
):
continue
ret.append([pid, name_])
if name_ not in ret:
ret[name_] = []
ret[name_].append(pid)
except:
pass
kv = {}
for pid, exe in ret:
if exe not in kv:
kv[exe] = []
kv[exe].append(pid)
xxx = []
for exe in kv:
xxx.append([kv[exe], exe])
return xxx
if exe is None:
return ret
return ret.get(exe, [])
def getExeIcon(name, icon=True, cache=False):

View File

@ -8,7 +8,7 @@ from winsharedutils import Is64bit
from myutils.config import globalconfig, savehook_new_data, static_data
from textsource.textsourcebase import basetext
from myutils.utils import checkchaos
from myutils.hwnd import injectdll, test_injectable
from myutils.hwnd import injectdll, test_injectable, ListProcess
from myutils.wrapper import threader
from myutils.utils import getfilemd5
from traceback import print_exc
@ -264,8 +264,12 @@ class texthook(basetext):
@threader
def start(self):
if self.injecttimeout:
time.sleep(self.injecttimeout)
if set(self.pids) != set(ListProcess(self.gamepath)):
# 部分cef/v8引擎的游戏会在一段启动时间后启动子进程用于渲染
return self.start()
if self.ending:
return
try:

View File

@ -256,7 +256,9 @@ getprocesses.argtypes = (c_void_p,)
def Getprcesses():
ret = []
getprocesses(CFUNCTYPE(None, DWORD)(ret.append))
getprocesses(
CFUNCTYPE(None, DWORD, c_wchar_p)(lambda pid, exe: ret.append((pid, exe)))
)
return ret

View File

@ -28,7 +28,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
include(generate_product_version)
set(VERSION_MAJOR 5)
set(VERSION_MINOR 19)
set(VERSION_MINOR 20)
set(VERSION_PATCH 0)
add_library(pch pch.cpp)

View File

@ -110,7 +110,7 @@ DECLARE bool Is64bit(DWORD pid)
return false;
}
DECLARE void getprocesses(void (*cb)(DWORD))
DECLARE void getprocesses(void (*cb)(DWORD, const wchar_t *))
{
std::unordered_map<std::wstring, std::vector<int>> exe_pid;
AutoHandle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
@ -124,7 +124,7 @@ DECLARE void getprocesses(void (*cb)(DWORD))
{
do
{
cb(pe32.th32ProcessID);
cb(pe32.th32ProcessID, pe32.szExeFile);
} while (Process32Next(hSnapshot, &pe32));
}
}