1414import urllib .parse
1515import urllib .request
1616import zipfile
17- from typing import Any , IO , List , Optional
17+ from typing import IO , Any , List , Optional
1818from urllib import error
1919
2020from volatility3 import framework
2727except ImportError :
2828 HAS_MAGIC = False
2929
30+ try :
31+ import zstd
32+
33+ ZSTD_SUPPORTED = True
34+ except ImportError :
35+ ZSTD_SUPPORTED = False
36+
3037try :
3138 # Import so that the handler is found by the framework.class_subclasses callc
3239 from smb import SMBHandler as SMBHandler # lgtm [py/unused-import]
@@ -232,21 +239,26 @@ def open(self, url: str, mode: str = "rb") -> Any:
232239 # Only file's python has magic.detect_from_fobj
233240
234241 if detected :
242+ inside_compressed_file = False
235243 if detected .mime_type == "application/x-xz" :
236244 curfile = cascadeCloseFile (
237245 lzma .LZMAFile (curfile , mode ), curfile
238246 )
247+ inside_compressed_file = True
239248 elif detected .mime_type == "application/x-bzip2" :
240249 curfile = cascadeCloseFile (bz2 .BZ2File (curfile , mode ), curfile )
250+ inside_compressed_file = True
241251 elif detected .mime_type == "application/x-gzip" :
242252 curfile = cascadeCloseFile (
243253 gzip .GzipFile (fileobj = curfile , mode = mode ), curfile
244254 )
245- if detected .mime_type in [
246- "application/x-xz" ,
247- "application/x-bzip2" ,
248- "application/x-gzip" ,
249- ]:
255+ inside_compressed_file = True
256+ elif detected .mime_type == "application/zstd" and ZSTD_SUPPORTED :
257+ curfile = cascadeCloseFile (
258+ zstd .ZstdFile (fileobj = curfile , mode = mode ), curfile
259+ )
260+ inside_compressed_file = True
261+ if inside_compressed_file :
250262 # Read and rewind to ensure we're inside any compressed file layers
251263 curfile .read (1 )
252264 curfile .seek (0 )
@@ -272,6 +284,10 @@ def open(self, url: str, mode: str = "rb") -> Any:
272284 curfile = cascadeCloseFile (
273285 gzip .GzipFile (fileobj = curfile , mode = mode ), curfile
274286 )
287+ elif extension == "zstd" and ZSTD_SUPPORTED :
288+ curfile = cascadeCloseFile (
289+ zstd .ZstdFile (fileobj = curfile , mode = mode ), curfile
290+ )
275291 else :
276292 stop = True
277293
0 commit comments