dissect.evidence 3.10.dev3__tar.gz → 3.11.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dissect_evidence-3.10.dev3/dissect.evidence.egg-info → dissect_evidence-3.11.dev1}/PKG-INFO +2 -2
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/ad1.py +26 -26
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/asdf/asdf.py +12 -9
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/ewf.py +6 -15
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/exceptions.py +0 -10
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/dd.py +31 -29
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/meta.py +24 -19
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/repair.py +40 -37
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/verify.py +22 -10
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1/dissect.evidence.egg-info}/PKG-INFO +2 -2
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/SOURCES.txt +1 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/pyproject.toml +48 -5
- dissect_evidence-3.11.dev1/tests/__init__.py +0 -0
- dissect_evidence-3.11.dev1/tests/conftest.py +47 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/test_ad1.py +7 -4
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/test_asdf.py +14 -12
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/test_ewf.py +6 -3
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tox.ini +4 -10
- dissect_evidence-3.10.dev3/tests/conftest.py +0 -41
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/COPYRIGHT +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/LICENSE +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/MANIFEST.in +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/README.md +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/__init__.py +1 -1
- /dissect_evidence-3.10.dev3/dissect/evidence/tools/__init__.py → /dissect_evidence-3.11.dev1/dissect/evidence/aff4.py +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/asdf/__init__.py +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/asdf/streams.py +0 -0
- {dissect_evidence-3.10.dev3/dissect/evidence/tools/asdf → dissect_evidence-3.11.dev1/dissect/evidence/tools}/__init__.py +0 -0
- {dissect_evidence-3.10.dev3/tests → dissect_evidence-3.11.dev1/dissect/evidence/tools/asdf}/__init__.py +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/dependency_links.txt +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/entry_points.txt +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/requires.txt +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/top_level.txt +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/setup.cfg +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/data/ad1_long.ad1 +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/data/ad1_test.ad1 +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/data/ad1_test_compressed.ad1 +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/data/ewf.E01 +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/docs/Makefile +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/docs/conf.py +0 -0
- {dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/docs/index.rst +0 -0
{dissect_evidence-3.10.dev3/dissect.evidence.egg-info → dissect_evidence-3.11.dev1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: dissect.evidence
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.dev1
|
|
4
4
|
Summary: A Dissect module implementing a parsers for various forensic evidence file containers, currently: AD1, ASDF and EWF
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Affero General Public License v3
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import zlib
|
|
4
|
+
from typing import Any, BinaryIO
|
|
2
5
|
|
|
3
6
|
from dissect.cstruct import cstruct
|
|
4
7
|
from dissect.util.stream import AlignedStream, RelativeStream
|
|
@@ -91,7 +94,7 @@ MetaType = c_ad1.MetaType
|
|
|
91
94
|
|
|
92
95
|
|
|
93
96
|
class AD1:
|
|
94
|
-
def __init__(self, fh):
|
|
97
|
+
def __init__(self, fh: BinaryIO):
|
|
95
98
|
self.fh = fh
|
|
96
99
|
self.header = c_ad1.SegmentedFileHeader(fh)
|
|
97
100
|
|
|
@@ -99,13 +102,13 @@ class AD1:
|
|
|
99
102
|
self.logical_image = LogicalImage(RelativeStream(fh, offset))
|
|
100
103
|
self.root = self.logical_image
|
|
101
104
|
|
|
102
|
-
def __getattr__(self, k):
|
|
105
|
+
def __getattr__(self, k: str) -> Any:
|
|
103
106
|
if k in self.header.__class__.fields:
|
|
104
107
|
return getattr(self.header, k)
|
|
105
108
|
|
|
106
109
|
return super().__getattr__(k)
|
|
107
110
|
|
|
108
|
-
def entry(self, path=""):
|
|
111
|
+
def entry(self, path: str = "") -> LogicalImage | FileEntry:
|
|
109
112
|
components = path.lstrip("/").split("/")
|
|
110
113
|
current = self.root
|
|
111
114
|
|
|
@@ -120,37 +123,34 @@ class AD1:
|
|
|
120
123
|
if current.name == components[-1]:
|
|
121
124
|
return current
|
|
122
125
|
|
|
123
|
-
raise IOError("Path not found:
|
|
126
|
+
raise IOError(f"Path not found: {path}")
|
|
124
127
|
|
|
125
|
-
def listdir(self, path):
|
|
128
|
+
def listdir(self, path: str) -> list[FileEntry]:
|
|
126
129
|
return [e.name for e in self.entry(path).children]
|
|
127
130
|
|
|
128
|
-
def get(self, path):
|
|
131
|
+
def get(self, path: str) -> LogicalImage | FileEntry:
|
|
129
132
|
return self.entry(path)
|
|
130
133
|
|
|
131
|
-
def open(self, path):
|
|
134
|
+
def open(self, path: str) -> FileObject:
|
|
132
135
|
return self.entry(path).open()
|
|
133
136
|
|
|
134
|
-
def walk(self):
|
|
135
|
-
raise NotImplementedError()
|
|
136
|
-
|
|
137
137
|
|
|
138
138
|
class LogicalImage:
|
|
139
|
-
def __init__(self, fh):
|
|
139
|
+
def __init__(self, fh: BinaryIO):
|
|
140
140
|
self.fh = fh
|
|
141
141
|
self.header = c_ad1.LogicalImageHeader(fh)
|
|
142
142
|
|
|
143
143
|
self.children = []
|
|
144
144
|
offset = self.header.entry_offset
|
|
145
145
|
while offset != 0:
|
|
146
|
-
child = FileEntry(self, offset
|
|
146
|
+
child = FileEntry(self, offset)
|
|
147
147
|
offset = child.entry.next
|
|
148
148
|
self.children.append(child)
|
|
149
149
|
|
|
150
|
-
def __repr__(self):
|
|
150
|
+
def __repr__(self) -> str:
|
|
151
151
|
return f"<LogicalImage name={self.header.name}>"
|
|
152
152
|
|
|
153
|
-
def __getattr__(self, k):
|
|
153
|
+
def __getattr__(self, k: str) -> Any:
|
|
154
154
|
if k in self.header.__class__.fields:
|
|
155
155
|
return getattr(self.header, k)
|
|
156
156
|
|
|
@@ -158,7 +158,7 @@ class LogicalImage:
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
class FileEntry:
|
|
161
|
-
def __init__(self, image, offset
|
|
161
|
+
def __init__(self, image: LogicalImage, offset: int):
|
|
162
162
|
fh = image.fh
|
|
163
163
|
fh.seek(offset)
|
|
164
164
|
self.image = image
|
|
@@ -176,11 +176,11 @@ class FileEntry:
|
|
|
176
176
|
self.children = []
|
|
177
177
|
offset = self.entry.child
|
|
178
178
|
while offset != 0:
|
|
179
|
-
child = FileEntry(image, offset
|
|
179
|
+
child = FileEntry(image, offset)
|
|
180
180
|
offset = child.entry.next
|
|
181
181
|
self.children.append(child)
|
|
182
182
|
|
|
183
|
-
def __repr__(self):
|
|
183
|
+
def __repr__(self) -> str:
|
|
184
184
|
file_type = "Unknown type"
|
|
185
185
|
if self.is_file():
|
|
186
186
|
file_type = "File"
|
|
@@ -188,34 +188,34 @@ class FileEntry:
|
|
|
188
188
|
file_type = "Directory"
|
|
189
189
|
return f"<{file_type} name={self.entry.name}>"
|
|
190
190
|
|
|
191
|
-
def __getattr__(self, k):
|
|
191
|
+
def __getattr__(self, k: str) -> Any:
|
|
192
192
|
if k in self.entry.__class__.fields:
|
|
193
193
|
return getattr(self.entry, k)
|
|
194
194
|
|
|
195
195
|
return object.__getattribute__(self, k)
|
|
196
196
|
|
|
197
|
-
def open(self):
|
|
197
|
+
def open(self) -> FileObject:
|
|
198
198
|
return FileObject(self)
|
|
199
199
|
|
|
200
|
-
def is_file(self):
|
|
200
|
+
def is_file(self) -> bool:
|
|
201
201
|
return self.entry.type == EntryType.File
|
|
202
202
|
|
|
203
|
-
def is_dir(self):
|
|
203
|
+
def is_dir(self) -> bool:
|
|
204
204
|
return self.entry.type == EntryType.Directory
|
|
205
205
|
|
|
206
206
|
|
|
207
207
|
class FileMeta:
|
|
208
|
-
def __init__(self, image, offset):
|
|
208
|
+
def __init__(self, image: LogicalImage, offset: int):
|
|
209
209
|
fh = image.fh
|
|
210
210
|
fh.seek(offset)
|
|
211
211
|
self.image = image
|
|
212
212
|
self.offset = offset
|
|
213
213
|
self.entry = c_ad1.FileMeta(fh)
|
|
214
214
|
|
|
215
|
-
def __repr__(self):
|
|
215
|
+
def __repr__(self) -> str:
|
|
216
216
|
return f"<Meta category={self.entry.category} type={self.entry.type} data={self.entry.data}>"
|
|
217
217
|
|
|
218
|
-
def __getattr__(self, k):
|
|
218
|
+
def __getattr__(self, k: str) -> Any:
|
|
219
219
|
if k in self.entry.__class__.fields:
|
|
220
220
|
return getattr(self.entry, k)
|
|
221
221
|
|
|
@@ -223,11 +223,11 @@ class FileMeta:
|
|
|
223
223
|
|
|
224
224
|
|
|
225
225
|
class FileObject(AlignedStream):
|
|
226
|
-
def __init__(self, entry):
|
|
226
|
+
def __init__(self, entry: FileEntry):
|
|
227
227
|
self.entry = entry
|
|
228
228
|
super().__init__(self.entry.size, self.entry.image.chunk_size)
|
|
229
229
|
|
|
230
|
-
def _read(self, offset, length):
|
|
230
|
+
def _read(self, offset: int, length: int) -> bytes:
|
|
231
231
|
r = []
|
|
232
232
|
fh = self.entry.image.fh
|
|
233
233
|
chunk_size = self.entry.image.chunk_size
|
|
@@ -9,7 +9,7 @@ import tarfile
|
|
|
9
9
|
import uuid
|
|
10
10
|
from bisect import bisect_right
|
|
11
11
|
from collections import defaultdict
|
|
12
|
-
from typing import BinaryIO, Callable
|
|
12
|
+
from typing import TYPE_CHECKING, BinaryIO, Callable
|
|
13
13
|
|
|
14
14
|
from dissect.cstruct import cstruct
|
|
15
15
|
from dissect.util import ts
|
|
@@ -22,6 +22,9 @@ from dissect.evidence.exceptions import (
|
|
|
22
22
|
UnsupportedVersion,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from collections.abc import Iterator
|
|
27
|
+
|
|
25
28
|
SnapshotTableEntry = tuple[int, int, int, int]
|
|
26
29
|
|
|
27
30
|
VERSION = 1
|
|
@@ -107,7 +110,7 @@ class AsdfWriter(io.RawIOBase):
|
|
|
107
110
|
def __init__(
|
|
108
111
|
self,
|
|
109
112
|
fh: BinaryIO,
|
|
110
|
-
guid: uuid.UUID = None,
|
|
113
|
+
guid: uuid.UUID | None = None,
|
|
111
114
|
compress: bool = False,
|
|
112
115
|
block_crc: bool = True,
|
|
113
116
|
):
|
|
@@ -129,11 +132,11 @@ class AsdfWriter(io.RawIOBase):
|
|
|
129
132
|
self._table_offset = 0
|
|
130
133
|
|
|
131
134
|
self._meta_buf = io.BytesIO()
|
|
132
|
-
self._meta_tar = tarfile.open(fileobj=self._meta_buf, mode="w")
|
|
135
|
+
self._meta_tar = tarfile.open(fileobj=self._meta_buf, mode="w") # noqa: SIM115
|
|
133
136
|
|
|
134
137
|
self._write_header()
|
|
135
138
|
|
|
136
|
-
def add_metadata_file(self, path: str, fh: BinaryIO, size:
|
|
139
|
+
def add_metadata_file(self, path: str, fh: BinaryIO, size: int | None = None) -> None:
|
|
137
140
|
"""Add a file to the metadata stream.
|
|
138
141
|
|
|
139
142
|
Args:
|
|
@@ -190,7 +193,7 @@ class AsdfWriter(io.RawIOBase):
|
|
|
190
193
|
source: BinaryIO,
|
|
191
194
|
offset: int,
|
|
192
195
|
num_blocks: int,
|
|
193
|
-
block_size:
|
|
196
|
+
block_size: int | None = None,
|
|
194
197
|
idx: int = 0,
|
|
195
198
|
base: int = 0,
|
|
196
199
|
) -> None:
|
|
@@ -214,7 +217,7 @@ class AsdfWriter(io.RawIOBase):
|
|
|
214
217
|
def copy_runlist(
|
|
215
218
|
self,
|
|
216
219
|
source: BinaryIO,
|
|
217
|
-
runlist: list[tuple[
|
|
220
|
+
runlist: list[tuple[int | None, int]],
|
|
218
221
|
runlist_block_size: int,
|
|
219
222
|
idx: int = 0,
|
|
220
223
|
base: int = 0,
|
|
@@ -450,12 +453,12 @@ class AsdfSnapshot:
|
|
|
450
453
|
raise IndexError(f"invalid stream idx: {idx}")
|
|
451
454
|
return AsdfStream(self, idx)
|
|
452
455
|
|
|
453
|
-
def streams(self) -> AsdfStream:
|
|
456
|
+
def streams(self) -> Iterator[AsdfStream]:
|
|
454
457
|
"""Iterate over all streams in the file."""
|
|
455
458
|
for i in sorted(self.table.keys()):
|
|
456
459
|
yield self.open(i)
|
|
457
460
|
|
|
458
|
-
def disks(self) -> AsdfStream:
|
|
461
|
+
def disks(self) -> Iterator[AsdfStream]:
|
|
459
462
|
"""Iterate over all non-reserved streams in the file."""
|
|
460
463
|
for i in sorted(self.table.keys()):
|
|
461
464
|
if i in RESERVED_IDX:
|
|
@@ -475,7 +478,7 @@ class Metadata:
|
|
|
475
478
|
def __init__(self, asdf: AsdfSnapshot):
|
|
476
479
|
self.tar = None
|
|
477
480
|
if IDX_METADATA in asdf.table:
|
|
478
|
-
self.tar = tarfile.open(fileobj=asdf.open(IDX_METADATA), mode="r")
|
|
481
|
+
self.tar = tarfile.open(fileobj=asdf.open(IDX_METADATA), mode="r") # noqa: SIM115
|
|
479
482
|
|
|
480
483
|
def names(self) -> list[str]:
|
|
481
484
|
"""Return all metadata file entries."""
|
|
@@ -6,7 +6,7 @@ import zlib
|
|
|
6
6
|
from bisect import bisect_right
|
|
7
7
|
from functools import lru_cache
|
|
8
8
|
from pathlib import Path
|
|
9
|
-
from typing import BinaryIO
|
|
9
|
+
from typing import BinaryIO
|
|
10
10
|
|
|
11
11
|
from dissect.cstruct import cstruct
|
|
12
12
|
from dissect.util.stream import AlignedStream
|
|
@@ -105,7 +105,7 @@ c_ewf = cstruct().load(ewf_def)
|
|
|
105
105
|
MAX_OPEN_SEGMENTS = 128
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
def find_files(path:
|
|
108
|
+
def find_files(path: str | Path) -> list[Path]:
|
|
109
109
|
"""Find all related EWF files from the given path."""
|
|
110
110
|
if not isinstance(path, Path):
|
|
111
111
|
path = Path(path)
|
|
@@ -116,10 +116,7 @@ def find_files(path: Union[str, Path]) -> list[Path]:
|
|
|
116
116
|
if ext[1].upper() not in "ELS":
|
|
117
117
|
raise EWFError(f"Invalid EWF file: {path}")
|
|
118
118
|
|
|
119
|
-
if len(ext) == 4
|
|
120
|
-
ewfglob = f"[{ext[1]}-{'Z' if ext[1].isupper() else 'z'}]"
|
|
121
|
-
else:
|
|
122
|
-
ewfglob = f"{ext[1]}[x-z]"
|
|
119
|
+
ewfglob = f"[{ext[1]}-{'Z' if ext[1].isupper() else 'z'}]" if len(ext) == 4 else f"{ext[1]}[x-z]"
|
|
123
120
|
|
|
124
121
|
return sorted(path.parent.glob(f"{path.stem}.{ewfglob}[0-9A-Za-z][0-9A-Za-z]"))
|
|
125
122
|
|
|
@@ -127,7 +124,7 @@ def find_files(path: Union[str, Path]) -> list[Path]:
|
|
|
127
124
|
class EWF:
|
|
128
125
|
"""Expert Witness Disk Image Format."""
|
|
129
126
|
|
|
130
|
-
def __init__(self, fh:
|
|
127
|
+
def __init__(self, fh: BinaryIO | list[BinaryIO]):
|
|
131
128
|
fhs = [fh] if not isinstance(fh, list) else fh
|
|
132
129
|
|
|
133
130
|
self.fh = fhs
|
|
@@ -189,10 +186,7 @@ class EWF:
|
|
|
189
186
|
|
|
190
187
|
fh = self.fh[idx]
|
|
191
188
|
if not hasattr(fh, "read"):
|
|
192
|
-
if isinstance(fh, Path):
|
|
193
|
-
fh = fh.open("rb")
|
|
194
|
-
else:
|
|
195
|
-
fh = open(fh, "rb")
|
|
189
|
+
fh = fh.open("rb") if isinstance(fh, Path) else Path(fh).open("rb") # noqa: SIM115
|
|
196
190
|
|
|
197
191
|
segment = Segment(self, fh)
|
|
198
192
|
if self.volume and 0 < idx <= len(self._segment_offsets):
|
|
@@ -344,10 +338,7 @@ class VolumeSection:
|
|
|
344
338
|
|
|
345
339
|
fh = segment.fh
|
|
346
340
|
fh.seek(section.data_offset)
|
|
347
|
-
if section.size ==
|
|
348
|
-
data = c_ewf.EWFVolumeSection(fh)
|
|
349
|
-
else:
|
|
350
|
-
data = c_ewf.EWFVolumeSectionSpec(fh)
|
|
341
|
+
data = c_ewf.EWFVolumeSection(fh) if section.size == 1052 else c_ewf.EWFVolumeSectionSpec(fh)
|
|
351
342
|
|
|
352
343
|
self.volume = data
|
|
353
344
|
self.chunk_count = data.chunk_count
|
|
@@ -2,28 +2,18 @@ class Error(Exception):
|
|
|
2
2
|
"""Base class for exceptions for this module.
|
|
3
3
|
It is used to recognize errors specific to this module"""
|
|
4
4
|
|
|
5
|
-
pass
|
|
6
|
-
|
|
7
5
|
|
|
8
6
|
class EWFError(Error):
|
|
9
7
|
"""Related to EWF (Expert Witness disk image Format)"""
|
|
10
8
|
|
|
11
|
-
pass
|
|
12
|
-
|
|
13
9
|
|
|
14
10
|
class InvalidSnapshot(Error):
|
|
15
11
|
"""Related to ASDF (Acquire Snapshot Data Format)"""
|
|
16
12
|
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
13
|
|
|
20
14
|
class InvalidBlock(Error):
|
|
21
15
|
"""Related to ASDF (Acquire Snapshot Data Format)"""
|
|
22
16
|
|
|
23
|
-
pass
|
|
24
|
-
|
|
25
17
|
|
|
26
18
|
class UnsupportedVersion(Error):
|
|
27
19
|
"""Related to ASDF (Acquire Snapshot Data Format)"""
|
|
28
|
-
|
|
29
|
-
pass
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
import io
|
|
3
3
|
import sys
|
|
4
|
+
from contextlib import nullcontext
|
|
5
|
+
from pathlib import Path
|
|
4
6
|
from typing import BinaryIO
|
|
5
7
|
|
|
6
8
|
from dissect.evidence.asdf import asdf
|
|
7
9
|
|
|
8
10
|
try:
|
|
9
|
-
from tqdm import tqdm
|
|
11
|
+
from tqdm import tqdm # type: ignore
|
|
10
12
|
|
|
11
13
|
HAS_TQDM = True
|
|
12
14
|
except ImportError:
|
|
@@ -45,7 +47,7 @@ def fill_zero(fhout: BinaryIO, length: int) -> None:
|
|
|
45
47
|
fhout.write(b"\x00" * remain)
|
|
46
48
|
|
|
47
49
|
|
|
48
|
-
def main():
|
|
50
|
+
def main() -> int:
|
|
49
51
|
parser = argparse.ArgumentParser(description="Utility to dump ASDF streams")
|
|
50
52
|
parser.add_argument("file", metavar="ASDF", help="ASDF file to dd")
|
|
51
53
|
parser.add_argument("-w", "--writer", default="-", help="file to write to, default is stdout")
|
|
@@ -57,43 +59,43 @@ def main():
|
|
|
57
59
|
global HAS_TQDM
|
|
58
60
|
HAS_TQDM = False
|
|
59
61
|
|
|
60
|
-
with
|
|
62
|
+
with Path(args.file).open("rb") as fh:
|
|
61
63
|
snapshot = asdf.AsdfSnapshot(fh)
|
|
62
64
|
|
|
63
65
|
if args.stream > 255 or not snapshot.contains(args.stream):
|
|
64
66
|
parser.print_help()
|
|
65
67
|
print(file=sys.stderr)
|
|
66
68
|
|
|
67
|
-
valid_keys = ", ".join(str(i) for i in snapshot.table
|
|
68
|
-
parser.exit(f"invalid stream index, must be one of {valid_keys}")
|
|
69
|
+
valid_keys = ", ".join(str(i) for i in snapshot.table)
|
|
70
|
+
parser.exit(1, f"invalid stream index, must be one of {valid_keys}")
|
|
69
71
|
|
|
70
72
|
stream = snapshot.open(args.stream)
|
|
71
73
|
progress = Progress(stream.size)
|
|
72
74
|
|
|
73
|
-
if args.writer == "-"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
fhout
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
progress.close()
|
|
94
|
-
if args.writer != "-":
|
|
95
|
-
fhout.close()
|
|
75
|
+
ctx = nullcontext(getattr(sys.stdout, "buffer", sys.stdout)) if args.writer == "-" else None
|
|
76
|
+
with ctx or Path(args.writer).open("wb") as fhout:
|
|
77
|
+
try:
|
|
78
|
+
prev_offset = 0
|
|
79
|
+
for offset, size, _, data_offset in stream.table:
|
|
80
|
+
stream.fh.seek(data_offset)
|
|
81
|
+
if fhout.seekable():
|
|
82
|
+
fhout.seek(offset)
|
|
83
|
+
else:
|
|
84
|
+
fill_zero(fhout, offset - prev_offset)
|
|
85
|
+
copy_stream(stream.fh, fhout, size)
|
|
86
|
+
|
|
87
|
+
progress.update(offset)
|
|
88
|
+
prev_offset = offset
|
|
89
|
+
except BrokenPipeError:
|
|
90
|
+
pass
|
|
91
|
+
finally:
|
|
92
|
+
progress.close()
|
|
93
|
+
|
|
94
|
+
return 0
|
|
96
95
|
|
|
97
96
|
|
|
98
97
|
if __name__ == "__main__":
|
|
99
|
-
|
|
98
|
+
try:
|
|
99
|
+
sys.exit(main())
|
|
100
|
+
except KeyboardInterrupt:
|
|
101
|
+
pass
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/meta.py
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import argparse
|
|
2
4
|
import datetime
|
|
3
5
|
import hashlib
|
|
@@ -5,39 +7,37 @@ import io
|
|
|
5
7
|
import shutil
|
|
6
8
|
import stat
|
|
7
9
|
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
8
12
|
|
|
9
13
|
from dissect.evidence.asdf import asdf
|
|
10
14
|
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from collections.abc import Iterator
|
|
17
|
+
|
|
11
18
|
|
|
12
|
-
def iterfileobj(src):
|
|
19
|
+
def iterfileobj(src: BinaryIO) -> Iterator[bytes]:
|
|
13
20
|
buf = src.read(io.DEFAULT_BUFFER_SIZE)
|
|
14
21
|
while buf:
|
|
15
22
|
yield buf
|
|
16
23
|
buf = src.read(io.DEFAULT_BUFFER_SIZE)
|
|
17
24
|
|
|
18
25
|
|
|
19
|
-
def hashfileobj(src, alg="sha256"):
|
|
26
|
+
def hashfileobj(src: BinaryIO, alg: str = "sha256") -> str:
|
|
20
27
|
ctx = hashlib.new(alg)
|
|
21
28
|
for buf in iterfileobj(src):
|
|
22
29
|
ctx.update(buf)
|
|
23
30
|
return ctx.hexdigest()
|
|
24
31
|
|
|
25
32
|
|
|
26
|
-
def
|
|
27
|
-
"""Helper method for generating a mode string from a numerical mode value."""
|
|
28
|
-
is_dir = "d" if stat.S_ISDIR(mode) else "-"
|
|
29
|
-
dic = {"7": "rwx", "6": "rw-", "5": "r-x", "4": "r--", "0": "---"}
|
|
30
|
-
perm = str(oct(mode)[-3:])
|
|
31
|
-
return is_dir + "".join(dic.get(x, x) for x in perm)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def handle_ls(snapshot, args):
|
|
33
|
+
def handle_ls(snapshot: asdf.AsdfSnapshot, args: argparse.Namespace) -> None:
|
|
35
34
|
for member in snapshot.metadata.members():
|
|
36
|
-
mtime = datetime.datetime.
|
|
37
|
-
print(f"{stat_modestr(member.mode)} {member.size:9d} {mtime} {member.name}")
|
|
35
|
+
mtime = datetime.datetime.fromtimestamp(member.mtime, datetime.timezone.utc).isoformat()
|
|
38
36
|
|
|
37
|
+
print(f"{stat.filemode(member.mode)} {member.size:9d} {mtime} {member.name}")
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
def handle_cat(snapshot: asdf.AsdfSnapshot, args: argparse.Namespace) -> None:
|
|
41
41
|
try:
|
|
42
42
|
fh = snapshot.metadata.open(args.name)
|
|
43
43
|
except Exception:
|
|
@@ -50,12 +50,12 @@ def handle_cat(snapshot, args):
|
|
|
50
50
|
pass
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def handle_hash(snapshot, args):
|
|
53
|
+
def handle_hash(snapshot: asdf.AsdfSnapshot, args: argparse.Namespace) -> None:
|
|
54
54
|
for name in snapshot.metadata.names():
|
|
55
55
|
print(f"{hashfileobj(snapshot.metadata.open(name))} {name}")
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def main():
|
|
58
|
+
def main() -> int:
|
|
59
59
|
parser = argparse.ArgumentParser(description="Utility to work with ASDF metadata")
|
|
60
60
|
parser.add_argument("file", metavar="ASDF", help="ASDF file to verify")
|
|
61
61
|
subparsers = parser.add_subparsers(help="metadata command")
|
|
@@ -72,12 +72,17 @@ def main():
|
|
|
72
72
|
|
|
73
73
|
if not hasattr(args, "handler"):
|
|
74
74
|
parser.print_help()
|
|
75
|
-
|
|
75
|
+
return 1
|
|
76
76
|
|
|
77
|
-
with
|
|
77
|
+
with Path(args.file).open("rb") as fh:
|
|
78
78
|
snapshot = asdf.AsdfSnapshot(fh)
|
|
79
79
|
args.handler(snapshot, args)
|
|
80
80
|
|
|
81
|
+
return 0
|
|
82
|
+
|
|
81
83
|
|
|
82
84
|
if __name__ == "__main__":
|
|
83
|
-
|
|
85
|
+
try:
|
|
86
|
+
sys.exit(main())
|
|
87
|
+
except KeyboardInterrupt:
|
|
88
|
+
pass
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/repair.py
RENAMED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import argparse
|
|
2
4
|
import io
|
|
3
5
|
import shutil
|
|
4
6
|
import sys
|
|
7
|
+
from contextlib import nullcontext
|
|
8
|
+
from pathlib import Path
|
|
5
9
|
|
|
6
10
|
from dissect.evidence.asdf import asdf
|
|
7
11
|
from dissect.evidence.asdf.streams import HashedStream
|
|
8
12
|
|
|
9
13
|
|
|
10
|
-
def main():
|
|
14
|
+
def main() -> int:
|
|
11
15
|
parser = argparse.ArgumentParser(description="Utility to repair block tables of ASDF files")
|
|
12
16
|
parser.add_argument("file", metavar="ASDF", help="ASDF file to repair")
|
|
13
17
|
parser.add_argument("-w", "--writer", default="-", help="file to write to, default is stdout")
|
|
14
18
|
args = parser.parse_args()
|
|
15
19
|
|
|
16
|
-
with
|
|
20
|
+
with Path(args.file).open("rb") as fh:
|
|
17
21
|
header = asdf.c_asdf.header(fh)
|
|
18
22
|
if header.magic != asdf.FILE_MAGIC:
|
|
19
|
-
parser.exit("invalid header magic, is this an ASDF file?")
|
|
23
|
+
parser.exit(1, "invalid header magic, is this an ASDF file?")
|
|
20
24
|
|
|
21
25
|
fh.seek(-len(asdf.c_asdf.footer), io.SEEK_END)
|
|
22
26
|
footer = asdf.c_asdf.footer(fh)
|
|
23
27
|
if footer.magic == asdf.FOOTER_MAGIC:
|
|
24
|
-
parser.exit("ASDF file already has a valid footer, no repair necessary")
|
|
28
|
+
parser.exit(1, "ASDF file already has a valid footer, no repair necessary")
|
|
25
29
|
|
|
26
30
|
fh.seek(len(asdf.c_asdf.header))
|
|
27
31
|
|
|
@@ -48,39 +52,38 @@ def main():
|
|
|
48
52
|
|
|
49
53
|
print(f"[*] Recovered {len(table)} blocks", file=sys.stderr)
|
|
50
54
|
|
|
51
|
-
if args.writer == "-"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
pass
|
|
80
|
-
finally:
|
|
81
|
-
if args.writer != "-":
|
|
82
|
-
fhout.close()
|
|
55
|
+
ctx = nullcontext(getattr(sys.stdout, "buffer", sys.stdout)) if args.writer == "-" else None
|
|
56
|
+
with ctx or Path(args.writer).open("wb") as fhout:
|
|
57
|
+
try:
|
|
58
|
+
print(f"[*] Writing to {args.writer}", file=sys.stderr)
|
|
59
|
+
# Copy the original file
|
|
60
|
+
fh.seek(0)
|
|
61
|
+
fhout = HashedStream(fhout)
|
|
62
|
+
shutil.copyfileobj(fh, fhout)
|
|
63
|
+
|
|
64
|
+
print("[*] Writing block table", file=sys.stderr)
|
|
65
|
+
# Write the block table
|
|
66
|
+
table_offset = fh.tell() # fhout might be stdout which we can't tell() on
|
|
67
|
+
for entry in table:
|
|
68
|
+
entry.write(fhout)
|
|
69
|
+
|
|
70
|
+
print("[*] Writing footer", file=sys.stderr)
|
|
71
|
+
# Write the footer
|
|
72
|
+
asdf.c_asdf.footer(
|
|
73
|
+
magic=asdf.FOOTER_MAGIC,
|
|
74
|
+
table_offset=table_offset,
|
|
75
|
+
sha256=fhout.digest(),
|
|
76
|
+
).write(fhout)
|
|
77
|
+
|
|
78
|
+
print("[*] All done, use asdf-verify to check file", file=sys.stderr)
|
|
79
|
+
except BrokenPipeError:
|
|
80
|
+
pass
|
|
81
|
+
|
|
82
|
+
return 0
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
if __name__ == "__main__":
|
|
86
|
-
|
|
86
|
+
try:
|
|
87
|
+
sys.exit(main())
|
|
88
|
+
except KeyboardInterrupt:
|
|
89
|
+
pass
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect/evidence/tools/asdf/verify.py
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from __future__ import
|
|
1
|
+
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
4
|
import hashlib
|
|
@@ -6,13 +6,17 @@ import io
|
|
|
6
6
|
import sys
|
|
7
7
|
import traceback
|
|
8
8
|
from contextlib import contextmanager
|
|
9
|
-
from
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
10
11
|
from zlib import crc32
|
|
11
12
|
|
|
12
13
|
from dissect.util.stream import RangeStream
|
|
13
14
|
|
|
14
15
|
from dissect.evidence.asdf import asdf
|
|
15
16
|
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from collections.abc import Iterator
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
def iter_fileobj(src: BinaryIO) -> Iterator[bytes]:
|
|
18
22
|
buf = src.read(io.DEFAULT_BUFFER_SIZE)
|
|
@@ -48,7 +52,7 @@ def status(line: str, verbose: bool = False) -> Iterator:
|
|
|
48
52
|
print(f"[!] {e}")
|
|
49
53
|
|
|
50
54
|
|
|
51
|
-
def main():
|
|
55
|
+
def main() -> int:
|
|
52
56
|
parser = argparse.ArgumentParser(description="Utility to verify ASDF files")
|
|
53
57
|
parser.add_argument("file", metavar="ASDF", help="ASDF file to verify")
|
|
54
58
|
parser.add_argument("--skip-hash", action="store_true", help="skip file hash")
|
|
@@ -56,7 +60,7 @@ def main():
|
|
|
56
60
|
parser.add_argument("-v", "--verbose", action="store_true", help="increase verbosity")
|
|
57
61
|
args = parser.parse_args()
|
|
58
62
|
|
|
59
|
-
with
|
|
63
|
+
with Path(args.file).open("rb") as fh:
|
|
60
64
|
header = None
|
|
61
65
|
footer = None
|
|
62
66
|
footer_offset = 0
|
|
@@ -64,7 +68,8 @@ def main():
|
|
|
64
68
|
with status("Checking header", args.verbose):
|
|
65
69
|
header = asdf.c_asdf.header(fh)
|
|
66
70
|
if header.magic != asdf.FILE_MAGIC:
|
|
67
|
-
|
|
71
|
+
print("[!] Invalid header magic")
|
|
72
|
+
return 1
|
|
68
73
|
|
|
69
74
|
with status("Checking footer", args.verbose):
|
|
70
75
|
fh.seek(-len(asdf.c_asdf.footer), io.SEEK_END)
|
|
@@ -72,16 +77,18 @@ def main():
|
|
|
72
77
|
footer = asdf.c_asdf.footer(fh)
|
|
73
78
|
if footer.magic != asdf.FOOTER_MAGIC:
|
|
74
79
|
footer = None
|
|
75
|
-
|
|
80
|
+
print("[!] Invalid footer magic, please run asdf-repair")
|
|
81
|
+
return 1
|
|
76
82
|
|
|
77
83
|
if not args.skip_hash and footer:
|
|
78
84
|
with status("Checking file hash", args.verbose):
|
|
79
85
|
hashstream = RangeStream(fh, 0, footer_offset)
|
|
80
86
|
res = hash_fileobj(hashstream)
|
|
81
87
|
if res != footer.sha256:
|
|
82
|
-
|
|
88
|
+
print(f"[!] File hash doesn't match. Expected {footer.sha256.hex()}, got {res.hex()}")
|
|
89
|
+
return 1
|
|
83
90
|
else:
|
|
84
|
-
print("[
|
|
91
|
+
print("[@] Skipping file hash")
|
|
85
92
|
|
|
86
93
|
if not args.skip_blocks and footer:
|
|
87
94
|
with status("Checking blocks", args.verbose):
|
|
@@ -107,8 +114,13 @@ def main():
|
|
|
107
114
|
print(f"[!] Block {i} crc32 doesn't match. Expected 0x{target_crc:x}, got 0x{crc:x}")
|
|
108
115
|
|
|
109
116
|
else:
|
|
110
|
-
print("[
|
|
117
|
+
print("[@] Skipping block check")
|
|
118
|
+
|
|
119
|
+
return 0
|
|
111
120
|
|
|
112
121
|
|
|
113
122
|
if __name__ == "__main__":
|
|
114
|
-
|
|
123
|
+
try:
|
|
124
|
+
sys.exit(main())
|
|
125
|
+
except KeyboardInterrupt:
|
|
126
|
+
pass
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1/dissect.evidence.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: dissect.evidence
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.dev1
|
|
4
4
|
Summary: A Dissect module implementing a parsers for various forensic evidence file containers, currently: AD1, ASDF and EWF
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Affero General Public License v3
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/SOURCES.txt
RENAMED
|
@@ -12,6 +12,7 @@ dissect.evidence.egg-info/requires.txt
|
|
|
12
12
|
dissect.evidence.egg-info/top_level.txt
|
|
13
13
|
dissect/evidence/__init__.py
|
|
14
14
|
dissect/evidence/ad1.py
|
|
15
|
+
dissect/evidence/aff4.py
|
|
15
16
|
dissect/evidence/ewf.py
|
|
16
17
|
dissect/evidence/exceptions.py
|
|
17
18
|
dissect/evidence/asdf/__init__.py
|
|
@@ -47,13 +47,56 @@ asdf-meta = "dissect.evidence.tools.asdf.meta:main"
|
|
|
47
47
|
asdf-repair = "dissect.evidence.tools.asdf.repair:main"
|
|
48
48
|
asdf-verify = "dissect.evidence.tools.asdf.verify:main"
|
|
49
49
|
|
|
50
|
-
[tool.
|
|
50
|
+
[tool.ruff]
|
|
51
51
|
line-length = 120
|
|
52
|
+
required-version = ">=0.9.0"
|
|
52
53
|
|
|
53
|
-
[tool.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
[tool.ruff.format]
|
|
55
|
+
docstring-code-format = true
|
|
56
|
+
|
|
57
|
+
[tool.ruff.lint]
|
|
58
|
+
select = [
|
|
59
|
+
"F",
|
|
60
|
+
"E",
|
|
61
|
+
"W",
|
|
62
|
+
"I",
|
|
63
|
+
"UP",
|
|
64
|
+
"YTT",
|
|
65
|
+
"ANN",
|
|
66
|
+
"B",
|
|
67
|
+
"C4",
|
|
68
|
+
"DTZ",
|
|
69
|
+
"T10",
|
|
70
|
+
"FA",
|
|
71
|
+
"ISC",
|
|
72
|
+
"G",
|
|
73
|
+
"INP",
|
|
74
|
+
"PIE",
|
|
75
|
+
"PYI",
|
|
76
|
+
"PT",
|
|
77
|
+
"Q",
|
|
78
|
+
"RSE",
|
|
79
|
+
"RET",
|
|
80
|
+
"SLOT",
|
|
81
|
+
"SIM",
|
|
82
|
+
"TID",
|
|
83
|
+
"TCH",
|
|
84
|
+
"PTH",
|
|
85
|
+
"PLC",
|
|
86
|
+
"TRY",
|
|
87
|
+
"FLY",
|
|
88
|
+
"PERF",
|
|
89
|
+
"FURB",
|
|
90
|
+
"RUF",
|
|
91
|
+
]
|
|
92
|
+
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
|
|
93
|
+
|
|
94
|
+
[tool.ruff.lint.per-file-ignores]
|
|
95
|
+
"tests/docs/**" = ["INP001"]
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint.isort]
|
|
98
|
+
known-first-party = ["dissect.evidence"]
|
|
99
|
+
known-third-party = ["dissect"]
|
|
57
100
|
|
|
58
101
|
[tool.setuptools]
|
|
59
102
|
license-files = ["LICENSE", "COPYRIGHT"]
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from dissect.evidence.asdf import AsdfWriter
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from collections.abc import Iterator
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def open_data(name: str) -> Iterator[BinaryIO]:
|
|
16
|
+
with (Path(__file__).parent / name).open("rb") as fh:
|
|
17
|
+
yield fh
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
def ad1_data() -> Iterator[BinaryIO]:
|
|
22
|
+
yield from open_data("data/ad1_test.ad1")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.fixture
|
|
26
|
+
def ad1_data_long() -> Iterator[BinaryIO]:
|
|
27
|
+
yield from open_data("data/ad1_long.ad1")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def ad1_data_compressed() -> Iterator[BinaryIO]:
|
|
32
|
+
yield from open_data("data/ad1_test_compressed.ad1")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def ewf_data() -> Iterator[BinaryIO]:
|
|
37
|
+
yield from open_data("data/ewf.E01")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.fixture
|
|
41
|
+
def asdf_writer() -> AsdfWriter:
|
|
42
|
+
def noop() -> None:
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
fh = BytesIO()
|
|
46
|
+
fh.close = noop # Prevent clearing the buffer, we need it
|
|
47
|
+
return AsdfWriter(fh)
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import hashlib
|
|
4
|
+
from typing import BinaryIO
|
|
2
5
|
|
|
3
6
|
from dissect.evidence import ad1
|
|
4
7
|
|
|
5
8
|
|
|
6
|
-
def test_ad1(ad1_data):
|
|
9
|
+
def test_ad1(ad1_data: BinaryIO) -> None:
|
|
7
10
|
a = ad1.AD1(ad1_data)
|
|
8
11
|
|
|
9
12
|
assert a.header.magic == b"ADSEGMENTEDFILE\x00"
|
|
@@ -13,7 +16,7 @@ def test_ad1(ad1_data):
|
|
|
13
16
|
assert a.root.children[0].open().read() == b"Inhoud document 1"
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
def test_ad1_long(ad1_data_long):
|
|
19
|
+
def test_ad1_long(ad1_data_long: BinaryIO) -> None:
|
|
17
20
|
a = ad1.AD1(ad1_data_long)
|
|
18
21
|
|
|
19
22
|
assert a.header.magic == b"ADSEGMENTEDFILE\x00"
|
|
@@ -30,10 +33,10 @@ def test_ad1_long(ad1_data_long):
|
|
|
30
33
|
b"'g'asldjg';askg\r\nkqe\r\n-["
|
|
31
34
|
)
|
|
32
35
|
md5sum = hashlib.md5(entry.open().read())
|
|
33
|
-
assert md5sum.hexdigest().encode() ==
|
|
36
|
+
assert md5sum.hexdigest().encode() == next(meta for meta in entry.meta if meta.type == ad1.MetaType.MD5).data
|
|
34
37
|
|
|
35
38
|
|
|
36
|
-
def test_ad1_compressed(ad1_data_compressed):
|
|
39
|
+
def test_ad1_compressed(ad1_data_compressed: BinaryIO) -> None:
|
|
37
40
|
a = ad1.AD1(ad1_data_compressed)
|
|
38
41
|
|
|
39
42
|
assert a.root.children[0].open().read() == b"Inhoud document 1"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import zlib
|
|
2
4
|
from io import BytesIO
|
|
3
5
|
|
|
@@ -8,7 +10,7 @@ from dissect.evidence.asdf.streams import CompressedStream, Crc32Stream, HashedS
|
|
|
8
10
|
from dissect.evidence.exceptions import InvalidSnapshot
|
|
9
11
|
|
|
10
12
|
|
|
11
|
-
def test_asdf(asdf_writer: AsdfWriter):
|
|
13
|
+
def test_asdf(asdf_writer: AsdfWriter) -> None:
|
|
12
14
|
asdf_writer.add_bytes(b"\x00" * 0x1000, idx=0, base=0)
|
|
13
15
|
asdf_writer.add_bytes(b"\x02" * 0x1000, idx=0, base=0x4000)
|
|
14
16
|
asdf_writer.add_bytes(b"\x04" * 0x1000, idx=0, base=0x8000)
|
|
@@ -57,7 +59,7 @@ def test_asdf(asdf_writer: AsdfWriter):
|
|
|
57
59
|
assert stream_1.read(0x4000) == (b"\xa5\xdf" * (0x2000 // 2)) + (b"\x08" * 0x1000) + (b"\xa5\xdf" * (0x1000 // 2))
|
|
58
60
|
|
|
59
61
|
|
|
60
|
-
def test_asdf_overlap(asdf_writer: AsdfWriter):
|
|
62
|
+
def test_asdf_overlap(asdf_writer: AsdfWriter) -> None:
|
|
61
63
|
asdf_writer.add_bytes(b"\x01" * 100, base=0)
|
|
62
64
|
asdf_writer.add_bytes(b"\x02" * 100, base=200)
|
|
63
65
|
assert asdf_writer._table_lookup[0] == [0, 200]
|
|
@@ -86,7 +88,7 @@ def test_asdf_overlap(asdf_writer: AsdfWriter):
|
|
|
86
88
|
assert stream.read() == (b"\x01" * 100) + (b"\x03" * 50) + (b"\x04" * 50) + (b"\x02" * 100)
|
|
87
89
|
|
|
88
90
|
|
|
89
|
-
def test_asdf_overlap_all(asdf_writer: AsdfWriter):
|
|
91
|
+
def test_asdf_overlap_all(asdf_writer: AsdfWriter) -> None:
|
|
90
92
|
asdf_writer.add_bytes(b"\x01" * 100, base=0)
|
|
91
93
|
asdf_writer.add_bytes(b"\x02" * 100, base=200)
|
|
92
94
|
asdf_writer.add_bytes(b"\x03" * 100, base=50)
|
|
@@ -108,7 +110,7 @@ def test_asdf_overlap_all(asdf_writer: AsdfWriter):
|
|
|
108
110
|
assert stream.read() == (b"\x01" * 100) + (b"\x06" * 300)
|
|
109
111
|
|
|
110
112
|
|
|
111
|
-
def test_asdf_overlap_contiguous(asdf_writer: AsdfWriter):
|
|
113
|
+
def test_asdf_overlap_contiguous(asdf_writer: AsdfWriter) -> None:
|
|
112
114
|
asdf_writer.add_bytes(b"\x01" * 100, base=0)
|
|
113
115
|
asdf_writer.add_bytes(b"\x02" * 100, base=100)
|
|
114
116
|
assert asdf_writer._table_lookup[0] == [0, 100]
|
|
@@ -129,7 +131,7 @@ def test_asdf_overlap_contiguous(asdf_writer: AsdfWriter):
|
|
|
129
131
|
assert stream.read() == (b"\x01" * 100) + (b"\x02" * 100)
|
|
130
132
|
|
|
131
133
|
|
|
132
|
-
def test_asdf_overlap_seek(asdf_writer: AsdfWriter):
|
|
134
|
+
def test_asdf_overlap_seek(asdf_writer: AsdfWriter) -> None:
|
|
133
135
|
asdf_writer.add_bytes(b"\x00" * 100, base=0)
|
|
134
136
|
asdf_writer.add_bytes(b"\x00" * 100, base=200)
|
|
135
137
|
asdf_writer.add_bytes(bytes(range(200)), base=50)
|
|
@@ -149,7 +151,7 @@ def test_asdf_overlap_seek(asdf_writer: AsdfWriter):
|
|
|
149
151
|
assert stream.read() == (b"\x00" * 100) + bytes(range(50, 150)) + (b"\x00" * 100)
|
|
150
152
|
|
|
151
153
|
|
|
152
|
-
def test_asdf_mid_run(asdf_writer: AsdfWriter):
|
|
154
|
+
def test_asdf_mid_run(asdf_writer: AsdfWriter) -> None:
|
|
153
155
|
asdf_writer.add_bytes(bytes([v & 0xFF for v in range(4096)]), base=0)
|
|
154
156
|
|
|
155
157
|
asdf_writer.close()
|
|
@@ -163,7 +165,7 @@ def test_asdf_mid_run(asdf_writer: AsdfWriter):
|
|
|
163
165
|
assert stream.read(512) == bytes([v & 0xFF for v in range(1100, 1100 + 512)])
|
|
164
166
|
|
|
165
167
|
|
|
166
|
-
def test_asdf_metadata(asdf_writer: AsdfWriter):
|
|
168
|
+
def test_asdf_metadata(asdf_writer: AsdfWriter) -> None:
|
|
167
169
|
asdf_writer.add_metadata_file("file", BytesIO(b"content"))
|
|
168
170
|
asdf_writer.add_metadata_file("dir/file", BytesIO(b"content here too"))
|
|
169
171
|
|
|
@@ -180,7 +182,7 @@ def test_asdf_metadata(asdf_writer: AsdfWriter):
|
|
|
180
182
|
reader.metadata.open("nonexistent")
|
|
181
183
|
|
|
182
184
|
|
|
183
|
-
def test_asdf_stream_crc32():
|
|
185
|
+
def test_asdf_stream_crc32() -> None:
|
|
184
186
|
fh = BytesIO()
|
|
185
187
|
stream = Crc32Stream(fh)
|
|
186
188
|
stream.write(b"srt was here")
|
|
@@ -189,7 +191,7 @@ def test_asdf_stream_crc32():
|
|
|
189
191
|
assert fh.getvalue() == b"srt was here\x2f\x0e\x60\xa4"
|
|
190
192
|
|
|
191
193
|
|
|
192
|
-
def test_asdf_stream_compressed():
|
|
194
|
+
def test_asdf_stream_compressed() -> None:
|
|
193
195
|
fh = BytesIO()
|
|
194
196
|
stream = CompressedStream(fh)
|
|
195
197
|
stream.write(b"srt was here" * 100)
|
|
@@ -198,14 +200,14 @@ def test_asdf_stream_compressed():
|
|
|
198
200
|
assert zlib.decompress(fh.getvalue()) == b"srt was here" * 100
|
|
199
201
|
|
|
200
202
|
|
|
201
|
-
def test_asdf_stream_hashed():
|
|
203
|
+
def test_asdf_stream_hashed() -> None:
|
|
202
204
|
fh = BytesIO()
|
|
203
205
|
stream = HashedStream(fh)
|
|
204
206
|
stream.write(b"srt was here")
|
|
205
207
|
assert stream.hexdigest() == "cd7bd850d261f8fa39a41d0963b42dae5f303615db19ac79e5044586d0825b7b"
|
|
206
208
|
|
|
207
209
|
|
|
208
|
-
def test_asdf_stream_combined():
|
|
210
|
+
def test_asdf_stream_combined() -> None:
|
|
209
211
|
fh = BytesIO()
|
|
210
212
|
stream = Crc32Stream(fh)
|
|
211
213
|
stream = CompressedStream(stream)
|
|
@@ -218,7 +220,7 @@ def test_asdf_stream_combined():
|
|
|
218
220
|
assert fh.getvalue() == bytes.fromhex("789c2b2e2a51284f2c56c8482d4a2d1e658fb247d9a3ec41cc06004445c530665f35fc")
|
|
219
221
|
|
|
220
222
|
|
|
221
|
-
def test_asdf_scrape(asdf_writer: AsdfWriter):
|
|
223
|
+
def test_asdf_scrape(asdf_writer: AsdfWriter) -> None:
|
|
222
224
|
asdf_writer.add_bytes(b"\x00" * 0x1000, idx=0, base=0)
|
|
223
225
|
asdf_writer.add_bytes(b"\x02" * 0x1000, idx=0, base=0x4000)
|
|
224
226
|
asdf_writer.add_bytes(b"\x04" * 0x1000, idx=0, base=0x8000)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
from
|
|
2
|
-
from unittest.mock import MagicMock, patch
|
|
1
|
+
from __future__ import annotations
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
from typing import TYPE_CHECKING, BinaryIO
|
|
4
|
+
from unittest.mock import MagicMock, patch
|
|
5
5
|
|
|
6
6
|
from dissect.evidence import ewf
|
|
7
7
|
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
def test_ewf(ewf_data: BinaryIO) -> None:
|
|
10
13
|
e = ewf.EWF(ewf_data)
|
|
@@ -32,23 +32,17 @@ commands =
|
|
|
32
32
|
[testenv:fix]
|
|
33
33
|
package = skip
|
|
34
34
|
deps =
|
|
35
|
-
|
|
36
|
-
isort==5.11.4
|
|
35
|
+
ruff==0.9.2
|
|
37
36
|
commands =
|
|
38
|
-
|
|
39
|
-
isort dissect tests
|
|
37
|
+
ruff format dissect tests
|
|
40
38
|
|
|
41
39
|
[testenv:lint]
|
|
42
40
|
package = skip
|
|
43
41
|
deps =
|
|
44
|
-
|
|
45
|
-
flake8
|
|
46
|
-
flake8-black
|
|
47
|
-
flake8-isort
|
|
48
|
-
isort==5.11.4
|
|
42
|
+
ruff==0.9.2
|
|
49
43
|
vermin
|
|
50
44
|
commands =
|
|
51
|
-
|
|
45
|
+
ruff check dissect tests
|
|
52
46
|
vermin -t=3.9- --no-tips --lint dissect tests
|
|
53
47
|
|
|
54
48
|
[flake8]
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from io import BytesIO
|
|
3
|
-
from typing import BinaryIO, Iterator
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
from dissect.evidence.asdf import AsdfWriter
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def open_data(name: str) -> BinaryIO:
|
|
11
|
-
return open(os.path.join(os.path.dirname(__file__), name), "rb")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@pytest.fixture
|
|
15
|
-
def ad1_data() -> BinaryIO:
|
|
16
|
-
return open_data("data/ad1_test.ad1")
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@pytest.fixture
|
|
20
|
-
def ad1_data_long() -> BinaryIO:
|
|
21
|
-
return open_data("data/ad1_long.ad1")
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@pytest.fixture
|
|
25
|
-
def ad1_data_compressed() -> BinaryIO:
|
|
26
|
-
return open_data("data/ad1_test_compressed.ad1")
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@pytest.fixture
|
|
30
|
-
def ewf_data() -> BinaryIO:
|
|
31
|
-
return open_data("data/ewf.E01")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@pytest.fixture
|
|
35
|
-
def asdf_writer() -> Iterator[AsdfWriter]:
|
|
36
|
-
def noop():
|
|
37
|
-
pass
|
|
38
|
-
|
|
39
|
-
fh = BytesIO()
|
|
40
|
-
fh.close = noop # Prevent clearing the buffer, we need it
|
|
41
|
-
yield AsdfWriter(fh)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/requires.txt
RENAMED
|
File without changes
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/dissect.evidence.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect_evidence-3.10.dev3 → dissect_evidence-3.11.dev1}/tests/data/ad1_test_compressed.ad1
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|