dissect.evidence 3.10.dev3__py3-none-any.whl → 3.11.dev2__py3-none-any.whl
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/__init__.py +1 -1
- dissect/evidence/ad1.py +26 -26
- dissect/evidence/aff4.py +0 -0
- dissect/evidence/asdf/asdf.py +12 -9
- dissect/evidence/ewf.py +6 -15
- dissect/evidence/exceptions.py +0 -10
- dissect/evidence/tools/asdf/dd.py +31 -29
- dissect/evidence/tools/asdf/meta.py +24 -19
- dissect/evidence/tools/asdf/repair.py +40 -37
- dissect/evidence/tools/asdf/verify.py +22 -10
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/METADATA +6 -6
- dissect.evidence-3.11.dev2.dist-info/RECORD +21 -0
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/WHEEL +1 -1
- dissect.evidence-3.10.dev3.dist-info/RECORD +0 -20
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/COPYRIGHT +0 -0
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/LICENSE +0 -0
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/entry_points.txt +0 -0
- {dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/top_level.txt +0 -0
dissect/evidence/__init__.py
CHANGED
dissect/evidence/ad1.py
CHANGED
|
@@ -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
|
dissect/evidence/aff4.py
ADDED
|
File without changes
|
dissect/evidence/asdf/asdf.py
CHANGED
|
@@ -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."""
|
dissect/evidence/ewf.py
CHANGED
|
@@ -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
|
dissect/evidence/exceptions.py
CHANGED
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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.dev2
|
|
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
|
|
@@ -22,11 +22,11 @@ Requires-Python: ~=3.9
|
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
License-File: LICENSE
|
|
24
24
|
License-File: COPYRIGHT
|
|
25
|
-
Requires-Dist: dissect.cstruct
|
|
26
|
-
Requires-Dist: dissect.util
|
|
25
|
+
Requires-Dist: dissect.cstruct<5,>=4
|
|
26
|
+
Requires-Dist: dissect.util<4,>=3
|
|
27
27
|
Provides-Extra: dev
|
|
28
|
-
Requires-Dist: dissect.cstruct
|
|
29
|
-
Requires-Dist: dissect.util
|
|
28
|
+
Requires-Dist: dissect.cstruct<5.0.dev,>=4.0.dev; extra == "dev"
|
|
29
|
+
Requires-Dist: dissect.util<4.0.dev,>=3.0.dev; extra == "dev"
|
|
30
30
|
|
|
31
31
|
# dissect.evidence
|
|
32
32
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
dissect/evidence/__init__.py,sha256=_r062qBdK0eNXdXYhU9F6-VVZPc_NGA_Osqk3UBb7RA,165
|
|
2
|
+
dissect/evidence/ad1.py,sha256=SaIoZA-vnAieUkgP2ZNh64cRg_3QwH1ZBQmoIiU1NgI,6910
|
|
3
|
+
dissect/evidence/aff4.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
dissect/evidence/ewf.py,sha256=5ThU94GvUNI3CGCbGEhJSqOTBEmbEL72F7XADLxUa2g,14628
|
|
5
|
+
dissect/evidence/exceptions.py,sha256=gAGWwczCskTVOPlOhoMxuTZcIIQjo5Qxk1KC4DEHLUo,488
|
|
6
|
+
dissect/evidence/asdf/__init__.py,sha256=yZxcpk-dYWkSqJ923fgh5x2l6GwXq2rJfmIrh5rZT68,177
|
|
7
|
+
dissect/evidence/asdf/asdf.py,sha256=23wBi80SqPfJWvT8F-8URfoTkyfVpgBNLSvM3N9mIrk,23959
|
|
8
|
+
dissect/evidence/asdf/streams.py,sha256=5VBq4az6c10r5qQaHgR8g0a7j5nAcgQuat3yyp-Eua8,2601
|
|
9
|
+
dissect/evidence/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
dissect/evidence/tools/asdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
dissect/evidence/tools/asdf/dd.py,sha256=ggCznU68agnAmSSae0eYty8t1j9DuYR_9cAQwbee2bg,3117
|
|
12
|
+
dissect/evidence/tools/asdf/meta.py,sha256=bMb9pI49MgjeKhVXYPqhw74Cn0Sq-25YMzXU3cYaZro,2568
|
|
13
|
+
dissect/evidence/tools/asdf/repair.py,sha256=XbIC0qte7VO6y-qaPIbSTJ5gZ3XhblI1iCdMwZ62u_M,3072
|
|
14
|
+
dissect/evidence/tools/asdf/verify.py,sha256=zvxRvHNFZv6bicDE7RcT-jWgDKdYbLKMNTpGOwUJmfU,4161
|
|
15
|
+
dissect.evidence-3.11.dev2.dist-info/COPYRIGHT,sha256=yExUrJwFMdmpUCxPrUiBR1pPQ_pGrr6hf3p231U6VnQ,303
|
|
16
|
+
dissect.evidence-3.11.dev2.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
17
|
+
dissect.evidence-3.11.dev2.dist-info/METADATA,sha256=J_bKW_BkbjVg_bKQV9HaBf5ZDsB50YKtro2LixPAJV4,3284
|
|
18
|
+
dissect.evidence-3.11.dev2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
19
|
+
dissect.evidence-3.11.dev2.dist-info/entry_points.txt,sha256=rz4YeIbMkl-wjryDbFnh25eK5qK4asKQvZoMJ8hM_eo,222
|
|
20
|
+
dissect.evidence-3.11.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
21
|
+
dissect.evidence-3.11.dev2.dist-info/RECORD,,
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
dissect/evidence/__init__.py,sha256=B0s7NJEWXtn2MvJkv1g1V68inFxHQp-YwJ9xRenka64,165
|
|
2
|
-
dissect/evidence/ad1.py,sha256=VWnDkISbZ8aSUMToponE6bd1LQy0bl18p-6vHxGiHF8,6622
|
|
3
|
-
dissect/evidence/ewf.py,sha256=egCAGRIGM_W9yTildgCApG-VNpIHKduTlg_8aBNzO4w,14751
|
|
4
|
-
dissect/evidence/exceptions.py,sha256=xFvnTpdkL7GhwV57dkI0t-63FxuBv_rjjP7VJ_zrL6Y,538
|
|
5
|
-
dissect/evidence/asdf/__init__.py,sha256=yZxcpk-dYWkSqJ923fgh5x2l6GwXq2rJfmIrh5rZT68,177
|
|
6
|
-
dissect/evidence/asdf/asdf.py,sha256=A0LM3Qk1WsCoj0Cl6Fe-x70Z976at0ncQ4XzJ_EVzFM,23854
|
|
7
|
-
dissect/evidence/asdf/streams.py,sha256=5VBq4az6c10r5qQaHgR8g0a7j5nAcgQuat3yyp-Eua8,2601
|
|
8
|
-
dissect/evidence/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
dissect/evidence/tools/asdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
dissect/evidence/tools/asdf/dd.py,sha256=ldyjyUIQhRaIxLhCbnvNK8d2sCvOw2PCVal3kCegERo,2975
|
|
11
|
-
dissect/evidence/tools/asdf/meta.py,sha256=Dqfs34wWU2lV2JPTdrwhPfZ3Dm-fETlA20yZDhQGmo4,2417
|
|
12
|
-
dissect/evidence/tools/asdf/repair.py,sha256=5XQRQ33-SOcFes55vyY-j9tHrmrbSB8Q-ijspQnMD3U,2893
|
|
13
|
-
dissect/evidence/tools/asdf/verify.py,sha256=DLYMXzsUtkimkhqUN_NHxnpamy8HHnL3rcp_aoL5-FI,3871
|
|
14
|
-
dissect.evidence-3.10.dev3.dist-info/COPYRIGHT,sha256=yExUrJwFMdmpUCxPrUiBR1pPQ_pGrr6hf3p231U6VnQ,303
|
|
15
|
-
dissect.evidence-3.10.dev3.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
16
|
-
dissect.evidence-3.10.dev3.dist-info/METADATA,sha256=UT3c9qyv-RdD1KcVchljRSPTTOKu3ZS8aEzdxE_oKKI,3290
|
|
17
|
-
dissect.evidence-3.10.dev3.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
|
|
18
|
-
dissect.evidence-3.10.dev3.dist-info/entry_points.txt,sha256=rz4YeIbMkl-wjryDbFnh25eK5qK4asKQvZoMJ8hM_eo,222
|
|
19
|
-
dissect.evidence-3.10.dev3.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
|
|
20
|
-
dissect.evidence-3.10.dev3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{dissect.evidence-3.10.dev3.dist-info → dissect.evidence-3.11.dev2.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|