Ghidra is a software reverse engineering (SRE) framework
GP-4786: format GP-4786: running GP-4786: more from review GP-4786: post-review GP-4786: types GP-4786: events listing GP-4786: savingGP-4786: how to pass an arrayGP-4786: exceptionsGP-4786: refresh methodsGP-4786: first half toggleGP-4786: toggle workingGP-4786: combining arb/spc
d-millar7447fc621b9a
diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.pyindex 08670799f3..6ad7d55b28 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py@@ -16,7 +16,7 @@from typing import Dict, List, Optional, Tuplefrom ghidratrace.client import Address, RegVal-from pybag import pydbg+from pybag import pydbg # type: ignorefrom . import utildiff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.pyindex 0840fd585f..ba720d8170 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py@@ -24,15 +24,16 @@ import sysimport timefrom typing import Any, Dict, Generator, Iterable, List, Optional, Sequence, Tuple, Union-from comtypes import c_ulong+# from ctypes import *+from comtypes import c_ulong # type: ignorefrom ghidratrace import schfrom ghidratrace.client import (Client, Address, AddressRange, Lifespan, RegVal,Schedule, Trace, TraceObject, TraceObjectValue,Transaction)from ghidratrace.display import print_tabular_values, wait-from pybag import pydbg, userdbg, kerneldbg-from pybag.dbgeng import core as DbgEng-from pybag.dbgeng import exception+from pybag import pydbg, userdbg, kerneldbg # type: ignore+from pybag.dbgeng import core as DbgEng # type: ignore+from pybag.dbgeng import exception # type: ignorefrom . import util, arch, methods, hooksfrom .dbgmodel.imodelobject import ModelObject, ModelObjectKind@@ -50,9 +51,16 @@ AVAILABLE_PATTERN = AVAILABLES_PATH + AVAILABLE_KEY_PATTERNPROCESSES_PATH = SESSION_PATH + '.Processes'PROCESS_KEY_PATTERN = '[{procnum}]'PROCESS_PATTERN = PROCESSES_PATH + PROCESS_KEY_PATTERN-PROC_BREAKS_PATTERN = PROCESS_PATTERN + '.Debug.Breakpoints'+PROC_DEBUG_PATTERN = PROCESS_PATTERN + '.Debug'+PROC_BREAKS_PATTERN = PROC_DEBUG_PATTERN + '.Breakpoints'PROC_BREAK_KEY_PATTERN = '[{breaknum}]'PROC_BREAK_PATTERN = PROC_BREAKS_PATTERN + PROC_BREAK_KEY_PATTERN+PROC_EVENTS_PATTERN = PROC_DEBUG_PATTERN + '.Events'+PROC_EVENT_KEY_PATTERN = '[{eventnum}]'+PROC_EVENT_PATTERN = PROC_EVENTS_PATTERN + PROC_EVENT_KEY_PATTERN+PROC_EXCS_PATTERN = PROC_DEBUG_PATTERN + '.Exceptions'+PROC_EXC_KEY_PATTERN = '[{eventnum}]'+PROC_EXC_PATTERN = PROC_EXCS_PATTERN + PROC_EXC_KEY_PATTERNENV_PATTERN = PROCESS_PATTERN + '.Environment'THREADS_PATTERN = PROCESS_PATTERN + '.Threads'THREAD_KEY_PATTERN = '[{tnum}]'@@ -1439,6 +1447,168 @@ def ghidra_trace_put_frames() -> None:put_frames()[email protected]_thread+def put_events() -> None:+ nproc = util.selected_process()+ if nproc < 0:+ return++ trace = STATE.require_trace()+ evtspath = PROC_EVENTS_PATTERN.format(procnum=nproc)+ keys = []+ (n_events, n_spec_exc, n_arb_exc) = util.GetNumberEventFilters()+ params = util.GetSpecificFilterParameters(0, n_events)+ for i in range(0, n_events):+ epath = PROC_EVENT_PATTERN.format(procnum=nproc, eventnum=i)+ eobj = trace.create_object(epath)+ keys.append(PROC_EVENT_KEY_PATTERN.format(eventnum=i))+ p = params[i]+ event_name = util.GetEventFilterText(i, p.TextSize)+ event_cmd = util.GetEventFilterCommand(i, p.CommandSize)+ event_arg = util.GetSpecificFilterArgument(i, p.ArgumentSize)+ eobj.set_value('Name', event_name)+ contobj = trace.create_object(epath+".Cont")+ contobj.set_value('_display', "Cont: {}".format(+ util.continue_options[p.ContinueOption]))+ contobj.insert()+ execobj = trace.create_object(epath+".Exec")+ execobj.set_value('_display', "Exec: {}".format(+ util.execution_options[p.ExecutionOption]))+ execobj.insert()+ if event_cmd is not None:+ eobj.set_value('Cmd', event_cmd)+ if event_arg is not None and event_arg != "":+ eobj.set_value('Arg', event_arg)+ eobj.set_value('_display', "{} {}".format(i, event_name))+ eobj.insert()+ trace.proxy_object_path(+ PROC_EVENTS_PATTERN.format(procnum=nproc)).retain_values(keys)+++def ghidra_trace_put_events() -> None:+ """+ Put the event set into the Ghidra trace+ """++ client = STATE.require_client()+ with client.batch() as b:+ put_events()++[email protected]_thread+def put_exceptions() -> None:+ nproc = util.selected_process()+ if nproc < 0:+ return++ trace = STATE.require_trace()+ evtspath = PROC_EXCS_PATTERN.format(procnum=nproc)+ keys = []+ (n_events, n_spec_exc, n_arb_exc) = util.GetNumberEventFilters()+ params = util.GetExceptionFilterParameters(+ n_events, None, n_spec_exc+n_arb_exc)+ for i in range(0, n_spec_exc+n_arb_exc):+ epath = PROC_EXC_PATTERN.format(procnum=nproc, eventnum=i)+ eobj = trace.create_object(epath)+ keys.append(PROC_EXC_KEY_PATTERN.format(eventnum=i))+ p = params[i]+ put_single_exception(eobj, epath, p, n_events, i, i < n_spec_exc)+ trace.proxy_object_path(+ PROC_EXCS_PATTERN.format(procnum=nproc)).retain_values(keys)++[email protected]_thread+def put_single_exception(obj: TraceObject, objpath: str,+ p: DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS,+ offset: int, index: int, specific: bool) -> None:+ exc_name = "None"+ if specific is True:+ exc_name = util.GetEventFilterText(offset + index, p.TextSize)+ obj.set_value('Name', exc_name)+ exc_cmd = util.GetEventFilterCommand(offset + index, p.CommandSize)+ exc_cmd2 = util.GetExceptionFilterSecondCommand(+ offset + index, p.SecondCommandSize)+ exc_code = hex(p.ExceptionCode)+ obj.set_value('Code', exc_code)+ trace = STATE.require_trace()+ contobj = trace.create_object(objpath+".Cont")+ contobj.set_value('_display', "Cont: {}".format(+ util.continue_options[p.ContinueOption]))+ contobj.insert()+ execobj = trace.create_object(objpath+".Exec")+ execobj.set_value('_display', "Exec: {}".format(+ util.execution_options[p.ExecutionOption]))+ execobj.insert()+ if exc_cmd is not None:+ obj.set_value('Cmd', exc_cmd)+ if exc_cmd2 is not None:+ obj.set_value('Cmd2', exc_cmd2)+ obj.set_value('_display', "{} {} [{}]".format(index, exc_name, exc_code))+ obj.insert()+++def ghidra_trace_put_exceptions() -> None:+ """+ Put the event set into the Ghidra trace+ """++ client = STATE.require_client()+ with client.batch() as b:+ put_exceptions()+++def toggle_evt_cont_option(n: int, events: List[DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS]) -> None:+ """+ Toggle the event continue option+ """++ client = STATE.require_client()+ with client.batch() as b:+ option = events[0].ContinueOption+ option = (option+1) % 2+ events[0].ContinueOption = option+ util.SetSpecificFilterParameters(n, 1, events)+++def toggle_evt_exec_option(n: int, events: List[DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS]) -> None:+ """+ Toggle the event execution option+ """++ client = STATE.require_client()+ with client.batch() as b:+ option = events[0].ExecutionOption+ option = (option+1) % 4+ events[0].ExecutionOption = option+ util.SetSpecificFilterParameters(n, 1, events)+++def toggle_exc_cont_option(n: int, events: List[DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS]) -> None:+ """+ Toggle the event continue option+ """++ client = STATE.require_client()+ with client.batch() as b:+ option = events[0].ContinueOption+ option = (option+1) % 2+ events[0].ContinueOption = option+ util.SetExceptionFilterParameters(1, events)+++def toggle_exc_exec_option(n: int, events: List[DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS]) -> None:+ """+ Toggle the event execution option+ """++ client = STATE.require_client()+ with client.batch() as b:+ option = events[0].ExecutionOption+ option = (option+1) % 4+ events[0].ExecutionOption = option+ util.SetExceptionFilterParameters(1, events)++def update_key(np: str, keyval: Tuple[int, ModelObject]) -> Union[int, str]:"""This should set the modified key."""key: Union[int, str] = keyval[0]@@ -1641,7 +1811,7 @@ def ghidra_trace_put_generic(node: TraceObject) -> None:def init_ttd() -> None:# print(f"put_events: {node}")trace = STATE.require_trace()- with trace.open_tx('Init TTDState'):+ with open_tracked_tx('Init TTDState'):ttd = util.ttdnproc = util.selected_process()path = TTD_PATTERN.format(var="curprocess") + ".Lifetime"@@ -1661,7 +1831,7 @@ def init_ttd() -> None:trace.snapshot(description, time=time)-def put_events() -> None:+def put_trace_events() -> None:trace = STATE.require_trace()ttd = util.ttdnproc = util.selected_process()@@ -1700,15 +1870,14 @@ def put_events() -> None:hooks.on_stop()-def ghidra_trace_put_events() -> None:+def ghidra_trace_put_trace_events() -> None:"""Put the event set the Ghidra trace."""-trace, tx = STATE.require_tx()with trace.client.batch() as b:- put_events()+ put_trace_events()-def put_events_custom(prefix: str, cmd: str):+def put_trace_events_custom(prefix: str, cmd: str) -> None:result = util.dbg.cmd("{prefix}.{cmd}".format(prefix=prefix, cmd=cmd))if result.startswith("Error"):print(result)@@ -1766,12 +1935,12 @@ def put_events_custom(prefix: str, cmd: str):hooks.on_stop()-def ghidra_trace_put_events_custom(prefix: str, cmd: str) -> None:+def ghidra_trace_put_trace_events_custom(prefix: str, cmd: str) -> None:"""Generate events by cmd and put them into the Ghidra trace."""trace, tx = STATE.require_tx()with trace.client.batch() as b:- put_events_custom(prefix, cmd)+ put_trace_events_custom(prefix, cmd)def ghidra_trace_put_all() -> None:diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.pyindex b62d64792f..54e775be07 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/hooks.py@@ -22,12 +22,12 @@ import timeimport tracebackfrom typing import Any, Callable, Collection, Dict, Optional, TypeVar, cast-from comtypes.hresult import S_OK-from pybag import pydbg-from pybag.dbgeng import core as DbgEng-from pybag.dbgeng import exception-from pybag.dbgeng.callbacks import EventHandler-from pybag.dbgeng.idebugbreakpoint import DebugBreakpoint+from comtypes.hresult import S_OK # type: ignore+from pybag import pydbg # type: ignore+from pybag.dbgeng import core as DbgEng # type: ignore+from pybag.dbgeng import exception # type: ignore+from pybag.dbgeng.callbacks import EventHandler # type: ignore+from pybag.dbgeng.idebugbreakpoint import DebugBreakpoint # type: ignorefrom ghidratrace.client import Schedule@@ -105,6 +105,8 @@ class ProcessState:self.modules = Falseif first or self.breaks:commands.put_breakpoints()+ commands.put_events()+ commands.put_exceptions()self.breaks = Falsedef record_continued(self) -> None:diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/libraries.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/libraries.pyindex a6ab245987..b0e540b604 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/libraries.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/libraries.py@@ -17,8 +17,8 @@ import ctypesimport osimport platform-import comtypes-import comtypes.client+import comtypes # type: ignore+import comtypes.client # type: ignorefrom ghidradbg import dbgmodel@@ -26,9 +26,9 @@ ctypes.windll.kernel32.SetErrorMode(0x0001 | 0x0002 | 0x8000)try:- from comtypes.gen import DbgMod+ from comtypes.gen import DbgMod # type: ignoreexcept:tlb = os.path.join(dbgmodel.module_locator(), 'tlb', 'dbgmodel.tlb')print(f"Loading TLB: {tlb}")comtypes.client.GetModule(tlb)- from comtypes.gen import DbgMod+ from comtypes.gen import DbgMod # type: ignorediff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.pyindex a72797b549..28afdc19c4 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py@@ -23,8 +23,8 @@ from typing import Annotated, Any, Dict, Optionalfrom ghidratrace import schfrom ghidratrace.client import (MethodRegistry, ParamDesc, Address,AddressRange, Schedule, TraceObject)-from pybag import pydbg-from pybag.dbgeng import core as DbgEng, exception+from pybag import pydbg # type: ignore+from pybag.dbgeng import core as DbgEng, exception # type: ignorefrom . import util, commands@@ -45,7 +45,8 @@ SESSION_PATTERN = extre(SESSIONS_PATTERN, '\\[(?P<snum>\\d*)\\]')AVAILABLE_PATTERN = extre(SESSION_PATTERN, '\\.Available\\[(?P<pid>\\d*)\\]')PROCESSES_PATTERN = extre(SESSION_PATTERN, '\\.Processes')PROCESS_PATTERN = extre(PROCESSES_PATTERN, '\\[(?P<procnum>\\d*)\\]')-PROC_BREAKS_PATTERN = extre(PROCESS_PATTERN, '\\.Debug.Breakpoints')+PROC_DEBUG_PATTERN = extre(PROCESS_PATTERN, '.Debug')+PROC_BREAKS_PATTERN = extre(PROC_DEBUG_PATTERN, '\\.Breakpoints')PROC_BREAKBPT_PATTERN = extre(PROC_BREAKS_PATTERN, '\\[(?P<breaknum>\\d*)\\]')ENV_PATTERN = extre(PROCESS_PATTERN, '\\.Environment')THREADS_PATTERN = extre(PROCESS_PATTERN, '\\.Threads')@@ -56,6 +57,15 @@ REGS_PATTERN0 = extre(THREAD_PATTERN, '\\.Registers')REGS_PATTERN = extre(FRAME_PATTERN, '\\.Registers')MEMORY_PATTERN = extre(PROCESS_PATTERN, '\\.Memory')MODULES_PATTERN = extre(PROCESS_PATTERN, '\\.Modules')+PROC_EVENTS_PATTERN = extre(PROC_DEBUG_PATTERN, '\\.Events')+PROC_EVENT_PATTERN = extre(PROC_EVENTS_PATTERN, '\\[(?P<eventnum>\\d*)\\]')+PROC_EVENT_CONT_PATTERN = extre(PROC_EVENT_PATTERN, '.Cont')+PROC_EVENT_EXEC_PATTERN = extre(PROC_EVENT_PATTERN, '.Exec')+PROC_EXCEPTIONS_PATTERN = extre(PROC_DEBUG_PATTERN, '\\.Exceptions')+PROC_EXCEPTION_PATTERN = extre(+ PROC_EXCEPTIONS_PATTERN, '\\[(?P<excnum>\\d*)\\]')+PROC_EXCEPTION_CONT_PATTERN = extre(PROC_EXCEPTION_PATTERN, '.Cont')+PROC_EXCEPTION_EXEC_PATTERN = extre(PROC_EXCEPTION_PATTERN, '.Exec')def find_availpid_by_pattern(pattern: re.Pattern, object: TraceObject,@@ -187,6 +197,55 @@ def find_bpt_by_obj(object: TraceObject) -> DbgEng.IDebugBreakpoint:return find_bpt_by_pattern(PROC_BREAKBPT_PATTERN, object, "a BreakpointSpec")+def find_evt_by_number(eventnum: int) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ try:+ return util.GetSpecificFilterParameters(eventnum, 1)+ except exception.E_NOINTERFACE_Error:+ raise KeyError(f"Events[{eventnum}] does not exist")+++def find_evt_by_pattern(pattern: re.Pattern, object: TraceObject,+ err_msg: str) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ mat = pattern.fullmatch(object.path)+ if mat is None:+ raise TypeError(f"{object} is not {err_msg}")+ eventnum = int(mat['eventnum'])+ return (eventnum, find_evt_by_number(eventnum))+++def find_evt_cont_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ return find_evt_by_pattern(PROC_EVENT_CONT_PATTERN, object, "as Event")+++def find_evt_exec_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ return find_evt_by_pattern(PROC_EVENT_EXEC_PATTERN, object, "as Event")+++def find_exc_by_number(excnum: int) -> DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS:+ try:+ (n_events, n_spec_exc, n_arb_exc) = util.GetNumberEventFilters()+ return util.GetExceptionFilterParameters(n_events + excnum, None, 1)+ except exception.E_NOINTERFACE_Error:+ raise KeyError(f"Events[{excnum}] does not exist")+++def find_exc_by_pattern(pattern: re.Pattern, object: TraceObject,+ err_msg: str) -> DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS:+ mat = pattern.fullmatch(object.path)+ if mat is None:+ raise TypeError(f"{object} is not {err_msg}")+ excnum = int(mat['excnum'])+ return (excnum, find_exc_by_number(excnum))+++def find_exc_cont_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ return find_exc_by_pattern(PROC_EXCEPTION_CONT_PATTERN, object, "as Exception")+++def find_exc_exec_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:+ return find_exc_by_pattern(PROC_EXCEPTION_EXEC_PATTERN, object, "as Exception")++shared_globals: Dict[str, Any] = dict()@@ -254,6 +313,22 @@ class BreakpointSpec(TraceObject):pass+class EventContainer(TraceObject):+ pass+++class ExceptionContainer(TraceObject):+ pass+++class ContinueOption(TraceObject):+ pass+++class ExecutionOption(TraceObject):+ pass++@REGISTRY.method()# @util.dbg.eng_threaddef execute(cmd: str, to_string: bool = False):@@ -302,6 +377,58 @@ def refresh_breakpoints(node: BreakpointContainer) -> None:commands.ghidra_trace_put_breakpoints()[email protected](action='refresh', display='Refresh Events')+def refresh_events(node: EventContainer) -> None:+ """+ Refresh the list of control events.+ """+ with commands.open_tracked_tx('Refresh Events'):+ commands.ghidra_trace_put_events()++[email protected](action='refresh', display='Refresh Exceptions')+def refresh_exceptions(node: ExceptionContainer) -> None:+ """+ Refresh the list of exceptions.+ """+ with commands.open_tracked_tx('Refresh Exceptions'):+ commands.ghidra_trace_put_exceptions()++[email protected](action='toggle', display='Toggle Execution Option')+def toggle_exec(node: ExecutionOption, enabled: bool) -> None:+ """+ Toggle the execution option+ """+ if "Events" in str(node):+ (n, events) = find_evt_exec_by_obj(node)+ with commands.open_tracked_tx('Toggle Execution Option'):+ commands.toggle_evt_exec_option(n, events)+ commands.ghidra_trace_put_events()+ elif "Exceptions" in str(node):+ (n, events) = find_exc_exec_by_obj(node)+ with commands.open_tracked_tx('Toggle Execution Option'):+ commands.toggle_exc_exec_option(n, events)+ commands.ghidra_trace_put_exceptions()++[email protected](action='toggle', display='Toggle Continue Option')+def toggle_cont(node: ContinueOption, enabled: bool) -> None:+ """+ Toggle the execution option+ """+ if "Events" in str(node):+ (n, events) = find_evt_cont_by_obj(node)+ with commands.open_tracked_tx('Toggle Execution Option'):+ commands.toggle_evt_cont_option(n, events)+ commands.ghidra_trace_put_events()+ elif "Exceptions" in str(node):+ (n, events) = find_exc_cont_by_obj(node)+ with commands.open_tracked_tx('Toggle Execution Option'):+ commands.toggle_exc_cont_option(n, events)+ commands.ghidra_trace_put_exceptions()++@REGISTRY.method(action='refresh', display='Refresh Processes')def refresh_processes(node: ProcessContainer) -> None:"""Refresh the list of processes."""@@ -361,10 +488,12 @@ def refresh_modules(node: ModuleContainer) -> None:@REGISTRY.method(action='refresh', display='Refresh Events')-def refresh_events(node: State) -> None:- """Refresh the events list for a trace."""+def refresh_trace_events(node: State) -> None:+ """+ Refresh the events list for a trace.+ """with commands.open_tracked_tx('Refresh Events'):- commands.ghidra_trace_put_events()+ commands.ghidra_trace_put_trace_events()@util.dbg.eng_thread@@ -723,12 +852,12 @@ def write_reg(frame: StackFrame, name: str, value: bytes) -> None:@REGISTRY.method(display='Refresh Events (custom)', condition=util.dbg.IS_TRACE)@util.dbg.eng_thread-def refresh_events_custom(node: State,- cmd: Annotated[str, ParamDesc(display='Cmd')],- prefix: Annotated[str, ParamDesc(display='Prefix')] = "dx -r2 @$cursession.TTD") -> None:+def refresh_trace_events_custom(node: State,+ cmd: Annotated[str, ParamDesc(display='Cmd')],+ prefix: Annotated[str, ParamDesc(display='Prefix')] = "dx -r2 @$cursession.TTD") -> None:"""Parse TTD objects generated from a LINQ command."""with commands.open_tracked_tx('Put Events (custom)'):- commands.ghidra_trace_put_events_custom(prefix, cmd)+ commands.ghidra_trace_put_trace_events_custom(prefix, cmd)def dbg():diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/schema.xml b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/schema.xmlindex 917fd8c2a0..72d8b60425 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/schema.xml+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/schema.xml@@ -42,6 +42,8 @@<interface name="Aggregate" /><element schema="VOID" /><attribute name="Breakpoints" schema="BreakpointContainer" required="yes" />+ <attribute name="Events" schema="EventContainer" required="yes" />+ <attribute name="Exceptions" schema="ExceptionContainer" required="yes" /><attribute name="_order" schema="INT" hidden="yes" /><attribute schema="VOID" /></schema>@@ -50,6 +52,42 @@<attribute name="_order" schema="INT" hidden="yes" /><attribute schema="ANY" /></schema>+ <schema name="EventContainer" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <element schema="Event" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema>+ <schema name="Event" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <element schema="ANY" />+ <attribute name="Cont" schema="ContinueOption" />+ <attribute name="Exec" schema="ExecutionOption" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema>+ <schema name="ExceptionContainer" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <element schema="Exception" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema>+ <schema name="Exception" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <element schema="ANY" />+ <attribute name="Cont" schema="ContinueOption" />+ <attribute name="Exec" schema="ExecutionOption" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema>+ <schema name="ContinueOption" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <interface name="Togglable" />+ <element schema="VOID" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema>+ <schema name="ExecutionOption" canonical="yes" elementResync="NEVER" attributeResync="NEVER">+ <interface name="Togglable" />+ <element schema="VOID" />+ <attribute name="_order" schema="INT" hidden="yes" />+ <attribute schema="ANY" />+ </schema><schema name="AvailableContainer" canonical="yes" elementResync="ALWAYS" attributeResync="NEVER"><element schema="Attachable" /><attribute name="_order" schema="INT" hidden="yes" />diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/util.py b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/util.pyindex 1c8abe3468..631cc59e52 100644--- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/util.py+++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/util.py@@ -13,11 +13,11 @@# See the License for the specific language governing permissions and# limitations under the License.##-from comtypes.automation import VARIANT+from comtypes.automation import VARIANT # type: ignorefrom ghidratrace.client import Schedulefrom .dbgmodel.imodelobject import ModelObject-from capstone import CsInsn+from capstone import CsInsn # type: ignorefrom _winapi import STILL_ACTIVEfrom collections import namedtuplefrom concurrent.futures import Future@@ -33,18 +33,18 @@ import threadingimport tracebackfrom typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, TypeVar, Union, cast-from comtypes import CoClass, GUID-import comtypes-from comtypes.gen import DbgMod-from comtypes.hresult import S_OK, S_FALSE+from comtypes import CoClass, GUID # type: ignore+import comtypes # type: ignore+from comtypes.gen import DbgMod # type: ignore+from comtypes.hresult import S_OK, S_FALSE # type: ignorefrom ghidradbg.dbgmodel.ihostdatamodelaccess import HostDataModelAccessfrom ghidradbg.dbgmodel.imodelmethod import ModelMethod-from pybag import pydbg, userdbg, kerneldbg, crashdbg-from pybag.dbgeng import core as DbgEng-from pybag.dbgeng import exception-from pybag.dbgeng import util as DbgUtil-from pybag.dbgeng.callbacks import DbgEngCallbacks-from pybag.dbgeng.idebugclient import DebugClient+from pybag import pydbg, userdbg, kerneldbg, crashdbg # type: ignore+from pybag.dbgeng import core as DbgEng # type: ignore+from pybag.dbgeng import exception # type: ignore+from pybag.dbgeng import util as DbgUtil # type: ignore+from pybag.dbgeng.callbacks import DbgEngCallbacks # type: ignore+from pybag.dbgeng.idebugclient import DebugClient # type: ignoreDESCRIPTION_PATTERN = '[{major:X}:{minor:X}] {type}'@@ -717,6 +717,104 @@ def GetExitCode() -> int:return exit_code.value[email protected]_thread+def GetNumberEventFilters() -> Tuple[int, int, int]:+ n_events = c_ulong()+ n_spec_exc = c_ulong()+ n_arb_exc = c_ulong()+ hr = dbg._base._control._ctrl.GetNumberEventFilters(+ byref(n_events), byref(n_spec_exc), byref(n_arb_exc))+ exception.check_err(hr)+ return (n_events.value, n_spec_exc.value, n_arb_exc.value)++[email protected]_thread+def GetEventFilterText(index: int, sz: int) -> str:+ if sz == 0:+ return "Unknown"+ len = c_ulong()+ val = create_string_buffer(sz)+ hr = dbg._base._control._ctrl.GetEventFilterText(+ index, val, sz, byref(len))+ # exception.check_err(hr)+ if hr != 0:+ return "Unknown"+ return val.value[:len.value].decode()++[email protected]_thread+def GetEventFilterCommand(index: int, sz: int) -> Union[str, None]:+ if sz == 0:+ return None+ len = c_ulong()+ val = create_string_buffer(sz)+ hr = dbg._base._control._ctrl.GetEventFilterCommand(+ index, val, sz, byref(len))+ exception.check_err(hr)+ return val.value[:len.value].decode()++[email protected]_thread+def GetExceptionFilterSecondCommand(index: int, sz: int) -> Union[str, None]:+ if sz == 0:+ return None+ len = c_ulong()+ val = create_string_buffer(sz)+ hr = dbg._base._control._ctrl.GetExceptionFilterSecondCommand(+ index, val, sz, byref(len))+ exception.check_err(hr)+ return val.value[:len.value].decode()++[email protected]_thread+def GetSpecificFilterArgument(index: int, sz: int) -> Union[str, None]:+ if sz == 0:+ return None+ len = c_ulong()+ val = create_string_buffer(sz)+ hr = dbg._base._control._ctrl.GetSpecificFilterArgument(+ index, val, sz, byref(len))+ exception.check_err(hr)+ return val.value[:len.value].decode()+++execution_options = ['enabled', 'disabled', 'output', 'ignore']+continue_options = ['handled', 'not handled', 'unknown']++[email protected]_thread+def GetSpecificFilterParameters(start: int, count: int) -> List[DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS]:+ # For reference, this is how you pass an array of structures!+ params = (DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS * count)()+ hr = dbg._base._control._ctrl.GetSpecificFilterParameters(+ start, count, params)+ exception.check_err(hr)+ return params++[email protected]_thread+def SetSpecificFilterParameters(start: int, count: int, parray: List[DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS]) -> None:+ hr = dbg._base._control._ctrl.SetSpecificFilterParameters(+ start, count, parray)+ exception.check_err(hr)++[email protected]_thread+def GetExceptionFilterParameters(start: int, codes, count: int) -> List[DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS]:+ # For reference, this is how you pass an array of structures!+ params = (DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS * count)()+ hr = dbg._base._control._ctrl.GetExceptionFilterParameters(+ count, codes, start, params)+ exception.check_err(hr)+ return params++[email protected]_thread+def SetExceptionFilterParameters(count: int, parray: List[DbgEng._DEBUG_EXCEPTION_FILTER_PARAMETERS]) -> None:+ hr = dbg._base._control._ctrl.SetExceptionFilterParameters(count, parray)+ exception.check_err(hr)++@dbg.eng_threaddef process_list(running: bool = False) -> Union[Iterable[Tuple[int, str, int]], Iterable[Tuple[int]]]: