From 06477c4e8c98e3f6d292ceef98ef01a7bf34da4f Mon Sep 17 00:00:00 2001 From: "Jarisch, Ferdinand" Date: Sun, 14 May 2023 20:13:21 +0200 Subject: [PATCH 1/3] feat: Expose entire class object in parsed args --- src/gallia/cli.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gallia/cli.py b/src/gallia/cli.py index 39797e877..5e5e2d2a2 100644 --- a/src/gallia/cli.py +++ b/src/gallia/cli.py @@ -184,7 +184,7 @@ def build_cli( epilog=cls.EPILOG, ) cmd = cls(subparser, config) - subparser.set_defaults(run_func=cmd.entry_point) + subparser.set_defaults(cls_object=cmd) def cmd_show_config( @@ -361,16 +361,13 @@ def cmd_template(args: argparse.Namespace) -> None: print(template.strip()) -def main() -> None: +def build_parser() -> tuple[argparse.ArgumentParser, Config, Path | None]: registry = cmd_registry[:] plugin_cmds = load_command_plugins() if len(plugin_cmds) > 0: registry += plugin_cmds - # Will be set to the correct verbosity later. - setup_logging() - parsers = load_parsers() # Load plugins. @@ -386,9 +383,17 @@ def main() -> None: build_cli(parsers, config, registry) parser = parsers["parser"] + return parser, config, config_path + + +def main() -> None: + parser, config, config_path = build_parser() argcomplete.autocomplete(parser) args = parser.parse_args() + # Will be set to the correct verbosity later. + setup_logging() + if args.show_config: cmd_show_config(args, config, config_path) sys.exit(exitcode.OK) @@ -409,11 +414,11 @@ def main() -> None: cmd_template(args) sys.exit(exitcode.OK) - if not hasattr(args, "run_func"): + if not hasattr(args, "cls_object"): args.help_func() parser.exit(exitcode.USAGE) - sys.exit(args.run_func(args)) + sys.exit(args.cls_object.entry_point(args)) if __name__ == "__main__": From e052f4b4711042dd85e5562fbdd43bf373a68b04 Mon Sep 17 00:00:00 2001 From: "Jarisch, Ferdinand" Date: Mon, 15 May 2023 17:56:37 +0200 Subject: [PATCH 2/3] feat: Expose results of scan sessions and scan services --- src/gallia/commands/scan/uds/services.py | 2 ++ src/gallia/commands/scan/uds/sessions.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/gallia/commands/scan/uds/services.py b/src/gallia/commands/scan/uds/services.py index 0b58c7fb0..d91019883 100644 --- a/src/gallia/commands/scan/uds/services.py +++ b/src/gallia/commands/scan/uds/services.py @@ -81,6 +81,7 @@ def configure_parser(self) -> None: ) async def main(self, args: Namespace) -> None: + self.result: list[tuple[int, int]] = [] self.ecu.max_retry = 1 found: dict[int, dict[int, Any]] = {} @@ -170,6 +171,7 @@ async def main(self, args: Namespace) -> None: for key, value in found.items(): self.logger.result(f"findings in session 0x{key:02X}:") for sid, data in value.items(): + self.result.append((key, sid)) try: self.logger.result( f" [{g_repr(sid)}] {UDSIsoServices(sid).name}: {data}" diff --git a/src/gallia/commands/scan/uds/sessions.py b/src/gallia/commands/scan/uds/sessions.py index a4827e86a..b8568ab22 100644 --- a/src/gallia/commands/scan/uds/sessions.py +++ b/src/gallia/commands/scan/uds/sessions.py @@ -110,6 +110,7 @@ async def recover_stack(self, stack: list[int], use_hooks: bool) -> bool: return True async def main(self, args: Namespace) -> None: + self.result: list[int] = [] found: dict[int, list[list[int]]] = {0: [[0x01]]} positive_results: list[dict[str, Any]] = [] negative_results: list[dict[str, Any]] = [] @@ -237,6 +238,7 @@ async def main(self, args: Namespace) -> None: if session != previous_session: previous_session = session + self.result.append(int(session)) self.logger.result(f"* Session {g_repr(session)} ") if self.db_handler is not None: From 6acd9867d1eb522872246e9ca0c26a6c90d65402 Mon Sep 17 00:00:00 2001 From: "Jarisch, Ferdinand" Date: Mon, 31 Jul 2023 17:26:06 +0200 Subject: [PATCH 3/3] feat(rdbi): Expose results of primitive RDBI --- src/gallia/commands/primitive/uds/read_by_identifier.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gallia/commands/primitive/uds/read_by_identifier.py b/src/gallia/commands/primitive/uds/read_by_identifier.py index f6b2e00d8..8fa4379c4 100644 --- a/src/gallia/commands/primitive/uds/read_by_identifier.py +++ b/src/gallia/commands/primitive/uds/read_by_identifier.py @@ -49,3 +49,7 @@ async def main(self, args: Namespace) -> None: data = resp.data_record self.logger.info(f"hex: {data.hex()}") self.logger.info(f"raw: {repr(data)}") + self.logger.result( + f"{self.ecu.transport.target} responds to {args.data_id:#06x} with {data.hex()}" + ) + self.result = data