This commit is contained in:
恍兮惚兮 2024-08-28 02:10:20 +08:00
parent ba2f0545d1
commit d8b3cbbd4c

View File

@ -186,6 +186,8 @@ class texthook(basetext):
def init(self): def init(self):
self.pids = [] self.pids = []
self.maybepids = []
self.maybepidslock = threading.Lock()
self.keepref = [] self.keepref = []
self.hookdatacollecter = OrderedDict() self.hookdatacollecter = OrderedDict()
self.reverse = {} self.reverse = {}
@ -200,8 +202,6 @@ class texthook(basetext):
self.runonce_line = "" self.runonce_line = ""
gobject.baseobject.autoswitchgameuid = False gobject.baseobject.autoswitchgameuid = False
self.delaycollectallselectedoutput() self.delaycollectallselectedoutput()
self.singlethread = True
self.singlethreadlock = threading.Lock()
self.autohookmonitorthread() self.autohookmonitorthread()
self.initdllonce = True self.initdllonce = True
self.initdlllock = threading.Lock() self.initdlllock = threading.Lock()
@ -359,10 +359,6 @@ class texthook(basetext):
@threader @threader
def autohookmonitorthread(self): def autohookmonitorthread(self):
with self.singlethreadlock:
if not self.singlethread:
return
self.singlethread = False
while (not self.ending) and (len(self.pids) == 0): while (not self.ending) and (len(self.pids) == 0):
try: try:
hwnd = windows.GetForegroundWindow() hwnd = windows.GetForegroundWindow()
@ -371,13 +367,10 @@ class texthook(basetext):
except: except:
print_exc() print_exc()
time.sleep(0.1) time.sleep(0.1)
with self.singlethreadlock:
self.singlethread = True
def start(self, hwnd, pids, gamepath, gameuid, autostart=False): def start(self, hwnd, pids, gamepath, gameuid, autostart=False):
self.delayinit() self.delayinit()
for pid in pids: for pid in pids:
# 如果有进程一闪而逝,没来的及注入,导致无法自动重连
self.waitend(pid) self.waitend(pid)
gobject.baseobject.hwnd = hwnd gobject.baseobject.hwnd = hwnd
gobject.baseobject.gameuid = gameuid gobject.baseobject.gameuid = gameuid
@ -424,11 +417,7 @@ class texthook(basetext):
return string return string
def removeproc(self, pid): def removeproc(self, pid):
try: self.pids.remove(pid)
if pid in self.pids:
self.pids.remove(pid)
except:
pass
if len(self.pids) == 0: if len(self.pids) == 0:
self.autohookmonitorthread() self.autohookmonitorthread()
@ -466,14 +455,25 @@ class texthook(basetext):
@threader @threader
def waitend(self, pid): def waitend(self, pid):
# 如果有进程一闪而逝,没来的及注入,导致无法自动重连
self.maybepids.append(pid)
windows.WaitForSingleObject( windows.WaitForSingleObject(
windows.AutoHandle(windows.OpenProcess(windows.SYNCHRONIZE, False, pid)), windows.AutoHandle(windows.OpenProcess(windows.SYNCHRONIZE, False, pid)),
windows.INFINITE, windows.INFINITE,
) )
self.removeproc(pid) with self.maybepidslock:
if len(self.pids) == 0 and len(self.maybepids):
# 如果进程连接则剔除maybepids
# 当进程结束,且发现是被试探过&未曾连接,则重试
self.maybepids.clear()
self.autohookmonitorthread()
def onprocconnect(self, pid): def onprocconnect(self, pid):
self.pids.append(pid) self.pids.append(pid)
try:
self.maybepids.remove(pid)
except:
pass
for hookcode in self.needinserthookcode: for hookcode in self.needinserthookcode:
self.Luna_InsertHookCode(pid, hookcode) self.Luna_InsertHookCode(pid, hookcode)
gobject.baseobject.displayinfomessage( gobject.baseobject.displayinfomessage(