diff --git a/src/rpcclient/rpcclient/darwin/objective_c_class.py b/src/rpcclient/rpcclient/darwin/objective_c_class.py index 4eb50c40..2dab2859 100644 --- a/src/rpcclient/rpcclient/darwin/objective_c_class.py +++ b/src/rpcclient/rpcclient/darwin/objective_c_class.py @@ -1,7 +1,7 @@ from collections import namedtuple from functools import partial from pathlib import Path -from typing import Mapping +from typing import Mapping, Optional from pygments import highlight from pygments.formatters import TerminalTrueColorFormatter @@ -85,11 +85,18 @@ def reload(self): objc.Method.from_data(method, self._client) for method in class_description['methods'] ] - def show(self): + def show(self, dump_to: Optional[str] = None): """ Print to terminal the highlighted class description. + :param dump_to: directory to dump. """ - print(highlight(str(self), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native'))) + formatted = str(self) + print(highlight(formatted, ObjectiveCLexer(), TerminalTrueColorFormatter(style='native'))) + + if not dump_to: + return + fn = (Path(dump_to) / f'{self.name}.m').expanduser() + fn.write_text(formatted) def objc_call(self, sel: str, *args, **kwargs): """ diff --git a/src/rpcclient/rpcclient/darwin/objective_c_symbol.py b/src/rpcclient/rpcclient/darwin/objective_c_symbol.py index 639e0417..26d1f38d 100644 --- a/src/rpcclient/rpcclient/darwin/objective_c_symbol.py +++ b/src/rpcclient/rpcclient/darwin/objective_c_symbol.py @@ -1,6 +1,8 @@ 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 +78,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): """