mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-11 20:27:38 +02:00
Refactor the way that plugins are imported for use on other modules (such as the upcoming automagic).
This commit is contained in:
+4
-4
@@ -8,11 +8,11 @@ import logging
|
||||
import pdb
|
||||
|
||||
import volatility.framework.symbols.windows.extensions
|
||||
import volatility.plugins
|
||||
from volatility import framework
|
||||
from volatility.framework import contexts
|
||||
from volatility.framework import layers, plugins
|
||||
from volatility.framework import contexts, layers
|
||||
from volatility.framework.interfaces import objects
|
||||
from volatility.framework.symbols import vtypes, native
|
||||
from volatility.framework.symbols import native, vtypes
|
||||
from volatility.framework.symbols.windows import xp_sp2_x86_vtypes
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ def test_plugin():
|
||||
if __name__ == '__main__':
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
plugins.import_plugins()
|
||||
framework.import_files(volatility.plugins)
|
||||
# import timeit
|
||||
# print(timeit.Timer(main).timeit(10))
|
||||
try:
|
||||
|
||||
@@ -5,10 +5,7 @@ import sys
|
||||
import volatility.framework
|
||||
import volatility.plugins
|
||||
from volatility.cli import argparse_adapter
|
||||
from volatility.framework import plugins, contexts
|
||||
from volatility.framework.automagic import windows as windows_automagic
|
||||
from volatility.framework.configuration import depresolver
|
||||
from volatility.framework.configuration.depresolver import DependencyError
|
||||
from volatility.framework import configuration, contexts
|
||||
from volatility.framework.renderers.text import TextRenderer
|
||||
|
||||
__author__ = 'mike'
|
||||
@@ -25,10 +22,10 @@ class CommandLine(object):
|
||||
ver = volatility.framework.version()
|
||||
sys.stdout.write("Volatility Framework 3 (version " + "{0}.{1}.{2}".format(ver[0], ver[1], ver[2]) + ")\n")
|
||||
|
||||
volatility.framework.require_version(3, 0, 0)
|
||||
volatility.framework.require_version(4, 0, 0)
|
||||
|
||||
# TODO: Get CLI config options
|
||||
plugins.import_plugins()
|
||||
volatility.framework.import_files(volatility.plugins)
|
||||
|
||||
# TODO: Choose a plugin
|
||||
plugin = volatility.plugins.windows.pslist.PsList
|
||||
|
||||
@@ -48,6 +48,30 @@ def class_subclasses(cls):
|
||||
yield return_value
|
||||
|
||||
|
||||
def import_files(base_module):
|
||||
"""Imports all plugins present under plugins path"""
|
||||
if not isinstance(base_module.__path__, list):
|
||||
raise TypeError("[base_module].__path__ must be a list of paths")
|
||||
for path in base_module.__path__:
|
||||
for root, _, files in os.walk(path, followlinks = True):
|
||||
# TODO: Figure out how to import pycache files
|
||||
if root.endswith("__pycache__"):
|
||||
continue
|
||||
for f in files:
|
||||
if (f.endswith(".py") or f.endswith(".pyc") or f.endswith(".pyo")) and not f.startswith("__"):
|
||||
modpath = os.path.join(root[len(path) + len(os.path.sep):], f[:f.rfind(".")])
|
||||
module = modpath.replace(os.path.sep, ".")
|
||||
if module not in sys.modules:
|
||||
try:
|
||||
vollog.debug("Importing " + base_module.__name__ + "." + module)
|
||||
__import__(base_module.__name__ + "." + module)
|
||||
except ImportError:
|
||||
vollog.warning("Failed to import module " + module + " based on file " + modpath)
|
||||
raise
|
||||
else:
|
||||
vollog.info("Skipping existing module " + module)
|
||||
|
||||
|
||||
# Check the python version to ensure it's suitable
|
||||
if sys.version_info.major != 3 or sys.version_info.minor < 4:
|
||||
raise RuntimeError("Volatility framework requires python version 3.4 or greater")
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
# TODO: Code to import all the py/pyc files available (but not both).
|
||||
# TODO: Code to return a none-instantiated list of plugin classes.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import volatility.plugins as plugins
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def import_plugins():
|
||||
"""Imports all plugins present under plugins path"""
|
||||
if not isinstance(plugins.__path__, list):
|
||||
raise TypeError("Plugins.__path__ must be a list of paths")
|
||||
for path in plugins.__path__:
|
||||
for root, _, files in os.walk(path, followlinks = True):
|
||||
# TODO: Figure out how to import pycache files
|
||||
if root.endswith("__pycache__"):
|
||||
continue
|
||||
for f in files:
|
||||
if (f.endswith(".py") or f.endswith(".pyc") or f.endswith(".pyo")) and not f.startswith("__"):
|
||||
path = os.path.join(root[len(path) + len(os.path.sep):], f[:f.rfind(".")])
|
||||
module = path.replace(os.path.sep, ".")
|
||||
if module not in sys.modules:
|
||||
try:
|
||||
logging.debug("Importing volatility.plugins." + str(module))
|
||||
__import__("volatility.plugins." + str(module))
|
||||
except ImportError:
|
||||
logger.warning("Failed to import module " + str(module) + " based on file " + path)
|
||||
raise
|
||||
else:
|
||||
logger.info("Skipping existing module " + str(module))
|
||||
|
||||
Reference in New Issue
Block a user