This commit is contained in:
恍兮惚兮 2024-05-13 23:22:25 +08:00
parent af91d678dd
commit 4e53b7cbd7
3 changed files with 48 additions and 64 deletions

View File

@ -394,7 +394,7 @@ class searchhookparam(QDialog):
class hookselect(closeashidewindow): class hookselect(closeashidewindow):
addnewhooksignal = pyqtSignal(tuple, bool, list) addnewhooksignal = pyqtSignal(tuple, bool)
getnewsentencesignal = pyqtSignal(str) getnewsentencesignal = pyqtSignal(str)
sysmessagesignal = pyqtSignal(str) sysmessagesignal = pyqtSignal(str)
changeprocessclearsignal = pyqtSignal() changeprocessclearsignal = pyqtSignal()
@ -441,8 +441,8 @@ class hookselect(closeashidewindow):
self.allres = OrderedDict() self.allres = OrderedDict()
self.hidesearchhookbuttons() self.hidesearchhookbuttons()
def addnewhook(self, ss, select, textthread): def addnewhook(self, key, select):
hc, hn, tp = textthread hc, hn, tp = key
if len(self.save) == 0: if len(self.save) == 0:
if gobject.baseobject.textsource.allow_set_text_name: if gobject.baseobject.textsource.allow_set_text_name:
self.ttCombomodelmodel.setHorizontalHeaderLabels( self.ttCombomodelmodel.setHorizontalHeaderLabels(
@ -478,21 +478,21 @@ class hookselect(closeashidewindow):
0, QHeaderView.ResizeToContents 0, QHeaderView.ResizeToContents
) )
if ss[-1][0] == "E": if hc[0] == "E":
self.selectionbutton.insert( self.selectionbutton.insert(
0, 0,
getsimpleswitch( getsimpleswitch(
{1: False}, 1, callback=functools.partial(self.accept, ss) {1: False}, 1, callback=functools.partial(self.accept, key)
), ),
) )
self.save.insert(0, ss) self.save.insert(0, key)
rown = 0 rown = 0
else: else:
self.save.append(ss) self.save.append(key)
rown = self.ttCombomodelmodel.rowCount() rown = self.ttCombomodelmodel.rowCount()
self.selectionbutton.append( self.selectionbutton.append(
getsimpleswitch( getsimpleswitch(
{1: False}, 1, callback=functools.partial(self.accept, ss) {1: False}, 1, callback=functools.partial(self.accept, key)
) )
) )
if gobject.baseobject.textsource.allow_set_text_name: if gobject.baseobject.textsource.allow_set_text_name:
@ -507,20 +507,20 @@ class hookselect(closeashidewindow):
): ):
continue continue
if gobject.baseobject.textsource.match_compatibility( if gobject.baseobject.textsource.match_compatibility(
json.loads(jskey), ss json.loads(jskey), key
): ):
gobject.baseobject.textsource.hooktypecollecter[ss] = 1 gobject.baseobject.textsource.hooktypecollecter[key] = 1
self.typecombo.insert( self.typecombo.insert(
rown, rown,
getsimplecombobox( getsimplecombobox(
_TRL(["文本", "人名"]), _TRL(["文本", "人名"]),
gobject.baseobject.textsource.hooktypecollecter, gobject.baseobject.textsource.hooktypecollecter,
ss, key,
callback=functools.partial( callback=functools.partial(
savehook_new_data[gobject.baseobject.textsource.pname][ savehook_new_data[gobject.baseobject.textsource.pname][
"hooktypeasname" "hooktypeasname"
].__setitem__, ].__setitem__,
json.dumps(ss), json.dumps(key),
), ),
), ),
) )
@ -529,7 +529,7 @@ class hookselect(closeashidewindow):
[ [
QStandardItem(), QStandardItem(),
QStandardItem(), QStandardItem(),
QStandardItem("%s %s %x:%x" % (ss[-2], ss[-1], ss[-3], ss[-4])), QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)),
QStandardItem(), QStandardItem(),
], ],
) )
@ -541,7 +541,7 @@ class hookselect(closeashidewindow):
rown, rown,
[ [
QStandardItem(), QStandardItem(),
QStandardItem("%s %s %x:%x" % (ss[-2], ss[-1], ss[-3], ss[-4])), QStandardItem("%s %s %x:%x" % (hn, hc, tp.ctx, tp.ctx2)),
QStandardItem(), QStandardItem(),
], ],
) )
@ -551,7 +551,7 @@ class hookselect(closeashidewindow):
self.tttable.setIndexWidget( self.tttable.setIndexWidget(
self.ttCombomodelmodel.index(rown, 0), self.selectionbutton[rown] self.ttCombomodelmodel.index(rown, 0), self.selectionbutton[rown]
) )
if ss[-1][0] == "E": if hc[0] == "E":
embedw, hlay = getformlayoutw(cls=QHBoxLayout) embedw, hlay = getformlayoutw(cls=QHBoxLayout)
label = QLabel() label = QLabel()
hlay.addWidget(label) hlay.addWidget(label)
@ -566,11 +566,11 @@ class hookselect(closeashidewindow):
if _isusing: if _isusing:
_text = "取消内嵌翻译" _text = "取消内嵌翻译"
if ss[-2][:8] == "UserHook": if hn[:8] == "UserHook":
needinserthookcode = savehook_new_data[ needinserthookcode = savehook_new_data[
gobject.baseobject.textsource.pname gobject.baseobject.textsource.pname
]["needinserthookcode"] ]["needinserthookcode"]
needinserthookcode = list(set(needinserthookcode + [ss[-1]])) needinserthookcode = list(set(needinserthookcode + [hc]))
savehook_new_data[gobject.baseobject.textsource.pname].update( savehook_new_data[gobject.baseobject.textsource.pname].update(
{"needinserthookcode": needinserthookcode} {"needinserthookcode": needinserthookcode}
) )
@ -739,14 +739,14 @@ class hookselect(closeashidewindow):
r = self.tttable.currentIndex().row() r = self.tttable.currentIndex().row()
if r < 0: if r < 0:
return return
hook = self.save[r] hc, hn, tp = self.save[r]
if action == remove: if action == remove:
pid = hook[0] pid = tp.processId
addr = hook[1] addr = tp.addr
gobject.baseobject.textsource.removehook(pid, addr) gobject.baseobject.textsource.removehook(pid, addr)
elif action == copy: elif action == copy:
copyhook = hook[-1] copyhook = hc
if copyhook[0] == "E": if copyhook[0] == "E":
copyhook = copyhook[copyhook.find("H") :] copyhook = copyhook[copyhook.find("H") :]
winsharedutils.clipboard_set(copyhook) winsharedutils.clipboard_set(copyhook)
@ -924,7 +924,7 @@ class hookselect(closeashidewindow):
pass pass
savehook_new_data[gobject.baseobject.textsource.pname].update( savehook_new_data[gobject.baseobject.textsource.pname].update(
{"hook": gobject.baseobject.textsource.selectedhook} {"hook": gobject.baseobject.textsource.serialselectedhook()}
) )
except: except:
print_exc() print_exc()
@ -972,10 +972,10 @@ class hookselect(closeashidewindow):
try: try:
# print(gobject.baseobject.textsource) # print(gobject.baseobject.textsource)
gobject.baseobject.textsource.selectinghook = self.save[index.row()] gobject.baseobject.textsource.selectinghook = self.save[index.row()]
pid, addr, ctx1, ctx2, _, _ = self.save[index.row()] hc, hn, tp = self.save[index.row()]
self.textOutput.setPlainText( self.textOutput.setPlainText(
gobject.baseobject.textsource.QueryThreadHistory(pid, addr, ctx1, ctx2) gobject.baseobject.textsource.QueryThreadHistory(tp)
) )
self.textOutput.moveCursor(QTextCursor.End) self.textOutput.moveCursor(QTextCursor.End)

View File

@ -193,12 +193,7 @@ class texthook(basetext):
self.Luna_QueryThreadHistory.argtypes = (ThreadParam,) self.Luna_QueryThreadHistory.argtypes = (ThreadParam,)
self.Luna_QueryThreadHistory.restype = c_void_p self.Luna_QueryThreadHistory.restype = c_void_p
def QueryThreadHistory(self, pid, addr, ctx1, ctx2): def QueryThreadHistory(self, tp):
tp = ThreadParam()
tp.addr = addr
tp.processId = pid
tp.ctx = ctx1
tp.ctx2 = ctx2
ws = self.Luna_QueryThreadHistory(tp) ws = self.Luna_QueryThreadHistory(tp)
string = cast(ws, c_wchar_p).value string = cast(ws, c_wchar_p).value
self.Luna_FreePtr(ws) self.Luna_FreePtr(ws)
@ -209,7 +204,7 @@ class texthook(basetext):
ProcessEvent(self.onprocconnect), ProcessEvent(self.onprocconnect),
ProcessEvent(self.connectedpids.remove), ProcessEvent(self.connectedpids.remove),
ThreadEvent(self.onnewhook), ThreadEvent(self.onnewhook),
ThreadEvent(lambda _1, _2, tp: self.onremovehook(tp)), ThreadEvent(self.onremovehook),
OutputCallback(self.handle_output), OutputCallback(self.handle_output),
ConsoleHandler(gobject.baseobject.hookselectdialog.sysmessagesignal.emit), ConsoleHandler(gobject.baseobject.hookselectdialog.sysmessagesignal.emit),
HookInsertHandler(self.newhookinsert), HookInsertHandler(self.newhookinsert),
@ -309,43 +304,32 @@ class texthook(basetext):
True, True,
) )
def onremovehook(self, tp): def onremovehook(self, hc, hn, tp):
toremove = [] key = (hc, hn.decode('utf8'), tp)
for key in self.hookdatacollecter:
if key[1] == tp.addr:
toremove.append(key)
for key in toremove:
gobject.baseobject.hookselectdialog.removehooksignal.emit(key)
self.hookdatacollecter.pop(key) self.hookdatacollecter.pop(key)
gobject.baseobject.hookselectdialog.removehooksignal.emit(key)
def parsetextthread(self, hc, hn, tp): def match_compatibility(self, tp, hc, autostarthookcode):
key = (tp.processId, tp.addr, tp.ctx, tp.ctx2, hn.decode("ascii"), hc) base = (tp.ctx & 0xFFFF, tp.ctx2 & 0xFFFF, hc) == (
return key
def match_compatibility(self, key, autostarthookcode):
base = (key[2] & 0xFFFF, key[3] & 0xFFFF, key[5]) == (
autostarthookcode[2] & 0xFFFF, autostarthookcode[2] & 0xFFFF,
autostarthookcode[3] & 0xFFFF, autostarthookcode[3] & 0xFFFF,
autostarthookcode[5], autostarthookcode[5],
) )
name = ( name = (hc[:8] == "UserHook" and autostarthookcode[-1][:8] == "UserHook") or (
key[-1][:8] == "UserHook" and autostarthookcode[-1][:8] == "UserHook" hc == autostarthookcode[-1]
) or (key[-1] == autostarthookcode[-1]) )
return base and name return base and name
def onnewhook(self, hc, hn, tp): def onnewhook(self, hc, hn, tp):
key = (hc, hn.decode("utf8"), tp)
key = self.parsetextthread(hc, hn, tp)
if self.isremoveuseless: if self.isremoveuseless:
if key[1] not in [_[1] for _ in self.autostarthookcode]: if tp.addr not in [_[1] for _ in self.autostarthookcode]:
self.Luna_RemoveHook(key[0], key[1]) self.Luna_RemoveHook(tp.processId, tp.addr)
return False return False
select = False select = False
for _i, autostarthookcode in enumerate(self.autostarthookcode): for _i, autostarthookcode in enumerate(self.autostarthookcode):
if self.match_compatibility(key, autostarthookcode): if self.match_compatibility(tp, hc, autostarthookcode):
self.selectedhook += [key] self.selectedhook += [key]
self.selectinghook = key self.selectinghook = key
select = True select = True
@ -353,9 +337,7 @@ class texthook(basetext):
self.hookdatacollecter[key] = [] self.hookdatacollecter[key] = []
self.hooktypecollecter[key] = 0 self.hooktypecollecter[key] = 0
gobject.baseobject.hookselectdialog.addnewhooksignal.emit( gobject.baseobject.hookselectdialog.addnewhooksignal.emit(key, select)
key, select, [hc, hn, tp]
)
return True return True
def setsettings(self): def setsettings(self):
@ -451,14 +433,10 @@ class texthook(basetext):
collector = [] collector = []
def handle_output(self, hc, hn, tp, output): def handle_output(self, hc, hn, tp, output):
key = self.parsetextthread(hc, hn, tp)
if globalconfig["filter_chaos_code"] and checkchaos(output): if globalconfig["filter_chaos_code"] and checkchaos(output):
return False return False
key = (hc, hn.decode("utf8"), tp)
if key not in self.hookdatacollecter:
if self.onnewhook(hc, hn, tp) == False:
return False
if self.hooktypecollecter[key] == 1: if self.hooktypecollecter[key] == 1:
self.currentname = output self.currentname = output
@ -478,6 +456,12 @@ class texthook(basetext):
return True return True
def serialselectedhook(self):
xx = []
for hc, hn, tp in self.selectedhook:
xx.append((tp.processId, tp.addr, tp.ctx, tp.ctx2, hn, hc))
return xx
def checkisusingembed(self, address, ctx1, ctx2): def checkisusingembed(self, address, ctx1, ctx2):
for pid in self.connectedpids: for pid in self.connectedpids:
if self.Luna_checkisusingembed(pid, address, ctx1, ctx2): if self.Luna_checkisusingembed(pid, address, ctx1, ctx2):

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 2) set(VERSION_MAJOR 2)
set(VERSION_MINOR 50) set(VERSION_MINOR 50)
set(VERSION_PATCH 1) set(VERSION_PATCH 2)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)