From fb5c306649c22df73dadb4a6d180951fd59d27ba Mon Sep 17 00:00:00 2001 From: Netanel Cohen Date: Thu, 29 Jun 2023 01:55:30 -0700 Subject: [PATCH] objective_c_symbol: Add dump option to `show` --- .../rpcclient/darwin/objective_c_symbol.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rpcclient/rpcclient/darwin/objective_c_symbol.py b/src/rpcclient/rpcclient/darwin/objective_c_symbol.py index 639e0417..8ec05e20 100644 --- a/src/rpcclient/rpcclient/darwin/objective_c_symbol.py +++ b/src/rpcclient/rpcclient/darwin/objective_c_symbol.py @@ -1,6 +1,9 @@ +import os from contextlib import suppress from dataclasses import dataclass from functools import partial +from pathlib import Path +from typing import Optional from pygments import highlight from pygments.formatters import TerminalTrueColorFormatter @@ -76,12 +79,19 @@ def reload(self): self.properties = properties_list self.class_ = class_wrapper - def show(self, recursive: bool = False): + def show(self, dump_to: Optional[str] = None, recursive: bool = False): """ Print to terminal the highlighted class description. + :param dump_to: directory to dump. :param recursive: Show methods of super classes. """ - print(highlight(self._to_str(recursive), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native'))) + formatted = self._to_str(recursive) + print(highlight(formatted, ObjectiveCLexer(), TerminalTrueColorFormatter(style='native'))) + + if not dump_to: + return + fn = (Path(dump_to) / f'{self.class_.name}.m').expanduser() + fn.write_text(formatted) def objc_call(self, selector: str, *params, **kwargs): """