From 08531c5859dd304071807a93a484e0640799ec26 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 30 Jan 2018 15:22:33 +0000 Subject: [PATCH 1/2] Gracefully handle non-addurlinfo classes from the opener. --- volatility/framework/layers/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/volatility/framework/layers/__init__.py b/volatility/framework/layers/__init__.py index 1ff4fbf02..4c44c2eee 100644 --- a/volatility/framework/layers/__init__.py +++ b/volatility/framework/layers/__init__.py @@ -11,7 +11,6 @@ import typing import urllib.parse import urllib.request import zipfile -from urllib import request try: import magic @@ -46,7 +45,7 @@ class ResourceAccessor(object): self._progress_callback = progress_callback self._context = context self._cached_files = [] # type: typing.List[str] - self._handlers = list(framework.class_subclasses(request.BaseHandler)) + self._handlers = list(framework.class_subclasses(urllib.request.BaseHandler)) vollog.log(constants.LOGLEVEL_VVV, "Available URL handlers: {}".format(", ".join([x.__name__ for x in self._handlers]))) @@ -70,7 +69,11 @@ class ResourceAccessor(object): if not temp_filename in self._cached_files or not os.path.exists(temp_filename): vollog.info("Caching file at: {}".format(temp_filename)) - content_length = fp.info().get('Content-Length', -1) + try: + content_length = fp.info().get('Content-Length', -1) + except AttributeError: + # If our fp doesn't have an info member, carry on gracefully + content_length = -1 cache_file = open(temp_filename, "wb") count = 0 @@ -138,7 +141,7 @@ class ResourceAccessor(object): return curfile -class JarHandler(request.BaseHandler): +class JarHandler(urllib.request.BaseHandler): """Handles the jar scheme for URIs Reference used for the schema syntax: From 3e3a3a85baf4c8e75665f58c600fed3310b4441a Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 30 Jan 2018 15:22:50 +0000 Subject: [PATCH 2/2] Slightly clean-up magic import errors. --- volatility/framework/layers/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/volatility/framework/layers/__init__.py b/volatility/framework/layers/__init__.py index 4c44c2eee..8f63f2ad5 100644 --- a/volatility/framework/layers/__init__.py +++ b/volatility/framework/layers/__init__.py @@ -6,7 +6,6 @@ import logging import lzma import os import ssl -import sys import typing import urllib.parse import urllib.request @@ -15,7 +14,7 @@ import zipfile try: import magic except ImportError: - pass + magic = None try: import smb.SMBHandler @@ -94,7 +93,7 @@ class ResourceAccessor(object): # Determine whether the file is a particular type of file, and if so, open it as such IMPORTED_MAGIC = False - if 'magic' in sys.modules: + if not magic is None: while True: detected = None try: