-
Notifications
You must be signed in to change notification settings - Fork 75
Add AD1 loader and filesystem #1306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
726d4a2
add ad1 loader and filesystem
JSCU-CNI c10f940
Merge branch 'main' into ad1
JSCU-CNI 4b76150
Make AD1 fs and loader work with ADCRYPT
JSCU-CNI b98c23d
prevent confusing error message
JSCU-CNI e3fb209
add tests
JSCU-CNI 72ec8c3
Update dependency
Schamper fbebd0d
Apply suggestions from code review
JSCU-CNI d6caca4
Update dissect/target/loaders/ad1.py
JSCU-CNI 3f59968
Merge branch 'main' into ad1
JSCU-CNI 7d02048
add test
JSCU-CNI dc5c0ad
Merge branch 'main' into ad1
Schamper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from dissect.evidence.ad1.ad1 import find_files | ||
|
|
||
| from dissect.target.filesystems.ad1 import AD1Filesystem | ||
| from dissect.target.loader import Loader | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| from dissect.target.target import Target | ||
|
|
||
|
|
||
| class AD1Loader(Loader): | ||
| """Access Data ``.ad`` loader.""" | ||
|
|
||
| @staticmethod | ||
| def detect(path: Path) -> bool: | ||
| return path.suffix.lower() == ".ad1" | ||
|
|
||
| def map(self, target: Target) -> None: | ||
| """Map the detected segment files as an :class:`AD1Filesystem` to the target. | ||
|
|
||
| Currently does not detect NTFS / case-insensitive filesystems or custom content | ||
| images with multiple sources. | ||
| """ | ||
| try: | ||
| fs = AD1Filesystem(find_files(self.path)) | ||
| target.filesystems.add(fs) | ||
|
|
||
| except ValueError as e: | ||
| target.log.error("Unable to map AD1: %s", e) # noqa: TRY400 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from dissect.evidence.ad1.ad1 import find_files | ||
|
|
||
| from dissect.target.filesystems.ad1 import AD1Filesystem | ||
| from dissect.target.helpers import keychain | ||
| from tests._utils import absolute_path | ||
|
|
||
|
|
||
| def test_ad1_encrypted() -> None: | ||
| """Test if we can open an AD1 ADCRYPT encrypted image using the keychain.""" | ||
|
|
||
| path = absolute_path("_data/filesystems/ad1/encrypted-small.ad1") | ||
| segments = find_files(path) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Failed to unlock ADCRYPT: no key\(s\) provided"): | ||
| AD1Filesystem(segments) | ||
|
|
||
| keychain.register_wildcard_value("invalid") | ||
|
|
||
| with pytest.raises(ValueError, match=r"Failed to unlock ADCRYPT using provided key\(s\)"): | ||
| AD1Filesystem(segments) | ||
|
|
||
| keychain.register_wildcard_value("password") | ||
| fs = AD1Filesystem(segments) | ||
|
|
||
| assert not fs.ad1.is_locked() | ||
| assert list(fs.get("C:/Users/user/Desktop/Data").iterdir()) == [ | ||
| "hello.txt", | ||
| "philipp-pilz-QZ2EQuPpQJs-unsplash.jpg", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pytest | ||
|
|
||
| from dissect.target.exceptions import TargetError | ||
| from dissect.target.helpers import keychain | ||
| from dissect.target.loaders.ad1 import AD1Loader | ||
| from dissect.target.target import Target | ||
| from tests._utils import absolute_path | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("opener"), | ||
| [ | ||
| pytest.param(Target.open, id="target-open"), | ||
| pytest.param(lambda x: next(Target.open_all([x])), id="target-open-all"), | ||
| ], | ||
| ) | ||
| def test_target_open(opener: Callable[[str | Path], Target]) -> None: | ||
| """Test that we correctly use ``AD1Loader`` when opening a ``Target``.""" | ||
|
|
||
| path = absolute_path("_data/filesystems/ad1/encrypted-small.ad1") | ||
|
|
||
| with pytest.raises(TargetError): | ||
| opener(path) | ||
|
|
||
| keychain.register_wildcard_value("password") | ||
| target = opener(path) | ||
|
|
||
| assert isinstance(target._loader, AD1Loader) | ||
| assert target.path == path | ||
| assert target.fs.path("C:/Users/user/Desktop/Data").is_dir() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.