Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dissect/target/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def get(self, path: str) -> FilesystemEntry:
def scandir(self) -> Iterator[DirEntry]:
raise NotADirectoryError(f"'{self.path}' is not a directory")

def open(self) -> BinaryIO:
def open(self, *args, **kwargs) -> BinaryIO:
return VirtualFileHandle(self.entry)

def stat(self, follow_symlinks: bool = True) -> fsutil.stat_result:
Expand Down Expand Up @@ -1118,7 +1118,7 @@ def __init__(self, fs: Filesystem, path: str, entry: str, algo: str = "gzip"):
if self._compressor is None:
raise ValueError(f"Unsupported compression algorithm {algo}")

def open(self) -> BinaryIO:
def open(self, *args, **kwargs) -> BinaryIO:
return self._compressor.open(self.entry, "rb")


Expand Down
3 changes: 2 additions & 1 deletion dissect/target/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
except Exception:
log.debug("Failed to resolve loader path %r", path)
self.absolute_path = path
self.base_path = self.absolute_path.parent
# self.base_path = self.absolute_path.parent
self.parsed_path = parsed_path
self.parsed_query = (
dict(urllib.parse.parse_qsl(parsed_path.query, keep_blank_values=True)) if parsed_path else {}
Expand Down Expand Up @@ -288,4 +288,5 @@ def open(path: str | Path, *, fallbacks: list[type[Loader]] | None = None, **kwa
register("log", "LogLoader")
register("remote", "RemoteLoader")
register("mqtt", "MqttLoader")
register("gzip", "GzipLoader")
register("multiraw", "MultiRawLoader") # Should be last
41 changes: 41 additions & 0 deletions dissect/target/loaders/gzip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from dissect.target.filesystem import VirtualFilesystem
from dissect.target.loader import LOADERS, Loader

if TYPE_CHECKING:
from pathlib import Path

from dissect.target.target import target

GZ_EXT = (".gz",)


class GzipLoader(Loader):
"""Allow loading Gzip compressed files. Actual loading is handled by the normal loaders."""

def __init__(self, path: Path, **kwargs):
super().__init__(path, **kwargs)

@staticmethod
def detect(path: Path) -> bool:
return path.name.lower().endswith(GZ_EXT)

def map(self, target: target.Target) -> None:
filename = self.path.name.removesuffix(".gz")
vfs = VirtualFilesystem()
vfs.map_file(filename, self.path, "gzip")
path = vfs.get(filename)

for candidate in LOADERS:
try:
target.log.info("Testing sub-loader %s", candidate.__name__)
if candidate.detect(path):
self.subloader = candidate(path)
self.subloader.map(target)
break
except Exception as e:
target.log.debug("Failed to use loader %s", candidate)
target.log.debug("", exc_info=e)