Layers: Allow handler to avoid caching

This commit is contained in:
Mike Auty
2021-02-19 01:17:34 +00:00
parent f562c3e864
commit 8b6c6b604d
+22 -3
View File
@@ -13,7 +13,7 @@ import ssl
import urllib.parse
import urllib.request
import zipfile
from typing import Optional, Any, IO
from typing import Optional, Any, IO, List
from urllib import error
from volatility3 import framework
@@ -79,7 +79,15 @@ class ResourceAccessor(object):
"""Determines whether a URLs contents should be cached"""
parsed_url = urllib.parse.urlparse(url)
return not parsed_url.scheme in ['file', 'jar']
return not parsed_url.scheme in self._non_cached_schemes()
@staticmethod
def _non_cached_schemes() -> List[str]:
"""Returns the list of schemes not to be cached"""
result = ['file']
for clazz in framework.class_subclasses(VolatilityHandler):
result += clazz.non_cached_schemes()
return result
# Current urllib.request.urlopen returns Any, so we do the same
def open(self, url: str, mode: str = "rb") -> Any:
@@ -201,7 +209,14 @@ class ResourceAccessor(object):
return curfile
class JarHandler(urllib.request.BaseHandler):
class VolatilityHandler(urllib.request.BaseHandler):
@classmethod
def non_cached_schemes(cls) -> List[str]:
return []
class JarHandler(VolatilityHandler):
"""Handles the jar scheme for URIs.
Reference used for the schema syntax:
@@ -211,6 +226,10 @@ class JarHandler(urllib.request.BaseHandler):
http://developer.java.sun.com/developer/onlineTraining/protocolhandlers/
"""
@classmethod
def non_cached_schemes(cls) -> List[str]:
return ['jar']
@staticmethod
def default_open(req: urllib.request.Request) -> Optional[Any]:
"""Handles the request if it's the jar scheme."""