Skip to content
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
4 changes: 2 additions & 2 deletions dissect/evidence/ad1/ad1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from datetime import datetime, timezone
from functools import cached_property
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
from pathlib import Path, PurePosixPath, PureWindowsPath
from typing import TYPE_CHECKING, BinaryIO

from dissect.evidence.ad1.c_ad1 import c_ad1
Expand All @@ -13,6 +13,7 @@

if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import PurePath

EntryType = c_ad1.EntryType
MetaType = c_ad1.MetaType
Expand Down Expand Up @@ -440,7 +441,6 @@ def __repr__(self) -> str:

def convert_ts(value: bytes) -> datetime:
"""Convert an AD1 timestamp to datetime object. Assuming this is UTC."""

# DateCreated does not (always) have ``.%f`` precision.
fmt = "%Y%m%dT%H%M%S.%f" if b"." in value else "%Y%m%dT%H%M%S"
return datetime.strptime(value.decode(), fmt).replace(tzinfo=timezone.utc)
2 changes: 2 additions & 0 deletions dissect/evidence/asdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from dissect.evidence.asdf.asdf import FILE_MAGIC, AsdfSnapshot, AsdfStream, AsdfWriter

__all__ = [
Expand Down
2 changes: 2 additions & 0 deletions dissect/evidence/asdf/stream.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import hashlib
import io
import struct
Expand Down
11 changes: 7 additions & 4 deletions dissect/evidence/exception.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


class Error(Exception):
pass

Expand All @@ -19,16 +22,16 @@ class NotASymlinkError(Error):


class EWFError(Error):
"""Related to EWF (Expert Witness disk image Format)"""
"""Related to EWF (Expert Witness disk image Format)."""


class InvalidSnapshot(Error):
"""Related to ASDF (Acquire Snapshot Data Format)"""
"""Related to ASDF (Acquire Snapshot Data Format)."""


class InvalidBlock(Error):
"""Related to ASDF (Acquire Snapshot Data Format)"""
"""Related to ASDF (Acquire Snapshot Data Format)."""


class UnsupportedVersion(Error):
"""Related to ASDF (Acquire Snapshot Data Format)"""
"""Related to ASDF (Acquire Snapshot Data Format)."""
2 changes: 2 additions & 0 deletions dissect/evidence/tools/asdf/dd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import argparse
import io
import sys
Expand Down
22 changes: 20 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,33 @@ select = [
"SLOT",
"SIM",
"TID",
"TCH",
"TC",
"PTH",
"PLC",
"TRY",
"FLY",
"PERF",
"FURB",
"RUF",
"D"
]
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
ignore = [
"E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003", "PLC0415",
# Ignore some pydocstyle rules for now as they require a larger cleanup
"D1",
"D205",
"D301",
"D417",
# Seems bugged: https://github.com/astral-sh/ruff/issues/16824
"D402",
]
future-annotations = true

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.lint.per-file-ignores]
"tests/_docs/**" = ["INP001"]
Expand All @@ -124,6 +141,7 @@ ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM1
[tool.ruff.lint.isort]
known-first-party = ["dissect.evidence"]
known-third-party = ["dissect"]
required-imports = ["from __future__ import annotations"]

[tool.setuptools.packages.find]
include = ["dissect.*"]
Expand Down
2 changes: 2 additions & 0 deletions tests/_docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

project = "dissect.evidence"

extensions = [
Expand Down
5 changes: 0 additions & 5 deletions tests/test_ad1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

def test_ad1(ad1_basic: BinaryIO) -> None:
"""Test if we can parse a basic non-segmented AD1 file with no file hierarchy."""

fs = ad1.AD1(ad1_basic)
assert fs.segment(0).header.magic == b"ADSEGMENTEDFILE\x00"

Expand All @@ -32,7 +31,6 @@ def test_ad1(ad1_basic: BinaryIO) -> None:

def test_ad1_long(ad1_long: BinaryIO) -> None:
"""Test if we can parse a basic non-segmented AD1 file with long file names."""

fs = ad1.AD1(ad1_long)

assert fs.segment(0).header.magic == b"ADSEGMENTEDFILE\x00"
Expand Down Expand Up @@ -64,7 +62,6 @@ def test_ad1_long(ad1_long: BinaryIO) -> None:

def test_ad1_compressed(ad1_compressed: BinaryIO) -> None:
"""Test if we can parse a non-segmented AD1 file with standard zlib compression."""

fs = ad1.AD1(ad1_compressed)

assert fs.segment(0).header.magic == b"ADSEGMENTEDFILE\x00"
Expand Down Expand Up @@ -110,7 +107,6 @@ def test_ad1_compressed(ad1_compressed: BinaryIO) -> None:
)
def test_ad1_find_files(path: str, expected_files: list[str]) -> None:
"""Test if we correctly find and order segmented AD1 files and do not find .txt or .csv artifact files."""

files = find_files(absolute_path(path))
assert [file.name for file in files] == expected_files

Expand All @@ -121,7 +117,6 @@ def test_ad1_segmented(ad1_segmented: list[Path]) -> None:
References:
- https://github.com/pcbje/pyad1/tree/master/test_data
"""

fs = ad1.AD1(ad1_segmented)

assert len(fs.fh) == 4
Expand Down
6 changes: 5 additions & 1 deletion tests/test_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import zlib
from io import BytesIO
from typing import TYPE_CHECKING

import pytest

from dissect.evidence.asdf.asdf import AsdfSnapshot, AsdfWriter
from dissect.evidence.asdf.asdf import AsdfSnapshot
from dissect.evidence.asdf.stream import CompressedStream, Crc32Stream, HashedStream
from dissect.evidence.exception import InvalidSnapshot

if TYPE_CHECKING:
from dissect.evidence.asdf.asdf import AsdfWriter


def test_asdf(asdf_writer: AsdfWriter) -> None:
asdf_writer.add_bytes(b"\x00" * 0x1000, idx=0, base=0)
Expand Down
2 changes: 0 additions & 2 deletions tests/tools/test_adcrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

def test_adcrypt_passphrase(tmp_path: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test if we can decrypt ADCRYPT AD1 images using the adcrypt tool."""

with caplog.at_level(logging.DEBUG, adcrypt.log.name), monkeypatch.context() as m:
m.setattr(
"sys.argv",
Expand Down Expand Up @@ -46,7 +45,6 @@ def test_adcrypt_passphrase(tmp_path: Path, caplog: pytest.LogCaptureFixture, mo

def test_adcrypt_certificate(tmp_path: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test if we can decrypt ADCRYPT AD1 images using the adcrypt tool."""

with caplog.at_level(logging.DEBUG, adcrypt.log.name), monkeypatch.context() as m:
m.setattr(
"sys.argv",
Expand Down
Loading