mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-11 04:07:39 +02:00
Initial imlementation of a mapping from volatility config trees to Argparse arguments.
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import argparse
|
||||
|
||||
from volatility.cli import argparse_adapter
|
||||
|
||||
__author__ = 'mike'
|
||||
|
||||
import sys
|
||||
@@ -27,6 +31,14 @@ class CommandLine(object):
|
||||
# TODO: Choose a plugin
|
||||
plugin = volatility.plugins.windows.pslist.PsList
|
||||
context = self.handle_plugin_requirements(plugin)
|
||||
parser = argparse.ArgumentParser(prog = 'volatility',
|
||||
description = "An open-source memory forensics framework")
|
||||
argparse_adapter.adapt_config(context.config, parser)
|
||||
|
||||
# Run the argparser
|
||||
parser.parse_args()
|
||||
|
||||
# Validate the requirement
|
||||
|
||||
# Construct the plugin
|
||||
runner = plugin(context)
|
||||
@@ -46,7 +58,6 @@ class CommandLine(object):
|
||||
context = contexts.Context()
|
||||
|
||||
for req in reqs:
|
||||
context.config.add_item(req, plugin.__name__)
|
||||
if isinstance(req, config.TranslationLayerRequirement):
|
||||
# Choose an appropriate LayerFactory (add layer to the req.name so we don't blat the requirement itself
|
||||
namespace = config.namespace_join([plugin.__name__, req.name + "_layer"])
|
||||
@@ -54,13 +65,8 @@ class CommandLine(object):
|
||||
facreqs = factory.requirements()
|
||||
for facreq in facreqs:
|
||||
context.config.add_item(facreq, namespace = namespace)
|
||||
print(facreq.name)
|
||||
|
||||
# TODO: Allow for values to be set
|
||||
for facreq in facreqs:
|
||||
facreq.validate(context)
|
||||
context = factory(context)
|
||||
context.config.get(config.namespace_join([plugin.__name__, req.name])).value = 'intel'
|
||||
else:
|
||||
context.config.add_item(req, plugin.__name__)
|
||||
return context
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import argparse
|
||||
|
||||
from volatility.framework import interfaces
|
||||
|
||||
__author__ = 'mike'
|
||||
|
||||
|
||||
def StoreItemFactory(config_item):
|
||||
class StoreItemAction(argparse.Action):
|
||||
def __init__(self, option_strings, dest, nargs = None, **kwargs):
|
||||
super(StoreItemAction, self).__init__(option_strings, dest, **kwargs)
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string = None):
|
||||
config_item.value = values[0]
|
||||
|
||||
return StoreItemAction
|
||||
|
||||
|
||||
def adapt_config(config, parser, group = None):
|
||||
"""Constructs an argument parser based on a volatility configuration"""
|
||||
if not group and not isinstance(config, interfaces.config.ConfigurationGroup):
|
||||
raise TypeError("adapt_config expects a ConfigurationItem, not a " + type(config).__name__)
|
||||
|
||||
for item in flatten_configuration(config):
|
||||
parser.add_argument("--" + item.replace('.', '-'),
|
||||
default = config[item].default,
|
||||
action = StoreItemFactory(config[item]))
|
||||
|
||||
|
||||
def flatten_configuration(config):
|
||||
output = {}
|
||||
for item in config:
|
||||
if isinstance(config[item], interfaces.config.ConfigurationGroup):
|
||||
for k, v in flatten_configuration(config[item]).items():
|
||||
output[item + "." + k] = v
|
||||
else:
|
||||
output[item] = config[item]
|
||||
return output
|
||||
Reference in New Issue
Block a user