From 5528f8f86c9e23f1b6dd3cb2ce5457ac6eaddd1e Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Wed, 13 Nov 2019 22:06:40 +0000 Subject: [PATCH] CLI: Don't output the title for structured output. --- volatility/cli/__init__.py | 7 ++++++- volatility/cli/text_renderer.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/volatility/cli/__init__.py b/volatility/cli/__init__.py index 9cad7491e..86c320ac3 100644 --- a/volatility/cli/__init__.py +++ b/volatility/cli/__init__.py @@ -77,7 +77,6 @@ class CommandLine(interfaces.plugins.FileConsumerInterface): def run(self): """Executes the command line module, taking the system arguments, determining the plugin to run and then running it.""" - sys.stdout.write("Volatility 3 Framework {}\n".format(constants.PACKAGE_VERSION)) volatility.framework.require_interface_version(1, 0, 0) @@ -144,6 +143,12 @@ class CommandLine(interfaces.plugins.FileConsumerInterface): # processed the plugin choice or had the plugin subparser added. known_args = [arg for arg in sys.argv if arg != '--help' and arg != '-h'] partial_args, _ = parser.parse_known_args(known_args) + + banner_output = sys.stdout + if renderers[partial_args.renderer].structured_output: + banner_output = sys.stderr + banner_output.write("Volatility 3 Framework {}\n".format(constants.PACKAGE_VERSION)) + if partial_args.plugin_dirs: volatility.plugins.__path__ = [os.path.abspath(p) for p in partial_args.plugin_dirs.split(";")] + constants.PLUGINS_PATH diff --git a/volatility/cli/text_renderer.py b/volatility/cli/text_renderer.py index 37d092e2c..e3b356e5b 100644 --- a/volatility/cli/text_renderer.py +++ b/volatility/cli/text_renderer.py @@ -107,6 +107,7 @@ def display_disassembly(disasm: interfaces.renderers.Disassembly) -> str: class CLIRenderer(interfaces.renderers.Renderer): """Class to add specific requirements for CLI renderers.""" name = "unnamed" + structured_output = False class QuickTextRenderer(CLIRenderer): @@ -176,6 +177,7 @@ class CSVRenderer(CLIRenderer): } name = "csv" + structured_output = True def get_render_options(self): pass @@ -192,7 +194,7 @@ class CSVRenderer(CLIRenderer): for column in grid.columns: # Ignore the type because namedtuples don't realize they have accessible attributes line.append("{}".format('"' + column.name + '"')) - outfd.write("\n{}".format(",".join(line))) + outfd.write("{}".format(",".join(line))) def visitor(node, accumulator): accumulator.write("\n") @@ -218,6 +220,7 @@ class PrettyTextRenderer(CLIRenderer): _type_renderers = QuickTextRenderer._type_renderers name = "pretty" + structured_output = True def get_render_options(self): pass