dissect.evidence 3.6.dev1__tar.gz → 3.7.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.6.dev1/dissect.evidence.egg-info → dissect.evidence-3.7.dev1}/PKG-INFO +1 -1
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/ewf.py +153 -104
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1/dissect.evidence.egg-info}/PKG-INFO +1 -1
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/conftest.py +7 -6
- dissect.evidence-3.7.dev1/tests/test_ewf.py +38 -0
- dissect.evidence-3.6.dev1/tests/test_ewf.py +0 -8
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/COPYRIGHT +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/LICENSE +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/MANIFEST.in +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/README.md +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/__init__.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/ad1.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/asdf/__init__.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/asdf/asdf.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/asdf/streams.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/exceptions.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/__init__.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/__init__.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/dd.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/meta.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/repair.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/verify.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/SOURCES.txt +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/dependency_links.txt +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/entry_points.txt +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/requires.txt +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/top_level.txt +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/pyproject.toml +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/setup.cfg +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/__init__.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/data/ad1_long.ad1 +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/data/ad1_test.ad1 +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/data/ad1_test_compressed.ad1 +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/data/ewf.E01 +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/docs/Makefile +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/docs/conf.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/docs/index.rst +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/test_ad1.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tests/test_asdf.py +0 -0
- {dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.evidence
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.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,4 @@
|
|
|
1
|
-
from __future__ import
|
|
1
|
+
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
@@ -6,8 +6,9 @@ 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, Union
|
|
9
10
|
|
|
10
|
-
from dissect import cstruct
|
|
11
|
+
from dissect.cstruct import cstruct
|
|
11
12
|
from dissect.util.stream import AlignedStream
|
|
12
13
|
|
|
13
14
|
from dissect.evidence.exceptions import EWFError
|
|
@@ -91,23 +92,22 @@ typedef struct {
|
|
|
91
92
|
|
|
92
93
|
typedef struct {
|
|
93
94
|
uint32 num_entries;
|
|
94
|
-
uint32
|
|
95
|
+
uint32 _;
|
|
95
96
|
uint64 base_offset;
|
|
96
|
-
uint32
|
|
97
|
+
uint32 _;
|
|
97
98
|
uint32 checksum;
|
|
98
99
|
uint32 entries[num_entries];
|
|
99
100
|
} EWFTableSection;
|
|
100
101
|
"""
|
|
101
102
|
|
|
102
|
-
c_ewf = cstruct
|
|
103
|
+
c_ewf = cstruct()
|
|
103
104
|
c_ewf.load(ewf_def)
|
|
104
105
|
|
|
106
|
+
MAX_OPEN_SEGMENTS = 128
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
It used outside the module, in dissect.target containers
|
|
110
|
-
"""
|
|
108
|
+
|
|
109
|
+
def find_files(path: Union[str, Path]) -> list[Path]:
|
|
110
|
+
"""Find all related EWF files from the given path."""
|
|
111
111
|
if not isinstance(path, Path):
|
|
112
112
|
path = Path(path)
|
|
113
113
|
|
|
@@ -125,22 +125,24 @@ def find_files(path):
|
|
|
125
125
|
return sorted(path.parent.glob(f"{path.stem}.{ewfglob}[0-9A-Za-z][0-9A-Za-z]"))
|
|
126
126
|
|
|
127
127
|
|
|
128
|
-
class EWF
|
|
129
|
-
"""Expert Witness
|
|
128
|
+
class EWF:
|
|
129
|
+
"""Expert Witness Disk Image Format."""
|
|
130
130
|
|
|
131
|
-
def __init__(self, fh):
|
|
131
|
+
def __init__(self, fh: Union[BinaryIO, list[BinaryIO]]):
|
|
132
132
|
fhs = [fh] if not isinstance(fh, list) else fh
|
|
133
133
|
|
|
134
|
-
self.
|
|
135
|
-
self.
|
|
136
|
-
self.
|
|
137
|
-
self.
|
|
134
|
+
self.fh = fhs
|
|
135
|
+
self.header: HeaderSection = None
|
|
136
|
+
self.volume: VolumeSection = None
|
|
137
|
+
self._segments: dict[str, Segment] = {}
|
|
138
|
+
self._segment_offsets = []
|
|
139
|
+
self._segment_lru = []
|
|
138
140
|
|
|
139
141
|
segment_offset = 0
|
|
140
142
|
|
|
141
|
-
for
|
|
143
|
+
for i in range(len(fhs)):
|
|
142
144
|
try:
|
|
143
|
-
segment =
|
|
145
|
+
segment = self.open_segment(i)
|
|
144
146
|
except Exception:
|
|
145
147
|
log.exception("Failed to parse as EWF file: %s", fh)
|
|
146
148
|
continue
|
|
@@ -152,57 +154,101 @@ class EWF(AlignedStream):
|
|
|
152
154
|
self.volume = segment.volume
|
|
153
155
|
|
|
154
156
|
if segment_offset != 0:
|
|
155
|
-
self.
|
|
157
|
+
self._segment_offsets.append(segment_offset)
|
|
156
158
|
|
|
157
159
|
segment.offset = segment_offset * self.volume.sector_size
|
|
158
160
|
segment.sector_offset = segment_offset
|
|
159
161
|
segment_offset += segment.sector_count
|
|
160
162
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if not self.header or not self.volume or not self.segments:
|
|
163
|
+
if not self.header or not self.volume:
|
|
164
164
|
raise EWFError(f"Failed to load EWF: {fh}")
|
|
165
165
|
|
|
166
166
|
self.chunk_size = self.volume.sector_count * self.volume.sector_size
|
|
167
167
|
|
|
168
168
|
max_size = self.volume.chunk_count * self.volume.sector_count * self.volume.sector_size
|
|
169
|
-
last_table = self.
|
|
170
|
-
last_chunk_size = len(last_table.read_chunk(last_table.
|
|
169
|
+
last_table = self.open_segment(len(self.fh) - 1).tables[-1]
|
|
170
|
+
last_chunk_size = len(last_table.read_chunk(last_table.num_entries - 1))
|
|
171
171
|
|
|
172
172
|
self.size = max_size - (self.chunk_size - last_chunk_size)
|
|
173
|
-
super().__init__(self.size)
|
|
174
173
|
|
|
175
|
-
def
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
def open_segment(self, idx: int) -> Segment:
|
|
175
|
+
# Poor mans LRU
|
|
176
|
+
if idx in self._segments:
|
|
177
|
+
self._segment_lru.remove(idx)
|
|
178
|
+
self._segment_lru.append(idx)
|
|
179
|
+
return self._segments[idx]
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
if len(self._segment_lru) >= MAX_OPEN_SEGMENTS:
|
|
182
|
+
oldest_idx = self._segment_lru.pop(0)
|
|
183
|
+
oldest_segment = self._segments.pop(oldest_idx)
|
|
182
184
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
# Don't close it if we received it as a file-like object
|
|
186
|
+
if not hasattr(self.fh[oldest_idx], "read"):
|
|
187
|
+
oldest_segment.fh.close()
|
|
185
188
|
|
|
186
|
-
|
|
187
|
-
sector += segment_sectors
|
|
188
|
-
count -= segment_sectors
|
|
189
|
+
del oldest_segment
|
|
189
190
|
|
|
190
|
-
|
|
191
|
+
fh = self.fh[idx]
|
|
192
|
+
if not hasattr(fh, "read"):
|
|
193
|
+
if isinstance(fh, Path):
|
|
194
|
+
fh = fh.open("rb")
|
|
195
|
+
else:
|
|
196
|
+
fh = open(fh, "rb")
|
|
191
197
|
|
|
192
|
-
|
|
198
|
+
segment = Segment(self, fh)
|
|
199
|
+
if self.volume and 0 < idx <= len(self._segment_offsets):
|
|
200
|
+
# We already have a known segment offset for this segment, so set it back
|
|
201
|
+
segment_offset = self._segment_offsets[idx - 1]
|
|
202
|
+
segment.offset = segment_offset * self.volume.sector_size
|
|
203
|
+
segment.sector_offset = segment_offset
|
|
204
|
+
else:
|
|
205
|
+
# Otherwise we're in the initialization loop (or we're idx == 0)
|
|
206
|
+
segment.offset = 0
|
|
207
|
+
segment.sector_offset = 0
|
|
193
208
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
sector_offset = offset // self.volume.sector_size
|
|
197
|
-
sector_count = (length + self.volume.sector_size - 1) // self.volume.sector_size
|
|
209
|
+
self._segments[idx] = segment
|
|
210
|
+
self._segment_lru.append(idx)
|
|
198
211
|
|
|
199
|
-
return
|
|
212
|
+
return segment
|
|
200
213
|
|
|
214
|
+
def open(self) -> BinaryIO:
|
|
215
|
+
return EWFStream(self)
|
|
201
216
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
217
|
+
|
|
218
|
+
class EWFStream(AlignedStream):
|
|
219
|
+
def __init__(self, ewf: EWF):
|
|
220
|
+
self.ewf = ewf
|
|
221
|
+
self.sector_size = self.ewf.volume.sector_size
|
|
222
|
+
super().__init__(ewf.size)
|
|
223
|
+
|
|
224
|
+
def _read(self, offset: int, length: int) -> bytes:
|
|
225
|
+
result = []
|
|
226
|
+
|
|
227
|
+
sector_offset = offset // self.sector_size
|
|
228
|
+
sector_count = (length + self.sector_size - 1) // self.sector_size
|
|
229
|
+
|
|
230
|
+
segment_idx = bisect_right(self.ewf._segment_offsets, sector_offset)
|
|
231
|
+
while sector_count > 0:
|
|
232
|
+
segment = self.ewf.open_segment(segment_idx)
|
|
233
|
+
|
|
234
|
+
segment_remaining_sectors = segment.sector_count - (sector_offset - segment.sector_offset)
|
|
235
|
+
segment_sectors = min(segment_remaining_sectors, sector_count)
|
|
236
|
+
|
|
237
|
+
result.append(segment.read_sectors(sector_offset, segment_sectors))
|
|
238
|
+
sector_offset += segment_sectors
|
|
239
|
+
sector_count -= segment_sectors
|
|
240
|
+
|
|
241
|
+
segment_idx += 1
|
|
242
|
+
|
|
243
|
+
return b"".join(result)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class Segment:
|
|
247
|
+
def __init__(self, ewf: EWF, fh: BinaryIO):
|
|
205
248
|
self.ewf = ewf
|
|
249
|
+
self.fh = fh
|
|
250
|
+
|
|
251
|
+
fh.seek(0)
|
|
206
252
|
self.ewfheader = c_ewf.EWFHeader(fh)
|
|
207
253
|
self.header = ewf.header
|
|
208
254
|
self.volume = ewf.volume
|
|
@@ -210,25 +256,25 @@ class EWFSegment:
|
|
|
210
256
|
if self.ewfheader.signature not in (b"EVF\x09\x0d\x0a\xff\x00", b"LVF\x09\x0d\x0a\xff\x00"):
|
|
211
257
|
raise EWFError(f"Invalid signature, got {self.ewfheader.signature!r}")
|
|
212
258
|
|
|
213
|
-
self.sections = []
|
|
214
|
-
self.tables = []
|
|
259
|
+
self.sections: list[SectionDescriptor] = []
|
|
260
|
+
self.tables: list[TableSection] = []
|
|
215
261
|
self.table_offsets = []
|
|
216
262
|
|
|
217
263
|
offset = 0
|
|
218
264
|
sector_offset = 0
|
|
219
265
|
|
|
220
266
|
while True:
|
|
221
|
-
section =
|
|
267
|
+
section = SectionDescriptor(fh)
|
|
222
268
|
self.sections.append(section)
|
|
223
269
|
|
|
224
270
|
if section.type in (b"header", b"header2") and not self.header:
|
|
225
|
-
self.header =
|
|
271
|
+
self.header = HeaderSection(self, section)
|
|
226
272
|
|
|
227
273
|
if section.type in (b"disk", b"volume") and not self.volume:
|
|
228
|
-
self.volume =
|
|
274
|
+
self.volume = VolumeSection(self, section)
|
|
229
275
|
|
|
230
276
|
if section.type == b"table":
|
|
231
|
-
table =
|
|
277
|
+
table = TableSection(self, section)
|
|
232
278
|
|
|
233
279
|
if sector_offset != 0:
|
|
234
280
|
self.table_offsets.append(sector_offset)
|
|
@@ -247,12 +293,12 @@ class EWFSegment:
|
|
|
247
293
|
|
|
248
294
|
self.chunk_count = sum([t.num_entries for t in self.tables])
|
|
249
295
|
self.sector_count = self.chunk_count * self.volume.sector_count
|
|
250
|
-
self.sector_offset = None
|
|
251
296
|
self.size = self.chunk_count * self.volume.sector_count * self.volume.sector_size
|
|
252
|
-
self.
|
|
297
|
+
self.sector_offset = None # Set later
|
|
298
|
+
self.offset = None # Set later
|
|
253
299
|
|
|
254
|
-
def read_sectors(self, sector, count):
|
|
255
|
-
log.debug("
|
|
300
|
+
def read_sectors(self, sector: int, count: int) -> bytes:
|
|
301
|
+
log.debug("Segment::read_sectors(0x%x, 0x%x)", sector, count)
|
|
256
302
|
segment_sector = sector - self.sector_offset
|
|
257
303
|
r = []
|
|
258
304
|
|
|
@@ -272,20 +318,28 @@ class EWFSegment:
|
|
|
272
318
|
return b"".join(r)
|
|
273
319
|
|
|
274
320
|
|
|
275
|
-
class
|
|
276
|
-
def __init__(self,
|
|
321
|
+
class HeaderSection:
|
|
322
|
+
def __init__(self, segment: Segment, section: SectionDescriptor):
|
|
323
|
+
self.segment = segment
|
|
324
|
+
self.section = section
|
|
325
|
+
|
|
326
|
+
fh = segment.fh
|
|
277
327
|
fh.seek(section.data_offset)
|
|
278
328
|
self.data = zlib.decompress(fh.read(section.size))
|
|
279
329
|
|
|
280
330
|
if self.data[0] in (b"\xff", b"\xfe"):
|
|
281
331
|
self.data = self.data.decode("utf16")
|
|
282
332
|
|
|
283
|
-
def __repr__(self):
|
|
284
|
-
return f"<
|
|
333
|
+
def __repr__(self) -> str:
|
|
334
|
+
return f"<HeaderSection categories={int(self.data[0])}>"
|
|
285
335
|
|
|
286
336
|
|
|
287
|
-
class
|
|
288
|
-
def __init__(self,
|
|
337
|
+
class VolumeSection:
|
|
338
|
+
def __init__(self, segment: Segment, section: SectionDescriptor):
|
|
339
|
+
self.segment = segment
|
|
340
|
+
self.section = section
|
|
341
|
+
|
|
342
|
+
fh = segment.fh
|
|
289
343
|
fh.seek(section.data_offset)
|
|
290
344
|
if section.size == 0x41C:
|
|
291
345
|
data = c_ewf.EWFVolumeSection(fh)
|
|
@@ -293,39 +347,35 @@ class EWFVolumeSection:
|
|
|
293
347
|
data = c_ewf.EWFVolumeSectionSpec(fh)
|
|
294
348
|
|
|
295
349
|
self.volume = data
|
|
350
|
+
self.chunk_count = data.chunk_count
|
|
351
|
+
self.sector_count = data.sector_count
|
|
352
|
+
self.sector_size = data.sector_size
|
|
296
353
|
|
|
297
|
-
def __getattr__(self, k):
|
|
298
|
-
if k in self.volume:
|
|
299
|
-
return getattr(self.volume, k)
|
|
300
|
-
|
|
301
|
-
return object.__getattribute__(self, k)
|
|
302
354
|
|
|
355
|
+
class TableSection:
|
|
356
|
+
def __init__(self, segment: Segment, section: SectionDescriptor):
|
|
357
|
+
self.segment = segment
|
|
358
|
+
self.section = section
|
|
303
359
|
|
|
304
|
-
|
|
305
|
-
def __init__(self, fh, section, segment):
|
|
360
|
+
fh = segment.fh
|
|
306
361
|
fh.seek(section.data_offset)
|
|
307
|
-
|
|
308
|
-
self.section = section
|
|
309
|
-
self.segment = segment
|
|
362
|
+
|
|
310
363
|
self.header = c_ewf.EWFTableSection(fh)
|
|
364
|
+
self.num_entries = self.header.num_entries
|
|
311
365
|
self.base_offset = self.header.base_offset
|
|
366
|
+
self.entries = self.header.entries
|
|
312
367
|
|
|
313
|
-
self.sector_count = self.
|
|
314
|
-
self.
|
|
315
|
-
self.
|
|
316
|
-
self.offset = None
|
|
317
|
-
|
|
318
|
-
def __getattr__(self, k):
|
|
319
|
-
if hasattr(self.header, k):
|
|
320
|
-
return getattr(self.header, k)
|
|
368
|
+
self.sector_count = self.num_entries * self.segment.volume.sector_count
|
|
369
|
+
self.size = self.sector_count * self.segment.volume.sector_size
|
|
370
|
+
self.sector_offset = None # Set later
|
|
371
|
+
self.offset = None # Set later
|
|
321
372
|
|
|
322
|
-
|
|
373
|
+
self.read_chunk = lru_cache(1024)(self.read_chunk)
|
|
323
374
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
log.debug("EWFTableSection::read_chunk(0x%x)", chunk)
|
|
375
|
+
def read_chunk(self, chunk: int) -> bytes:
|
|
376
|
+
log.debug("TableSection::read_chunk(0x%x)", chunk)
|
|
327
377
|
|
|
328
|
-
chunk_entry = self.
|
|
378
|
+
chunk_entry = self.entries[chunk]
|
|
329
379
|
chunk_offset = self.base_offset + (chunk_entry & 0x7FFFFFFF)
|
|
330
380
|
compressed = chunk_entry >> 31 == 1
|
|
331
381
|
|
|
@@ -334,7 +384,7 @@ class EWFTableSection:
|
|
|
334
384
|
# When it's the last chunk in the table though, this becomes trickier.
|
|
335
385
|
# We have to check if the chunk data is preceding the table, or if it's contained within the table section
|
|
336
386
|
# Then we can calculate the chunk size using these offsets
|
|
337
|
-
if chunk + 1 == self.
|
|
387
|
+
if chunk + 1 == self.num_entries:
|
|
338
388
|
# The chunk data is stored before the table section
|
|
339
389
|
if chunk_offset < self.section.offset:
|
|
340
390
|
chunk_size = self.section.offset - chunk_offset
|
|
@@ -344,26 +394,26 @@ class EWFTableSection:
|
|
|
344
394
|
else:
|
|
345
395
|
raise EWFError("Unknown size of last chunk")
|
|
346
396
|
else:
|
|
347
|
-
chunk_size = self.base_offset + (self.
|
|
397
|
+
chunk_size = self.base_offset + (self.entries[chunk + 1] & 0x7FFFFFFF) - chunk_offset
|
|
348
398
|
|
|
349
399
|
# Non compressed chunks have a 4 byte checksum
|
|
350
400
|
if not compressed:
|
|
351
401
|
chunk_size -= 4
|
|
352
402
|
|
|
353
|
-
self.fh.seek(chunk_offset)
|
|
354
|
-
buf = self.fh.read(chunk_size)
|
|
403
|
+
self.segment.fh.seek(chunk_offset)
|
|
404
|
+
buf = self.segment.fh.read(chunk_size)
|
|
355
405
|
|
|
356
406
|
if compressed:
|
|
357
407
|
buf = zlib.decompress(buf)
|
|
358
408
|
|
|
359
409
|
return buf
|
|
360
410
|
|
|
361
|
-
def read_sectors(self, sector, count):
|
|
362
|
-
log.debug("
|
|
363
|
-
|
|
411
|
+
def read_sectors(self, sector: int, count: int) -> bytes:
|
|
412
|
+
log.debug("TableSection::read_sectors(0x%x, 0x%x)", sector, count)
|
|
413
|
+
result = []
|
|
364
414
|
|
|
365
|
-
chunk_sector_count = self.segment.
|
|
366
|
-
sector_size = self.segment.
|
|
415
|
+
chunk_sector_count = self.segment.volume.sector_count
|
|
416
|
+
sector_size = self.segment.volume.sector_size
|
|
367
417
|
|
|
368
418
|
table_sector = sector - self.sector_offset
|
|
369
419
|
table_chunk = table_sector // chunk_sector_count
|
|
@@ -379,30 +429,29 @@ class EWFTableSection:
|
|
|
379
429
|
buf = self.read_chunk(table_chunk)
|
|
380
430
|
if chunk_pos != 0 or table_sectors != chunk_sector_count:
|
|
381
431
|
buf = buf[chunk_pos:chunk_end]
|
|
382
|
-
|
|
432
|
+
result.append(buf)
|
|
383
433
|
|
|
384
434
|
count -= table_sectors
|
|
385
435
|
table_sector += table_sectors
|
|
386
436
|
table_chunk += 1
|
|
387
437
|
|
|
388
|
-
return b"".join(
|
|
438
|
+
return b"".join(result)
|
|
389
439
|
|
|
390
440
|
|
|
391
|
-
class
|
|
392
|
-
def __init__(self, fh
|
|
441
|
+
class SectionDescriptor:
|
|
442
|
+
def __init__(self, fh: BinaryIO):
|
|
393
443
|
self.fh = fh
|
|
394
|
-
self.segment = segment
|
|
395
444
|
|
|
396
445
|
self.offset = fh.tell()
|
|
397
446
|
descriptor = c_ewf.EWFSectionDescriptor(fh)
|
|
398
447
|
self.type = descriptor.type.rstrip(b"\x00")
|
|
399
448
|
self.next = descriptor.next
|
|
400
|
-
self.size = descriptor.size -
|
|
449
|
+
self.size = descriptor.size - len(c_ewf.EWFSectionDescriptor)
|
|
401
450
|
self.checksum = descriptor.checksum
|
|
402
451
|
self.data_offset = fh.tell()
|
|
403
452
|
|
|
404
|
-
def __repr__(self):
|
|
453
|
+
def __repr__(self) -> str:
|
|
405
454
|
return (
|
|
406
|
-
f"<
|
|
407
|
-
f"offset=
|
|
455
|
+
f"<SectionDescriptor "
|
|
456
|
+
f"type={self.type} size={self.size:#x} offset={self.offset:#x} checksum={self.checksum:#x}>"
|
|
408
457
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.evidence
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.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,37 +1,38 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from io import BytesIO
|
|
3
|
+
from typing import BinaryIO, Iterator
|
|
3
4
|
|
|
4
5
|
import pytest
|
|
5
6
|
|
|
6
7
|
from dissect.evidence.asdf import AsdfWriter
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
def open_data(name):
|
|
10
|
+
def open_data(name: str) -> BinaryIO:
|
|
10
11
|
return open(os.path.join(os.path.dirname(__file__), name), "rb")
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
@pytest.fixture
|
|
14
|
-
def ad1_data():
|
|
15
|
+
def ad1_data() -> BinaryIO:
|
|
15
16
|
return open_data("data/ad1_test.ad1")
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
@pytest.fixture
|
|
19
|
-
def ad1_data_long():
|
|
20
|
+
def ad1_data_long() -> BinaryIO:
|
|
20
21
|
return open_data("data/ad1_long.ad1")
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
@pytest.fixture
|
|
24
|
-
def ad1_data_compressed():
|
|
25
|
+
def ad1_data_compressed() -> BinaryIO:
|
|
25
26
|
return open_data("data/ad1_test_compressed.ad1")
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
@pytest.fixture
|
|
29
|
-
def ewf_data():
|
|
30
|
+
def ewf_data() -> BinaryIO:
|
|
30
31
|
return open_data("data/ewf.E01")
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
@pytest.fixture
|
|
34
|
-
def asdf_writer():
|
|
35
|
+
def asdf_writer() -> Iterator[AsdfWriter]:
|
|
35
36
|
def noop():
|
|
36
37
|
pass
|
|
37
38
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from typing import BinaryIO
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from dissect.evidence import ewf
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_ewf(ewf_data: BinaryIO) -> None:
|
|
10
|
+
e = ewf.EWF(ewf_data)
|
|
11
|
+
|
|
12
|
+
assert e.size == 4097
|
|
13
|
+
assert e.open().read(4097) == (b"\xde\xad\xbe\xef" * 1024) + b"\n"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@patch("dissect.evidence.ewf.Segment")
|
|
17
|
+
def test_ewf_open_segment(MockSegment: MagicMock, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
18
|
+
monkeypatch.setattr(ewf, "MAX_OPEN_SEGMENTS", 2)
|
|
19
|
+
|
|
20
|
+
mock_segment = MockSegment.return_value
|
|
21
|
+
mock_segment.volume.sector_size = 512
|
|
22
|
+
mock_segment.sector_count = 2
|
|
23
|
+
|
|
24
|
+
mock_fh = [MagicMock(), MagicMock(), MagicMock(), MagicMock()]
|
|
25
|
+
e = ewf.EWF(mock_fh)
|
|
26
|
+
|
|
27
|
+
assert e._segment_offsets == [2, 4, 6]
|
|
28
|
+
assert e._segment_lru == [2, 3]
|
|
29
|
+
|
|
30
|
+
tmp = e.open_segment(0)
|
|
31
|
+
assert tmp.offset == 0
|
|
32
|
+
assert tmp.sector_offset == 0
|
|
33
|
+
assert e._segment_lru == [3, 0]
|
|
34
|
+
|
|
35
|
+
tmp = e.open_segment(1)
|
|
36
|
+
assert tmp.offset == 1024
|
|
37
|
+
assert tmp.sector_offset == 2
|
|
38
|
+
assert e._segment_lru == [0, 1]
|
|
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
|
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/repair.py
RENAMED
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect/evidence/tools/asdf/verify.py
RENAMED
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/requires.txt
RENAMED
|
File without changes
|
{dissect.evidence-3.6.dev1 → dissect.evidence-3.7.dev1}/dissect.evidence.egg-info/top_level.txt
RENAMED
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|