Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tar loader for windows #353

Merged
merged 5 commits into from
Aug 21, 2023
Merged
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
6 changes: 4 additions & 2 deletions dissect/target/loaders/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def map(self, target: target.Target) -> None:
if member.name == ".":
continue

if not member.name.startswith("fs/") and not member.name.startswith("/sysvol"):
if not member.name.startswith(("/fs", "fs/", "/sysvol", "sysvol/")):
if "/" not in volumes:
vol = filesystem.VirtualFilesystem(case_sensitive=True)
vol.tar = self.tar
Expand All @@ -52,8 +52,10 @@ def map(self, target: target.Target) -> None:
volume = volumes["/"]
mname = member.name
else:
if not member.name.startswith("/sysvol"):
if not member.name.startswith(("/sysvol", "sysvol/")):
parts = member.name.replace("fs/", "").split("/")
if parts[0] == "":
parts.pop(0)
else:
parts = member.name.lstrip("/").split("/")
volume_name = parts[0]
Expand Down
Binary file added tests/data/test-windows-fs-c-absolute.tar
Binary file not shown.
Binary file added tests/data/test-windows-fs-c-relative.tar
Binary file not shown.
Binary file added tests/data/test-windows-sysvol-absolute.tar
Binary file not shown.
Binary file added tests/data/test-windows-sysvol-relative.tar
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/test_loaders_tar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

from dissect.target import Target
from dissect.target.loaders.tar import TarLoader
from dissect.target.plugins.os.windows._os import WindowsPlugin

from ._utils import absolute_path

Expand Down Expand Up @@ -44,3 +47,18 @@ def test_tar_loader_compressed_tar_file_with_empty_dir(target_unix):
empty_folder = target_unix.fs.path("test/empty_dir")
assert empty_folder.exists()
assert empty_folder.is_dir()


@pytest.mark.parametrize(
"archive",
[
("data/test-windows-sysvol-absolute.tar"),
("data/test-windows-sysvol-relative.tar"),
("data/test-windows-fs-c-relative.tar"),
("data/test-windows-fs-c-absolute.tar"),
],
)
def test_tar_loader_windows_sysvol_formats(target_default, archive):
loader = TarLoader(absolute_path(archive))
loader.map(target_default)
assert WindowsPlugin(target_default).detect(target_default)