From 472e0deea1473154a18d70a7d6bd0e25e3378a69 Mon Sep 17 00:00:00 2001 From: Netanel Cohen Date: Thu, 6 Jun 2024 15:37:13 +0300 Subject: [PATCH] hilda_client: Add `set_selected_thread` --- hilda/common.py | 9 +++++++++ hilda/hilda_client.py | 9 +++++++-- requirements.txt | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hilda/common.py b/hilda/common.py index 06b76fe..8585407 100644 --- a/hilda/common.py +++ b/hilda/common.py @@ -1,5 +1,14 @@ from datetime import datetime from typing import Any, List, Mapping, Tuple, Union +import inquirer3 +from inquirer3.themes import GreenPassion + CfSerializable = Union[ Mapping[str, Any], List, Tuple[Any, ...], str, bool, float, bytes, datetime, None] + + +def selection_prompt(options_list: List): + question = [inquirer3.List('choice', message='choose device', choices=options_list, carousel=True)] + result = inquirer3.prompt(question, theme=GreenPassion(), raise_keyboard_interrupt=True) + return result['choice'] diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index 58e2d41..ab7f13b 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -30,7 +30,7 @@ from traitlets.config import Config from hilda import objective_c_class -from hilda.common import CfSerializable +from hilda.common import CfSerializable, selection_prompt from hilda.exceptions import AccessingMemoryError, AccessingRegisterError, AddingLldbSymbolError, \ BrokenLocalSymbolsJarError, ConvertingFromNSObjectError, ConvertingToNsObjectError, CreatingObjectiveCSymbolError, \ DisableJetsamMemoryChecksError, EvaluatingExpressionError, HildaException, SymbolAbsentError @@ -510,7 +510,7 @@ def callback(hilda, frame, bp_loc, options): if options.get('name', False): name = options['name'] - log_message = f'🚨 #{bp.id} 0x{symbol:x} {name}' + log_message = f'🚨 #{bp.id} 0x{symbol:x} {name} - Thread #{self.thread.idx}:{hex(self.thread.id)}' if 'regs' in options: log_message += '\nregs:' @@ -880,6 +880,11 @@ def import_module(self, filename: str, name: Optional[str] = None) -> Any: spec.loader.exec_module(m) return m + def set_selected_thread(self, idx: int = None): + if idx is None: + idx = selection_prompt(self.process.threads).idx + self.process.SetSelectedThread(self.process.threads[idx - 1]) + def unwind(self) -> bool: """ Unwind the stack (useful when get_evaluation_unwind() == False) """ return self.thread.UnwindInnermostExpression().Success() diff --git a/requirements.txt b/requirements.txt index 379a896..f9977e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ objc_types_decoder construct pymobiledevice3 keystone-engine -tabulate \ No newline at end of file +tabulate +inquirer3 \ No newline at end of file