From 5a1693b122aec9a6a19f0c6603e9c389fc0c6e35 Mon Sep 17 00:00:00 2001 From: doronz Date: Mon, 16 Oct 2023 10:47:37 +0300 Subject: [PATCH] hilda_client: remove unstable `is_objc_type()` --- hilda/hilda_client.py | 16 +++------ hilda/objective_c_class.py | 3 +- hilda/objective_c_symbol.py | 12 ------- tests/test_hilda_client/test_hilda_client.py | 34 ++----------------- tests/test_symbols/test_objective_c_symbol.py | 16 --------- 5 files changed, 8 insertions(+), 73 deletions(-) diff --git a/hilda/hilda_client.py b/hilda/hilda_client.py index a80b33c..3600dac 100644 --- a/hilda/hilda_client.py +++ b/hilda/hilda_client.py @@ -829,6 +829,10 @@ def unwind(self) -> bool: """ Unwind the stack (useful when get_evaluation_unwind() == False) """ return self.thread.UnwindInnermostExpression().Success() + @cached_property + def pid(self) -> int: + return self.process.GetProcessID() + @property def thread(self): """ Current active thread. """ @@ -982,18 +986,6 @@ def interact(self, additional_namespace: typing.Mapping = None) -> None: IPython.start_ipython(config=config, user_ns=namespace) - def is_objc_type(self, symbol: Symbol) -> bool: - """ - Test if a given symbol represents an objc object - :param symbol: - :return: - """ - try: - self.symbols.CFGetTypeID(symbol) - return True - except EvaluatingExpressionError: - return False - @staticmethod def _add_global(name: str, value: Any, reserved_names=None): if reserved_names is None or name not in reserved_names: diff --git a/hilda/objective_c_class.py b/hilda/objective_c_class.py index 0ab1adb..7fc11f2 100644 --- a/hilda/objective_c_class.py +++ b/hilda/objective_c_class.py @@ -185,8 +185,7 @@ def hook(hilda, frame, bp_loc, options): if 'group_uuid' in bp.options and bp.options.get('group_uuid', '') == options['group_uuid']: hilda.remove_hilda_breakpoint(bp_id) captured = hilda.evaluate_expression('$arg1') - if hilda.is_objc_type(captured): - captured = captured.objc_symbol + captured = captured.objc_symbol hilda.captured_objects[options['name'].split(' ')[0].split('[')[1]] = captured hilda.cont() diff --git a/hilda/objective_c_symbol.py b/hilda/objective_c_symbol.py index aa4ae82..a896350 100644 --- a/hilda/objective_c_symbol.py +++ b/hilda/objective_c_symbol.py @@ -83,16 +83,6 @@ def show(self, recursive: bool = False): """ print(highlight(self._to_str(recursive), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native'))) - def objc_call(self, selector: str, *params): - """ - Make objc_call() from self return ObjectiveCSymbol when it's an objc symbol. - :param selector: Selector to execute. - :param params: Additional parameters. - :return: ObjectiveCSymbol when return type is an objc symbol. - """ - symbol = super(ObjectiveCSymbol, self).objc_call(selector, *params) - return symbol.objc_symbol if self._client.is_objc_type(symbol) else symbol - def _reload_ivars(self, ivars_data): raw_ivars = sorted(ivars_data, key=lambda ivar: ivar['offset']) for i, ivar in enumerate(raw_ivars): @@ -201,8 +191,6 @@ def __getitem__(self, item): # Ivars for ivar in self.ivars: if ivar.name == item: - if self._client.is_objc_type(ivar.value): - return ivar.value.objc_symbol return ivar.value # Properties diff --git a/tests/test_hilda_client/test_hilda_client.py b/tests/test_hilda_client/test_hilda_client.py index 66ec370..4f57b88 100644 --- a/tests/test_hilda_client/test_hilda_client.py +++ b/tests/test_hilda_client/test_hilda_client.py @@ -1,17 +1,6 @@ import pytest from hilda.exceptions import GettingObjectiveCClassError -from hilda.objective_c_symbol import ObjectiveCSymbol -from hilda.symbol import Symbol - - -def test_detecting_objective_c_members(hilda_client): - """ - :param hilda.hilda_client.HildaClient hilda_client: Hilda client. - """ - dictionary = hilda_client.evaluate_expression('@{@"one": @1, @"two": @2}').objc_symbol - assert isinstance(dictionary._used, Symbol) and not isinstance(dictionary._used, ObjectiveCSymbol) - assert isinstance(dictionary.description, ObjectiveCSymbol) def test_get_objc_class_error(hilda_client): @@ -36,9 +25,9 @@ def test_lsof(hilda_client): """ :param hilda.hilda_client.HildaClient hilda_client: Hilda client. """ - temp_dir_url = hilda_client.objc_get_class('NSFileManager').defaultManager().objc_symbol.temporaryDirectory - temp_url = temp_dir_url.URLByAppendingPathComponent_(hilda_client.ns('temp.txt')).objc_symbol - c_file_path = temp_url.path.cString() + temp_dir_url = hilda_client.objc_get_class('NSFileManager').defaultManager().objc_call('temporaryDirectory') + temp_url = temp_dir_url.objc_call('URLByAppendingPathComponent:', hilda_client.ns('temp.txt')).objc_symbol + c_file_path = temp_url.path.objc_call('cString') file_path = c_file_path.peek_str() file_handle = hilda_client.symbols.mkstemp(c_file_path) max_path_len = hilda_client.evaluate_expression('PATH_MAX') @@ -49,20 +38,3 @@ def test_lsof(hilda_client): finally: hilda_client.symbols.close(file_handle) hilda_client.symbols.unlink(file_path) - - -def test_is_objc_type(hilda_client): - """ - :param hilda.hilda_client.HildaClient hilda_client: Hilda client. - """ - file_manager = hilda_client.objc_get_class('NSFileManager').defaultManager() - assert hilda_client.is_objc_type(file_manager) - temp_dir_url = file_manager.objc_symbol.temporaryDirectory.path.cString() - assert not hilda_client.is_objc_type(temp_dir_url) - - -def test_is_objc_type_invalid_address(hilda_client): - """ - :param hilda.hilda_client.HildaClient hilda_client: Hilda client. - """ - assert not hilda_client.is_objc_type(hilda_client.symbol(0)) diff --git a/tests/test_symbols/test_objective_c_symbol.py b/tests/test_symbols/test_objective_c_symbol.py index f0c38ac..319e07a 100644 --- a/tests/test_symbols/test_objective_c_symbol.py +++ b/tests/test_symbols/test_objective_c_symbol.py @@ -80,22 +80,6 @@ def test_call_objective_c_method_by_objc_call(hilda_client): assert not dictionary1.objc_call('isEqualToDictionary:', dictionary2) -def test_call_objective_c_property_returns_objc_object(hilda_client): - """ - :param hilda.hilda_client.HildaClient hilda_client: Hilda client. - """ - dictionary1 = hilda_client.evaluate_expression('@{@"one": @1}').objc_symbol - assert isinstance(dictionary1.description, ObjectiveCSymbol) - - -def test_call_objective_c_method_returns_objc_object(hilda_client): - """ - :param hilda.hilda_client.HildaClient hilda_client: Hilda client. - """ - dictionary1 = hilda_client.evaluate_expression('@{@"one": @1}').objc_symbol - assert isinstance(dictionary1.objectForKey_(hilda_client.ns('one')), ObjectiveCSymbol) - - def test_call_objective_c_method_returns_native_symbol(hilda_client): """ :param hilda.hilda_client.HildaClient hilda_client: Hilda client.