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,20 +807,16 @@ class MAINUI:
uid = findgameuidofpath(name_, savehook_new_list) uid = findgameuidofpath(name_, savehook_new_list)
if not uid: if not uid:
return return
lps = ListProcess(False) pids = ListProcess(name_)
for pids, _exe in lps: if self.textsource is not None:
if _exe != name_: return
continue if not globalconfig["sourcestatus2"]["texthook"]["use"]:
return
if self.textsource is not None: if globalconfig["startgamenototop"] == False:
return idx = savehook_new_list.index(uid)
if not globalconfig["sourcestatus2"]["texthook"]["use"]: savehook_new_list.insert(0, savehook_new_list.pop(idx))
return self.textsource = texthook(pids, hwnd, name_, uid, autostart=True)
if globalconfig["startgamenototop"] == False: self.textsource.start()
idx = savehook_new_list.index(uid)
savehook_new_list.insert(0, savehook_new_list.pop(idx))
self.textsource = texthook(pids, hwnd, name_, uid, autostart=True)
self.textsource.start()
else: else:
pids = self.textsource.pids pids = self.textsource.pids

View File

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

View File

@ -118,36 +118,34 @@ def test_injectable(pids):
return True return True
def ListProcess(filt=True): def ListProcess(exe=None):
ret = [] ret = {}
for pid in winsharedutils.Getprcesses(): for pid, exebase in winsharedutils.Getprcesses():
if os.getpid() == pid: if os.getpid() == pid:
continue continue
try: try:
if exe is not None:
if exebase.lower() != os.path.basename(exe).lower():
continue
name_ = getpidexe(pid) name_ = getpidexe(pid)
if name_ is None: if name_ is None:
continue continue
name = name_.lower() name = name_.lower()
if filt: if exe is None:
if ( if (
":\\windows\\" in name ":\\windows\\" in name
or "\\microsoft\\" in name or "\\microsoft\\" in name
or "\\windowsapps\\" in name or "\\windowsapps\\" in name
): ):
continue continue
ret.append([pid, name_]) if name_ not in ret:
ret[name_] = []
ret[name_].append(pid)
except: except:
pass pass
kv = {} if exe is None:
for pid, exe in ret: return ret
if exe not in kv: return ret.get(exe, [])
kv[exe] = []
kv[exe].append(pid)
xxx = []
for exe in kv:
xxx.append([kv[exe], exe])
return xxx
def getExeIcon(name, icon=True, cache=False): 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 myutils.config import globalconfig, savehook_new_data, static_data
from textsource.textsourcebase import basetext from textsource.textsourcebase import basetext
from myutils.utils import checkchaos 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.wrapper import threader
from myutils.utils import getfilemd5 from myutils.utils import getfilemd5
from traceback import print_exc from traceback import print_exc
@ -264,8 +264,12 @@ class texthook(basetext):
@threader @threader
def start(self): def start(self):
if self.injecttimeout:
time.sleep(self.injecttimeout)
if set(self.pids) != set(ListProcess(self.gamepath)):
# 部分cef/v8引擎的游戏会在一段启动时间后启动子进程用于渲染
return self.start()
time.sleep(self.injecttimeout)
if self.ending: if self.ending:
return return
try: try:

View File

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

View File

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

View File

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