dissect.evidence 3.14.dev3__py3-none-any.whl → 3.14.dev4__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.
@@ -14,6 +14,9 @@ from dissect.evidence.exception import FileNotFoundError, NotADirectoryError, No
14
14
  if TYPE_CHECKING:
15
15
  from collections.abc import Iterator
16
16
  from pathlib import PurePath
17
+ from types import TracebackType
18
+
19
+ from typing_extensions import Self
17
20
 
18
21
  EntryType = c_ad1.EntryType
19
22
  MetaType = c_ad1.MetaType
@@ -53,8 +56,9 @@ class AD1:
53
56
  - https://al3ks1s.fr/posts/adventures-part-1/
54
57
  """
55
58
 
56
- def __init__(self, fh: BinaryIO | list[BinaryIO]):
57
- fhs = [fh] if not isinstance(fh, list) else fh
59
+ def __init__(self, fh: BinaryIO | list[BinaryIO] | Path | list[Path]):
60
+ fhs = find_files(fh) if isinstance(fh, Path) else [fh] if not isinstance(fh, list) else fh
61
+
58
62
  self.fh = fhs
59
63
  self.root = VirtualEntry(self, "/")
60
64
 
@@ -77,6 +81,14 @@ class AD1:
77
81
  else:
78
82
  self._open_ad1()
79
83
 
84
+ def __enter__(self) -> Self:
85
+ return self
86
+
87
+ def __exit__(
88
+ self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
89
+ ) -> None:
90
+ self.close()
91
+
80
92
  def is_adcrypt(self) -> bool:
81
93
  """Return whether the AD1 container is ADCRYPT encrypted."""
82
94
  return self.adcrypt is not None
@@ -91,7 +103,7 @@ class AD1:
91
103
  Implements a simple LRU cache to limit the number of open segments.
92
104
 
93
105
  Args:
94
- idx: Index or URI of the segment to open.
106
+ idx: Index of the segment to open.
95
107
  """
96
108
  # Poor mans LRU
97
109
  if idx in self._segments:
@@ -103,21 +115,20 @@ class AD1:
103
115
  oldest_idx = self._segment_lru.pop(0)
104
116
  oldest_segment = self._segments.pop(oldest_idx)
105
117
 
106
- # Don't close it if we received it as a file-like object
107
- if not hasattr(self.fh[oldest_idx], "read"):
118
+ # Only close file handles that we opened ourselves
119
+ if isinstance(self.fh[oldest_idx], Path):
108
120
  oldest_segment.fh.close()
109
121
 
110
122
  del oldest_segment
111
123
 
112
124
  fh = self.fh[idx]
113
- if not hasattr(fh, "read"):
114
- fh = fh.open("rb") if isinstance(fh, Path) else Path(fh).open("rb") # noqa: SIM115
125
+ if isinstance(fh, Path):
126
+ fh = fh.open("rb")
115
127
 
116
128
  if self.is_adcrypt() and not self.is_locked():
117
129
  fh = self.adcrypt.wrap(fh, idx)
118
130
 
119
131
  segment = SegmentFile(fh)
120
-
121
132
  self._segments[idx] = segment
122
133
  self._segment_lru.append(idx)
123
134
 
@@ -210,6 +221,15 @@ class AD1:
210
221
  """Shortcut for ``AD1.entry(path).open()``."""
211
222
  return self.entry(path).open()
212
223
 
224
+ def close(self) -> None:
225
+ """Close all segment file handles that we opened ourselves and clear the segment cache."""
226
+ for idx, segment in self._segments.items():
227
+ if isinstance(self.fh[idx], Path):
228
+ segment.fh.close()
229
+
230
+ self._segments = {}
231
+ self._segment_lru = []
232
+
213
233
 
214
234
  def _hallicinate_root_entries(ad1: AD1) -> None:
215
235
  # We need to create some fake entries for all parts leading up to `logical_image.name`
@@ -38,3 +38,6 @@ class ADCryptStream(AlignedStream):
38
38
  )
39
39
  cipher = AES.new(self.key, AES.MODE_CTR, counter=ctr)
40
40
  return cipher.decrypt(buf)
41
+
42
+ def close(self) -> None:
43
+ self.fh.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.evidence
3
- Version: 3.14.dev3
3
+ Version: 3.14.dev4
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-Expression: AGPL-3.0-or-later
@@ -1,7 +1,7 @@
1
1
  dissect/evidence/__init__.py,sha256=HBsn_m9aTzUqV0niqY6DV1GwKhtL2WfMf3i1LJFyxO4,257
2
2
  dissect/evidence/exception.py,sha256=e--4r9hL1hWm0BeXaIqxsXcrjl60QAfYV3c2Q8caHss,570
3
3
  dissect/evidence/ad1/__init__.py,sha256=p31RFzymZqk4dp2h8Ov9uAOk-lUqbT2rQujrfOFScTc,557
4
- dissect/evidence/ad1/ad1.py,sha256=1E_-bb2ePXz1Za6exrExnMkFyIJTDuVpaps5LNkhWpU,14993
4
+ dissect/evidence/ad1/ad1.py,sha256=xP9MVcgAPDb78Np9sojDrUDdLFBQ2nC90nGsFx47nJY,15598
5
5
  dissect/evidence/ad1/c_ad1.py,sha256=3MWCTONFBj99M7ZZbzLMZM393uJqPqljMdvZZpeG78A,6421
6
6
  dissect/evidence/ad1/c_ad1.pyi,sha256=m4m5VK1fRe4N5LNE-Cb1Datd1yutC6fptvKeq7fWH1k,7299
7
7
  dissect/evidence/ad1/stream.py,sha256=clcugxOaTcgXS0C5M694pnmIRFgEI2Ip32iqkdBJ5hM,2539
@@ -9,7 +9,7 @@ dissect/evidence/adcrypt/__init__.py,sha256=6OZAzN5vI9EGAyDz4BNP2YO_Ev0dyCILDKNF
9
9
  dissect/evidence/adcrypt/adcrypt.py,sha256=u_YABDws6Q92tMK6K7Lmx7BcLyPfSqmlXgONOzZ2Be0,5400
10
10
  dissect/evidence/adcrypt/c_adcrypt.py,sha256=rE17LHpx1pSbsIxAupEwM8ZFY4U9BODAY8aCyRljZoM,1000
11
11
  dissect/evidence/adcrypt/c_adcrypt.pyi,sha256=-m3voe_rrLWCScds9tl9CRzoVbGn7GqhN9O7yUICtGA,2195
12
- dissect/evidence/adcrypt/stream.py,sha256=gwsim1mzSJnskzDL-y7FRLUt-MuNezGkT_Un950Gnfc,1144
12
+ dissect/evidence/adcrypt/stream.py,sha256=Zea3Jaj5WSqxmQV4CS41Wk6OOtMVIPy2shHCviakCa8,1198
13
13
  dissect/evidence/asdf/__init__.py,sha256=Q7gUKk6Z5nR_DHnSo2ZfuUIlDNmARk420lC7A0GPwkg,213
14
14
  dissect/evidence/asdf/asdf.py,sha256=5FvEQ0KsaCYvloNGbtqlQin1t52AvZFBpbgh8jbEkRY,22239
15
15
  dissect/evidence/asdf/c_asdf.py,sha256=rfP2dVcJLxSbkNHZdDnCOM5Hs-ZKD_QY5e3iyxBQWQU,1803
@@ -28,10 +28,10 @@ dissect/evidence/tools/asdf/dd.py,sha256=GPsEqyGBefXkUCHxZUTHDi1j2Nw1w39h2Qr-RoG
28
28
  dissect/evidence/tools/asdf/meta.py,sha256=bMb9pI49MgjeKhVXYPqhw74Cn0Sq-25YMzXU3cYaZro,2568
29
29
  dissect/evidence/tools/asdf/repair.py,sha256=8iDzS7wmVfg35AKolMzOpbJVBx-CMPqOvxPAlBkKc9w,3071
30
30
  dissect/evidence/tools/asdf/verify.py,sha256=zvxRvHNFZv6bicDE7RcT-jWgDKdYbLKMNTpGOwUJmfU,4161
31
- dissect_evidence-3.14.dev3.dist-info/licenses/COPYRIGHT,sha256=yExUrJwFMdmpUCxPrUiBR1pPQ_pGrr6hf3p231U6VnQ,303
32
- dissect_evidence-3.14.dev3.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
33
- dissect_evidence-3.14.dev3.dist-info/METADATA,sha256=C66J-fcZKWOn3MtHtYkdbbXUQVu38Wlz3aO7tF5oSsE,3340
34
- dissect_evidence-3.14.dev3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
35
- dissect_evidence-3.14.dev3.dist-info/entry_points.txt,sha256=Wwci5PSqdS9koYEtx9lIsmPRfnKRJUG2UPAKpsJfGOI,268
36
- dissect_evidence-3.14.dev3.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
37
- dissect_evidence-3.14.dev3.dist-info/RECORD,,
31
+ dissect_evidence-3.14.dev4.dist-info/licenses/COPYRIGHT,sha256=yExUrJwFMdmpUCxPrUiBR1pPQ_pGrr6hf3p231U6VnQ,303
32
+ dissect_evidence-3.14.dev4.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
33
+ dissect_evidence-3.14.dev4.dist-info/METADATA,sha256=UbQPOFO8zJyy-CO1uyUEDPBt7IKtluq_ZEB-8WGa5J0,3340
34
+ dissect_evidence-3.14.dev4.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
35
+ dissect_evidence-3.14.dev4.dist-info/entry_points.txt,sha256=Wwci5PSqdS9koYEtx9lIsmPRfnKRJUG2UPAKpsJfGOI,268
36
+ dissect_evidence-3.14.dev4.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
37
+ dissect_evidence-3.14.dev4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5