From fa2b840b5552c8ad3b4242652acdde362f9e0052 Mon Sep 17 00:00:00 2001 From: k1nd0ne Date: Sat, 18 Nov 2023 15:05:11 +0100 Subject: [PATCH] Object Storage Layer for PR #1037 --- volatility3/framework/layers/objectstorage.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 volatility3/framework/layers/objectstorage.py diff --git a/volatility3/framework/layers/objectstorage.py b/volatility3/framework/layers/objectstorage.py new file mode 100644 index 000000000..28f7a1bd4 --- /dev/null +++ b/volatility3/framework/layers/objectstorage.py @@ -0,0 +1,56 @@ +# This file is Copyright 2022 Volatility Foundation and licensed under the Volatility Software License 1.0 +# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 +# + +import logging +import urllib.parse +from typing import Optional, Any, List + +try: + import s3fs + HAS_S3FS = True +except ImportError: + HAS_S3FS = False + +try: + import gcsfs + HAS_GCSFS = True +except ImportError: + HAS_GCSFS = False + +from volatility3.framework import exceptions +from volatility3.framework.layers import resources + +vollog = logging.getLogger(__file__) + +class S3FileSystemHandler(resources.VolatilityHandler): + if HAS_S3FS: + @classmethod + def non_cached_schemes(cls) -> List[str]: + return ["s3"] + + @staticmethod + def default_open(req: urllib.request.Request) -> Optional[Any]: + """Handles the request if it's the s3 scheme.""" + if req.type == "s3": + object_uri = "://".join(req.full_url.split("://")[1:]) + return s3fs.S3FileSystem().open(object_uri) + else: + raise exceptions.LayerException("s3 requirement is missing.") + + +class GSFileSystemHandler(resources.VolatilityHandler): + if HAS_GCSFS: + @classmethod + def non_cached_schemes(cls) -> List[str]: + return ["gs"] + + @staticmethod + def default_open(req: urllib.request.Request) -> Optional[Any]: + """Handles the request if it's the gs scheme.""" + if req.type == "gs": + object_uri = "://".join(req.full_url.split("://")[1:]) + return gcsfs.GCSFileSystem().open(object_uri) + return None + else: + raise exceptions.LayerException("gcsfs requirement is missing.") \ No newline at end of file