Skip to content

Commit

Permalink
Make the driveletter case insensitive using the TarLoader (#102)
Browse files Browse the repository at this point in the history
-  remove specific mount of c: in conftest.py target_win as `c:` gets mounted during `apply` for windows targets
  • Loading branch information
Miauwkeru committed Dec 12, 2022
1 parent 7c6cf2c commit 1c821d9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
7 changes: 3 additions & 4 deletions dissect/target/loaders/tar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import stat
import tarfile
import logging
from typing import Union
from pathlib import Path
from typing import Union

from dissect.util.stream import BufferedStream

Expand All @@ -11,7 +11,6 @@
from dissect.target.helpers import fsutil, loaderutil
from dissect.target.loader import Loader


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -56,7 +55,7 @@ def map(self, target: target.Target):
parts = member.name.lstrip("/").split("/")
volume_name = parts[0]

if volume_name == "c:":
if volume_name.lower() == "c:":
volume_name = "sysvol"

if volume_name not in volumes:
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tempfile
import pathlib
import tempfile
from io import BytesIO

import pytest
Expand Down Expand Up @@ -90,7 +90,6 @@ def target_win(hive_hklm, fs_win):
mock_target.registry.map_hive("HKEY_LOCAL_MACHINE", hive_hklm)

mock_target.filesystems.add(fs_win)
mock_target.fs.mount("C:", fs_win)
mock_target.apply()

yield mock_target
Expand Down
3 changes: 3 additions & 0 deletions tests/data/uppercase_driveletter.tar
Git LFS file not shown
17 changes: 15 additions & 2 deletions tests/test_loaders_tar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from dissect.target import Target
from dissect.target.loaders.tar import TarLoader


from ._utils import absolute_path


def test_tar_loader_compressed_tar_file(target_win):
def test_tar_loader_compressed_tar_file(target_win: Target):

archive_path = absolute_path("data/test-archive.tar.gz")

Expand All @@ -17,3 +17,16 @@ def test_tar_loader_compressed_tar_file(target_win):

assert test_file.exists()
assert test_file.open().read() == b"test-value\n"


def test_tar_sensitive_drive_letter(target_win: Target):

tar_file = absolute_path("data/uppercase_driveletter.tar")

loader = TarLoader(tar_file)
loader.map(target_win)

assert len(target_win.fs.mounts) == 2
assert "C:" not in target_win.fs.mounts.keys()
assert target_win.fs.get("C:/test.file").open().read() == b"hello_world"
assert target_win.fs.get("c:/test.file").open().read() == b"hello_world"
2 changes: 1 addition & 1 deletion tests/test_tools_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def test_target_cli_ls(target_win, capsys, monkeypatch):
cli.onecmd("ls")

captured = capsys.readouterr()
assert captured.out == "\n".join(["C:", "sysvol"]) + "\n"
assert captured.out == "\n".join(["c:", "sysvol"]) + "\n"

0 comments on commit 1c821d9

Please sign in to comment.