From 966d51251e1e51acca6f75dc520d0ef6ed89a482 Mon Sep 17 00:00:00 2001 From: doronz88 Date: Mon, 8 Jul 2024 13:38:25 +0300 Subject: [PATCH 1/2] hilda_client: add `wait_for_module()` --- README.md | 2 ++ hilda/hilda_client.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 399cdeb..7a0a3a4 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,8 @@ Here is a gist of methods you can access from `p`: - sets the currently selected thread, which is used in other parts of the program, such as displaying disassembly or checking registers. This ensures the application focuses on the specified thread for these operations. +- `wait_for_module` + - Wait for a module to be loaded (`dlopen`) by checking if given expression is contained within its filename All these methods are available from the global `p` within the newly created IPython shell. In addition, you may invoke any of the exported APIs described in the [Python API](#python-api) diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index d6f31c3..2252a98 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -1043,6 +1043,24 @@ def add_lldb_symbol(self, symbol: lldb.SBSymbol) -> Symbol: return value + def wait_for_module(self, expression: str) -> None: + """ Wait for a module to be loaded using `dlopen` by matching given expression """ + self.log_info(f'Waiting for module name containing "{expression}" to be loaded') + + def bp(client: HildaClient, frame, bp_loc, options) -> None: + loading_module_name = client.evaluate_expression('$arg1').peek_str() + client.log_info(f'Loading module: {loading_module_name}') + if expression not in loading_module_name: + client.cont() + return + client.finish() + client.log_info(f'Desired module has been loaded: {expression}. Process remains stopped') + bp = bp_loc.GetBreakpoint() + client.remove_hilda_breakpoint(bp.id) + + self.bp('dlopen', bp) + self.cont() + def interact(self, additional_namespace: Optional[typing.Mapping] = None, startup_files: Optional[List[str]] = None) -> None: """ Start an interactive Hilda shell """ From be5e72d771e2ecb15c9630dac5e876e3cda3c988 Mon Sep 17 00:00:00 2001 From: doronz88 Date: Mon, 8 Jul 2024 13:38:48 +0300 Subject: [PATCH 2/2] hilda_client: fix `monitor()` when given symbol is `str` --- hilda/hilda_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index 2252a98..a4c19e2 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -511,7 +511,8 @@ def callback(hilda, frame, bp_loc, options): :param dict options: User defined options. """ bp = bp_loc.GetBreakpoint() - symbol = hilda.breakpoints[bp.id].address # type: Symbol + + symbol = hilda.symbol(hilda.frame.addr.GetLoadAddress(hilda.target)) # type: Symbol # by default, attempt to resolve the symbol name through lldb name = str(symbol.lldb_symbol)