dissect.vmfs 3.10.dev1__tar.gz → 3.11.dev2__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.
Files changed (32) hide show
  1. dissect_vmfs-3.11.dev2/.git-blame-ignore-revs +6 -0
  2. {dissect_vmfs-3.10.dev1/dissect.vmfs.egg-info → dissect_vmfs-3.11.dev2}/PKG-INFO +2 -2
  3. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/c_vmfs.py +7 -4
  4. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/lvm.py +7 -5
  5. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/resource.py +78 -73
  6. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/vmfs.py +92 -82
  7. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2/dissect.vmfs.egg-info}/PKG-INFO +2 -2
  8. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect.vmfs.egg-info/SOURCES.txt +1 -0
  9. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/pyproject.toml +48 -5
  10. dissect_vmfs-3.11.dev2/tests/conftest.py +28 -0
  11. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/test_address.py +5 -3
  12. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/test_exceptions.py +3 -1
  13. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/test_lvm.py +6 -2
  14. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/test_vmfs.py +6 -3
  15. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tox.ini +4 -17
  16. dissect_vmfs-3.10.dev1/tests/conftest.py +0 -22
  17. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/COPYRIGHT +0 -0
  18. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/LICENSE +0 -0
  19. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/MANIFEST.in +0 -0
  20. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/README.md +0 -0
  21. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/__init__.py +3 -3
  22. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect/vmfs/exceptions.py +0 -0
  23. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect.vmfs.egg-info/dependency_links.txt +0 -0
  24. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect.vmfs.egg-info/requires.txt +0 -0
  25. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/dissect.vmfs.egg-info/top_level.txt +0 -0
  26. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/setup.cfg +0 -0
  27. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/__init__.py +0 -0
  28. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/data/vmfs5.bin.gz +0 -0
  29. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/data/vmfs6.bin.gz +0 -0
  30. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/docs/Makefile +0 -0
  31. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/docs/conf.py +0 -0
  32. {dissect_vmfs-3.10.dev1 → dissect_vmfs-3.11.dev2}/tests/docs/index.rst +0 -0
@@ -0,0 +1,6 @@
1
+ # Formatting commits. You can ignore them during git-blame with `--ignore-rev` or `--ignore-revs-file`.
2
+ #
3
+ # $ git config --add 'blame.ignoreRevsFile' '.git-blame-ignore-revs'
4
+ #
5
+ # Change linter to Ruff (#35)
6
+ 833e7fecef636da9fda88db47d28c9ea01e85c0d
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.vmfs
3
- Version: 3.10.dev1
3
+ Version: 3.11.dev2
4
4
  Summary: A Dissect module implementing a parser for the VMFS file system, used by VMware virtualization software
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import stat
2
4
  import struct
3
5
 
@@ -375,21 +377,22 @@ ResourceType = c_vmfs.ResourceType
375
377
  FileType = c_vmfs.FileType
376
378
 
377
379
 
378
- def bsf(value, size=32):
380
+ def bsf(value: int, size: int = 32) -> int:
379
381
  """Count the number of zero bits in an integer of a given size."""
380
382
  for i in range(size):
381
383
  if value & (1 << i):
382
384
  return i
385
+ return 0
383
386
 
384
387
 
385
- def type_to_mode(type_):
388
+ def type_to_mode(type_: FileType) -> int:
386
389
  if type_ == FileType.Directory:
387
390
  return stat.S_IFDIR
388
- elif type_ == FileType.Symlink:
391
+ if type_ == FileType.Symlink:
389
392
  return stat.S_IFLNK
390
393
  return stat.S_IFREG
391
394
 
392
395
 
393
- def vmfs_uuid(buf):
396
+ def vmfs_uuid(buf: bytes) -> str:
394
397
  uuid1, uuid2, uuid3, uuid4 = struct.unpack("<IIH6s", buf)
395
398
  return f"{uuid1:08x}-{uuid2:08x}-{uuid3:04x}-{uuid4.hex()}"
@@ -1,7 +1,9 @@
1
1
  # References:
2
2
  # - /usr/lib/vmware/vmkmod/lvmdriver
3
+ from __future__ import annotations
3
4
 
4
5
  from bisect import bisect_right
6
+ from typing import BinaryIO
5
7
 
6
8
  from dissect.util.stream import AlignedStream
7
9
 
@@ -26,8 +28,8 @@ class LVM(AlignedStream):
26
28
  VMFS should start at LVM dataOffset + 0x200000
27
29
  """
28
30
 
29
- def __init__(self, fh):
30
- fhs = [fh] if not type(fh) is list else fh
31
+ def __init__(self, fh: BinaryIO | list[BinaryIO]):
32
+ fhs = [fh] if type(fh) is not list else fh
31
33
 
32
34
  size = None
33
35
  self.uuid = None
@@ -56,7 +58,7 @@ class LVM(AlignedStream):
56
58
 
57
59
  super().__init__(size)
58
60
 
59
- def _read(self, offset, length):
61
+ def _read(self, offset: int, length: int) -> bytes:
60
62
  r = []
61
63
 
62
64
  pe_offset = offset // VMFS_LVM_PE_SIZE
@@ -93,7 +95,7 @@ class Extent(AlignedStream):
93
95
  - 0x900000
94
96
  """
95
97
 
96
- def __init__(self, fh):
98
+ def __init__(self, fh: BinaryIO):
97
99
  self.fh = fh
98
100
 
99
101
  fh.seek(c_vmfs.VMFS_LVM_DEVICE_META_BASE)
@@ -126,6 +128,6 @@ class Extent(AlignedStream):
126
128
 
127
129
  super().__init__(self.metadata.volumeSize)
128
130
 
129
- def _read(self, offset, length):
131
+ def _read(self, offset: int, length: int) -> bytes:
130
132
  self.fh.seek(self.metadata.dataOffset + offset)
131
133
  return self.fh.read(length)
@@ -1,8 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, BinaryIO
4
+
1
5
  from dissect.vmfs.c_vmfs import FileType, ResourceType, c_vmfs
2
6
  from dissect.vmfs.exceptions import FileNotFoundError
3
7
 
8
+ if TYPE_CHECKING:
9
+ from collections.abc import Iterator
10
+
11
+ from dissect.vmfs.vmfs import VMFS
4
12
 
5
- def address_type(addr):
13
+
14
+ def address_type(addr: int) -> int:
6
15
  """Return the address type.
7
16
 
8
17
  Address type is encoded in the lower 3 bits.
@@ -10,7 +19,7 @@ def address_type(addr):
10
19
  return addr & 0b111
11
20
 
12
21
 
13
- def address_fmt(vmfs, address):
22
+ def address_fmt(vmfs: VMFS, address: int) -> str:
14
23
  """Create a human readable representation of an address.
15
24
 
16
25
  References:
@@ -25,46 +34,45 @@ def address_fmt(vmfs, address):
25
34
  if vmfs.is_vmfs5:
26
35
  block = parse_fb_address(vmfs, address)
27
36
  return f"<FB tbz={tbz != 0} cow={cow} {block}>"
28
- else:
29
- cluster, resource = parse_sfb_address(vmfs, address)
30
- return f"<SFB tbz=0x{tbz:x} cow={cow} c{cluster} r{resource}>"
37
+ cluster, resource = parse_sfb_address(vmfs, address)
38
+ return f"<SFB tbz=0x{tbz:x} cow={cow} c{cluster} r{resource}>"
31
39
 
32
- elif addr_type == ResourceType.SB:
40
+ if addr_type == ResourceType.SB:
33
41
  cow = address & cow_mask != 0
34
42
  cluster, resource = parse_sb_address(vmfs, address)
35
43
  return f"<SB cow={cow} c{cluster} r{resource}>"
36
44
 
37
- elif addr_type == ResourceType.PB:
45
+ if addr_type == ResourceType.PB:
38
46
  cow = address & cow_mask != 0
39
47
  cluster, resource = parse_pb_address(vmfs, address)
40
48
  return f"<PB cow={cow} c{cluster} r{resource}>"
41
49
 
42
- elif addr_type == ResourceType.FD:
50
+ if addr_type == ResourceType.FD:
43
51
  cluster, resource = parse_fd_address(vmfs, address)
44
52
  return f"<FD c{cluster} r{resource}>"
45
53
 
46
- elif addr_type == ResourceType.PB2:
54
+ if addr_type == ResourceType.PB2:
47
55
  cow = address & cow_mask != 0
48
56
  cluster, resource = parse_pb_address(vmfs, address)
49
57
  return f"<PB2 cow={cow} c{cluster} r{resource}>"
50
58
 
51
- elif addr_type == ResourceType.JB:
59
+ if addr_type == ResourceType.JB:
52
60
  cluster, resource = parse_jb_address(vmfs, address)
53
61
  return f"<JB c{cluster} r{resource}>"
54
62
 
55
- elif addr_type == ResourceType.LFB:
63
+ if addr_type == ResourceType.LFB:
56
64
  tbz = address_tbz(vmfs, address)
57
65
  cow = address & cow_mask != 0
58
66
  block = parse_lfb_address(vmfs, address)
59
67
  return f"<LFB tbz=0x{tbz:x} cow={cow} {block}>"
60
68
 
61
- elif addr_type == 0:
69
+ if addr_type == 0:
62
70
  return "<Null address>"
63
71
 
64
72
  return f"<Invalid address 0x{address:x}>"
65
73
 
66
74
 
67
- def address_tbz(vmfs, address):
75
+ def address_tbz(vmfs: VMFS, address: int) -> int | None:
68
76
  """Return whether the TBZ flag is set.
69
77
 
70
78
  The TBZ flag is only valid for FB and LFB addresses.
@@ -73,12 +81,12 @@ def address_tbz(vmfs, address):
73
81
 
74
82
  if vmfs.is_vmfs5 and addr_type == ResourceType.FB:
75
83
  return address & c_vmfs.ADDRESS_FLAG_TBZ
76
- elif vmfs.is_vmfs6 and addr_type in (ResourceType.FB, ResourceType.LFB):
84
+ if vmfs.is_vmfs6 and addr_type in (ResourceType.FB, ResourceType.LFB):
77
85
  return (address & c_vmfs.ADDRESS_FLAG_TBZ_VMFS6) >> 7
78
86
  return None
79
87
 
80
88
 
81
- def parse_fb_address(vmfs, address):
89
+ def parse_fb_address(vmfs: VMFS, address: int) -> int:
82
90
  """Parse a FB address and return the block.
83
91
 
84
92
  VMFS5 encoding:
@@ -87,7 +95,7 @@ def parse_fb_address(vmfs, address):
87
95
  return (address & 0xFFFFFFC0) >> 6
88
96
 
89
97
 
90
- def parse_sfb_address(vmfs, address):
98
+ def parse_sfb_address(vmfs: VMFS, address: int) -> tuple[int, int]:
91
99
  """Parse a SFB address and return the cluster and resource.
92
100
 
93
101
  SFB (small file block) in VMFS6 is what FB was in VMFS5.
@@ -101,7 +109,7 @@ def parse_sfb_address(vmfs, address):
101
109
  return cluster, resource
102
110
 
103
111
 
104
- def parse_sb_address(vmfs, address):
112
+ def parse_sb_address(vmfs: VMFS, address: int) -> tuple[int, int]:
105
113
  """Parse a SB address and return the cluster and resource.
106
114
 
107
115
  VMFS5 encoding:
@@ -125,7 +133,7 @@ def parse_sb_address(vmfs, address):
125
133
  return cluster, resource
126
134
 
127
135
 
128
- def parse_pb_address(vmfs, address):
136
+ def parse_pb_address(vmfs: VMFS, address: int) -> tuple[int, int]:
129
137
  """Parse a PB address and return the cluster and resource.
130
138
 
131
139
  Encoding:
@@ -145,7 +153,7 @@ def parse_pb_address(vmfs, address):
145
153
  return cluster, resource
146
154
 
147
155
 
148
- def parse_fd_address(vmfs, address):
156
+ def parse_fd_address(vmfs: VMFS, address: int) -> tuple[int, int]:
149
157
  """Parse a FD address and return the cluster and resource.
150
158
 
151
159
  Encoding:
@@ -157,7 +165,7 @@ def parse_fd_address(vmfs, address):
157
165
  return cluster, resource
158
166
 
159
167
 
160
- def parse_jb_address(vmfs, address):
168
+ def parse_jb_address(vmfs: VMFS, address: int) -> tuple[int, int]:
161
169
  """Parse a JB address and return the cluster and resource.
162
170
 
163
171
  Encoding:
@@ -169,7 +177,7 @@ def parse_jb_address(vmfs, address):
169
177
  return cluster, resource
170
178
 
171
179
 
172
- def parse_lfb_address(vmfs, address):
180
+ def parse_lfb_address(vmfs: VMFS, address: int) -> int:
173
181
  """Parse a LFB address and return the block.
174
182
 
175
183
  Encoding:
@@ -179,11 +187,11 @@ def parse_lfb_address(vmfs, address):
179
187
 
180
188
 
181
189
  class ResourceManager:
182
- def __init__(self, vmfs):
190
+ def __init__(self, vmfs: VMFS):
183
191
  self.vmfs = vmfs
184
192
  self.resources = {}
185
193
 
186
- def open(self, resource_type, address=None, fileobj=None):
194
+ def open(self, resource_type: ResourceType, address: int | None = None, fileobj: BinaryIO | None = None) -> None:
187
195
  if resource_type in self.resources:
188
196
  raise ValueError(f"Resource already opened: {resource_type}")
189
197
 
@@ -197,7 +205,7 @@ class ResourceManager:
197
205
  try:
198
206
  fd = self.vmfs.file_descriptor(address)
199
207
  except FileNotFoundError:
200
- return None
208
+ return
201
209
 
202
210
  if (
203
211
  fd.descriptor.address != address
@@ -205,7 +213,7 @@ class ResourceManager:
205
213
  or fd.type != FileType.System
206
214
  or fd.size == 0
207
215
  ):
208
- return None
216
+ return
209
217
 
210
218
  fileobj = fd.open()
211
219
 
@@ -214,60 +222,56 @@ class ResourceManager:
214
222
  self.vmfs, resource_type, address, fileobj
215
223
  )
216
224
  except Exception:
217
- return None
225
+ return
218
226
 
219
- def _get_resource_for_resource_type(self, resource_type):
227
+ def _get_resource_for_resource_type(self, resource_type: ResourceType) -> ResourceFile:
220
228
  resource_type = int(resource_type)
221
229
 
222
230
  if resource_type not in self.resources:
223
231
  raise ValueError(f"No resource opened for type {ResourceType(resource_type)}")
224
232
  return self.resources[resource_type]
225
233
 
226
- def _get_resource_for_address(self, address):
234
+ def _get_resource_for_address(self, address: int) -> ResourceFile:
227
235
  addr_type = address_type(address)
228
236
  return self._get_resource_for_resource_type(addr_type)
229
237
 
230
- def get(self, address):
238
+ def get(self, address: int) -> bytes:
231
239
  resource = self._get_resource_for_address(address)
232
240
  return resource.get(address)
233
241
 
234
- def get_resource(self, resource_type, cluster, resource):
242
+ def get_resource(self, resource_type: ResourceType, cluster: int, resource: int) -> bytes:
235
243
  return self._get_resource_for_resource_type(resource_type).get_resource(cluster, resource)
236
244
 
237
- def parse_address(self, address):
245
+ def parse_address(self, address: int) -> tuple[int, int]:
238
246
  resource = self._get_resource_for_address(address)
239
247
  return resource.parse_address(address)
240
248
 
241
- def resolve_address(self, address):
242
- resource = self._get_resource_for_address(address)
243
- return resource.resolve_address(address)
244
-
245
249
  @property
246
- def fdc(self):
250
+ def fdc(self) -> FileDescriptorResource:
247
251
  return self._get_resource_for_resource_type(ResourceType.FD)
248
252
 
249
253
  @property
250
- def pb2(self):
254
+ def pb2(self) -> PointerBlockResource:
251
255
  return self._get_resource_for_resource_type(ResourceType.PB2)
252
256
 
253
257
  @property
254
- def pbc(self):
258
+ def pbc(self) -> PointerBlockResource:
255
259
  return self._get_resource_for_resource_type(ResourceType.PB)
256
260
 
257
261
  @property
258
- def sbc(self):
262
+ def sbc(self) -> SubBlockResource:
259
263
  return self._get_resource_for_resource_type(ResourceType.SB)
260
264
 
261
265
  @property
262
- def fbb(self):
266
+ def fbb(self) -> SmallFileBlockResource:
263
267
  return self._get_resource_for_resource_type(ResourceType.FB)
264
268
 
265
269
  @property
266
- def lfb(self):
270
+ def lfb(self) -> LargeFileBlockResource:
267
271
  return self._get_resource_for_resource_type(ResourceType.LFB)
268
272
 
269
273
  @property
270
- def jbc(self):
274
+ def jbc(self) -> JournalBlockResource:
271
275
  return self._get_resource_for_resource_type(ResourceType.JB)
272
276
 
273
277
 
@@ -280,7 +284,7 @@ class ResourceFile:
280
284
  up of the clusters ("bitmaps"), followed by the actual resource items.
281
285
  """
282
286
 
283
- def __init__(self, vmfs, resource_type, address, fh):
287
+ def __init__(self, vmfs: VMFS, resource_type: ResourceType, address: int, fh: BinaryIO):
284
288
  self.vmfs = vmfs
285
289
  self.type = resource_type
286
290
  self.address = address
@@ -298,17 +302,17 @@ class ResourceFile:
298
302
  self._cluster_resource_offset = self.metadata.clustersPerClusterGroup * alignment
299
303
  self._cluster_size = self.metadata.resourcePerCluster * self.metadata.resourceSize
300
304
 
301
- def iter_resource_locations(self):
305
+ def iter_resource_locations(self) -> Iterator[tuple[int, int]]:
302
306
  resource_per_cluster = self.metadata.resourcePerCluster
303
307
  num_resources = (self.metadata.numResourcesHi << 32) | self.metadata.numResourcesLo
304
308
  for abs_resource in range(num_resources):
305
309
  yield divmod(abs_resource, resource_per_cluster)
306
310
 
307
311
  @property
308
- def resource_size(self):
312
+ def resource_size(self) -> int:
309
313
  return self.metadata.resourceSize
310
314
 
311
- def _cluster_header_offset(self, cluster):
315
+ def _cluster_header_offset(self, cluster: int) -> int:
312
316
  """Calculate the offset of a specific cluster header into the resource file."""
313
317
  md = self.metadata
314
318
  if self.vmfs.is_vmfs5:
@@ -316,33 +320,31 @@ class ResourceFile:
316
320
  group_offset = group * md.clusterGroupSize
317
321
  cluster_offset = rel_cluster << 10
318
322
  return md.firstClusterGroupOffset + group_offset + cluster_offset
319
- elif md.flags & 2 == 0:
323
+ if md.flags & 2 == 0:
320
324
  group, rel_cluster = divmod(cluster, md.clustersPerClusterGroup)
321
325
  group_offset = group * md.clusterGroupSize
322
326
  cluster_offset = rel_cluster * (2 * self.vmfs.descriptor.mdAlignment)
323
327
  return md.firstClusterGroupOffset + group_offset + cluster_offset
324
- else:
325
- parent_r_per_cg = md.parentResourcesPerCluster * md.parentClustersPerClusterGroup
326
- group, rel_cluster = divmod(cluster, parent_r_per_cg)
327
- group_offset = group * md.parentClusterGroupSize
328
- cluster_offset = md.parentClustersPerClusterGroup * (2 * self.vmfs.descriptor.mdAlignment) + rel_cluster
329
- return md.firstClusterGroupOffset + group_offset + cluster_offset
328
+ parent_r_per_cg = md.parentResourcesPerCluster * md.parentClustersPerClusterGroup
329
+ group, rel_cluster = divmod(cluster, parent_r_per_cg)
330
+ group_offset = group * md.parentClusterGroupSize
331
+ cluster_offset = md.parentClustersPerClusterGroup * (2 * self.vmfs.descriptor.mdAlignment) + rel_cluster
332
+ return md.firstClusterGroupOffset + group_offset + cluster_offset
330
333
 
331
- def _cluster_group_offset(self, group):
334
+ def _cluster_group_offset(self, group: int) -> int:
332
335
  """Calculate the offset of a specific cluster group into the resource file."""
333
336
  md = self.metadata
334
337
  if self.vmfs.is_vmfs5 or (md.flags & 2 == 0):
335
338
  # Don't know what this flag means, maybe a compatibility flag for VMFS6 to work with VMFS5 resource files?
336
339
  return md.firstClusterGroupOffset + (group * md.clusterGroupSize)
337
- else:
338
- parent_size = md.parentClustersPerClusterGroup * md.parentSourcesPerCluster // md.clustersPerClusterGroup
339
- parent, rel_group = divmod(group, parent_size)
340
- parent_offset = parent * md.parentClusterGroupSize
341
- alignment = md.parentClustersPerClusterGroup * (2 * self.vmfs.descriptor.mdAlignment)
342
- group_offset = rel_group * md.clusterGroupSize
343
- return md.firstClusterGroupOffset + parent_offset + group_offset + alignment
344
-
345
- def _resource_offset(self, cluster, resource):
340
+ parent_size = md.parentClustersPerClusterGroup * md.parentSourcesPerCluster // md.clustersPerClusterGroup
341
+ parent, rel_group = divmod(group, parent_size)
342
+ parent_offset = parent * md.parentClusterGroupSize
343
+ alignment = md.parentClustersPerClusterGroup * (2 * self.vmfs.descriptor.mdAlignment)
344
+ group_offset = rel_group * md.clusterGroupSize
345
+ return md.firstClusterGroupOffset + parent_offset + group_offset + alignment
346
+
347
+ def _resource_offset(self, cluster: int, resource: int) -> int:
346
348
  """Calculate the offset of a specific resource into the resource file."""
347
349
  md = self.metadata
348
350
  group, rel_cluster = divmod(cluster, md.clustersPerClusterGroup)
@@ -351,16 +353,16 @@ class ResourceFile:
351
353
  resource_offset = resource * md.resourceSize
352
354
  return group_offset + self._cluster_resource_offset + cluster_offset + resource_offset
353
355
 
354
- def parse_address(self, address):
356
+ def parse_address(self, address: int) -> tuple[int, int]:
355
357
  """Parse an address into a cluster/resource pair to use for looking up a resource."""
356
358
  raise NotImplementedError("Needs to be implemented by subclasses")
357
359
 
358
- def get(self, address):
360
+ def get(self, address: int) -> bytes:
359
361
  """Get the resource belonging to the given address."""
360
362
  cluster, resource = self.parse_address(address)
361
363
  return self.get_resource(cluster, resource)
362
364
 
363
- def get_resource(self, cluster, resource):
365
+ def get_resource(self, cluster: int, resource: int) -> bytes:
364
366
  """Get the resource belonging to the given cluster/resource pair."""
365
367
  offset = self._resource_offset(cluster, resource)
366
368
  self.fh.seek(offset)
@@ -368,36 +370,39 @@ class ResourceFile:
368
370
 
369
371
 
370
372
  class SmallFileBlockResource(ResourceFile):
371
- def parse_address(self, address):
373
+ def parse_address(self, address: int) -> tuple[int, int]:
372
374
  if self.vmfs.is_vmfs5:
373
375
  block = parse_fb_address(self.vmfs, address)
374
376
  return divmod(block, self.metadata.resourcePerCluster)
375
- elif self.vmfs.is_vmfs6:
377
+
378
+ if self.vmfs.is_vmfs6:
376
379
  return parse_sfb_address(self.vmfs, address)
377
380
 
381
+ raise ValueError("Unknown VMFS version")
382
+
378
383
 
379
384
  class SubBlockResource(ResourceFile):
380
- def parse_address(self, address):
385
+ def parse_address(self, address: int) -> tuple[int, int]:
381
386
  return parse_sb_address(self.vmfs, address)
382
387
 
383
388
 
384
389
  class PointerBlockResource(ResourceFile):
385
- def parse_address(self, address):
390
+ def parse_address(self, address: int) -> tuple[int, int]:
386
391
  return parse_pb_address(self.vmfs, address)
387
392
 
388
393
 
389
394
  class FileDescriptorResource(ResourceFile):
390
- def parse_address(self, address):
395
+ def parse_address(self, address: int) -> tuple[int, int]:
391
396
  return parse_fd_address(self.vmfs, address)
392
397
 
393
398
 
394
399
  class JournalBlockResource(ResourceFile):
395
- def parse_address(self, address):
400
+ def parse_address(self, address: int) -> tuple[int, int]:
396
401
  return parse_jb_address(self.vmfs, address)
397
402
 
398
403
 
399
404
  class LargeFileBlockResource(ResourceFile):
400
- def parse_address(self, address):
405
+ def parse_address(self, address: int) -> tuple[int, int]:
401
406
  block = parse_lfb_address(self.vmfs, address)
402
407
  return divmod(block, self.metadata.resourcePerCluster)
403
408
 
@@ -1,11 +1,13 @@
1
1
  # References:
2
2
  # - /usr/lib/vmware/vmkmod/vmfs3
3
3
  # - /bin/vmkfstools
4
+ from __future__ import annotations
4
5
 
5
6
  import stat
6
7
  import struct
7
8
  from functools import cached_property, lru_cache
8
9
  from io import BytesIO
10
+ from typing import TYPE_CHECKING, BinaryIO
9
11
 
10
12
  from dissect.util import ts
11
13
  from dissect.util.stream import AlignedStream
@@ -34,6 +36,10 @@ from dissect.vmfs.resource import (
34
36
  parse_sfb_address,
35
37
  )
36
38
 
39
+ if TYPE_CHECKING:
40
+ from collections.abc import Iterator
41
+ from datetime import datetime
42
+
37
43
 
38
44
  class VMFS:
39
45
  """VMFS filesystem implementation.
@@ -55,7 +61,17 @@ class VMFS:
55
61
  sacrifice of some human readability. Comments explaining as such are placed where appropriate.
56
62
  """
57
63
 
58
- def __init__(self, volume=None, vh=None, fdc=None, fbb=None, sbc=None, pbc=None, pb2=None, jbc=None):
64
+ def __init__(
65
+ self,
66
+ volume: BinaryIO | None = None,
67
+ vh: BinaryIO | None = None,
68
+ fdc: BinaryIO | None = None,
69
+ fbb: BinaryIO | None = None,
70
+ sbc: BinaryIO | None = None,
71
+ pbc: BinaryIO | None = None,
72
+ pb2: BinaryIO | None = None,
73
+ jbc: BinaryIO | None = None,
74
+ ):
59
75
  self.fh = volume
60
76
 
61
77
  if volume:
@@ -225,18 +241,18 @@ class VMFS:
225
241
  self.resources.open(ResourceType.JB, address=c_vmfs.JB_DESC_ADDR)
226
242
 
227
243
  @property
228
- def is_vmfs5(self):
244
+ def is_vmfs5(self) -> bool:
229
245
  return self.major_version <= 0x17
230
246
 
231
247
  @property
232
- def is_vmfs6(self):
248
+ def is_vmfs6(self) -> bool:
233
249
  return self.major_version > 0x17
234
250
 
235
- def get(self, path, node=None):
251
+ def get(self, path: str | int, node: FileDescriptor | None = None) -> FileDescriptor:
236
252
  if isinstance(path, int):
237
253
  return self.file_descriptor(path)
238
254
 
239
- node = self.root if not node else node
255
+ node = node if node else self.root
240
256
 
241
257
  parts = path.split("/")
242
258
  for p in parts:
@@ -252,13 +268,13 @@ class VMFS:
252
268
 
253
269
  return node
254
270
 
255
- def file_descriptor(self, address, name=None, filetype=None):
271
+ def file_descriptor(self, address: int, name: str | None = None, filetype: int | None = None) -> FileDescriptor:
256
272
  if address_type(address) != ResourceType.FD:
257
273
  raise TypeError(f"Invalid block type: {address_fmt(self, address)}")
258
274
 
259
275
  return FileDescriptor(self, address, name, filetype)
260
276
 
261
- def iter_fd(self):
277
+ def iter_fd(self) -> Iterator[FileDescriptor]:
262
278
  for cluster, resource in self.resources.fdc.iter_resource_locations():
263
279
  fd_addr = (cluster << 6) | (resource << 22) | ResourceType.FD.value
264
280
  yield self.file_descriptor(fd_addr)
@@ -288,7 +304,7 @@ class FileDescriptor:
288
304
  again (mostly) an array of directory entries.
289
305
  """
290
306
 
291
- def __init__(self, vmfs, address, name=None, filetype=None):
307
+ def __init__(self, vmfs: VMFS, address: int, name: str | None = None, filetype: int | None = None):
292
308
  self.vmfs = vmfs
293
309
  self.address = address
294
310
  self.name = name
@@ -298,42 +314,42 @@ class FileDescriptor:
298
314
  self._lock_info = None
299
315
  self._desc = None
300
316
 
301
- def __repr__(self):
317
+ def __repr__(self) -> str:
302
318
  return f"<FileDescriptor address={address_fmt(self.vmfs, self.address)} name={self.name}>"
303
319
 
304
320
  @cached_property
305
- def raw(self):
321
+ def raw(self) -> memoryview:
306
322
  """The raw buffer of this file descriptor."""
307
323
  return memoryview(self.vmfs.resources.fdc.get(self.address))
308
324
 
309
325
  @cached_property
310
- def lock_info(self):
326
+ def lock_info(self) -> c_vmfs.FS3_DiskLockInfo:
311
327
  """The parsed lock info of this file descriptor."""
312
328
  return c_vmfs.FS3_DiskLockInfo(self.raw)
313
329
 
314
330
  @cached_property
315
- def descriptor(self):
331
+ def descriptor(self) -> c_vmfs.FS3_FileDescriptor:
316
332
  """The parsed file descriptor struct for this file descriptor."""
317
333
  desc_offset = self.vmfs.descriptor.mdAlignment or c_vmfs.VMFS5_MD_ALIGNMENT
318
334
  return c_vmfs.FS3_FileDescriptor(self.raw[desc_offset:])
319
335
 
320
336
  @property
321
- def parent(self):
337
+ def parent(self) -> FileDescriptor | None:
322
338
  parent_fd = self.descriptor.parentFD
323
339
  return self.vmfs.file_descriptor(parent_fd) if parent_fd else None
324
340
 
325
341
  @property
326
- def size(self):
342
+ def size(self) -> int:
327
343
  """The size of this file."""
328
344
  return self.descriptor.length
329
345
 
330
346
  @property
331
- def type(self):
347
+ def type(self) -> int:
332
348
  """The type of this file."""
333
349
  return self._type or self.descriptor.type
334
350
 
335
351
  @property
336
- def zla(self):
352
+ def zla(self) -> int:
337
353
  """The ZLA of this file."""
338
354
  # This is how vmfs-tool does it
339
355
  # Don't think this is actually how the ZLA works, but let's roll with it for now
@@ -343,73 +359,72 @@ class FileDescriptor:
343
359
  return zla
344
360
 
345
361
  @property
346
- def mode(self):
362
+ def mode(self) -> int:
347
363
  """The file mode of this file."""
348
364
  if stat.S_IFMT(self.descriptor.mode) == stat.S_IFDIR:
349
365
  return self.descriptor.mode
350
- else:
351
- return self.descriptor.mode | type_to_mode(self.type)
366
+ return self.descriptor.mode | type_to_mode(self.type)
352
367
 
353
368
  @property
354
- def block_size(self):
369
+ def block_size(self) -> int:
355
370
  """The file specific block size of this file."""
356
371
  return self.descriptor.blockSize
357
372
 
358
373
  @cached_property
359
- def blocks(self):
374
+ def blocks(self) -> list[int]:
360
375
  """The block array of this file."""
361
376
  block_buf = self.raw[self.vmfs._fd_block_data_offset :]
362
377
  ctype = c_vmfs.uint32 if self.vmfs.is_vmfs5 else c_vmfs.uint64
363
378
  return ctype[self.vmfs._fd_block_count](block_buf)
364
379
 
365
380
  @cached_property
366
- def atime(self):
381
+ def atime(self) -> datetime:
367
382
  """The last access time of this file."""
368
383
  return ts.from_unix(self.descriptor.accessTime)
369
384
 
370
385
  @cached_property
371
- def mtime(self):
386
+ def mtime(self) -> datetime:
372
387
  """The last modified time of this file."""
373
388
  return ts.from_unix(self.descriptor.modificationTime)
374
389
 
375
390
  @cached_property
376
- def ctime(self):
391
+ def ctime(self) -> datetime:
377
392
  """The creation time of this file."""
378
393
  return ts.from_unix(self.descriptor.creationTime)
379
394
 
380
395
  @cached_property
381
- def link(self):
396
+ def link(self) -> str:
382
397
  """The destination of this file, if it's a symlink."""
383
398
  if not self.is_symlink():
384
399
  raise NotASymlinkError(f"{self} is not a symlink")
385
400
 
386
401
  return self.open().read().decode("utf-8")
387
402
 
388
- def is_dir(self):
403
+ def is_dir(self) -> bool:
389
404
  """Is this file a directory?"""
390
405
  return self.type == FileType.Directory
391
406
 
392
- def is_file(self):
407
+ def is_file(self) -> bool:
393
408
  """Is this file a regular file?"""
394
409
  return self.type == FileType.Regular
395
410
 
396
- def is_symlink(self):
411
+ def is_symlink(self) -> bool:
397
412
  """Is this file a symlink?"""
398
413
  return self.type == FileType.Symlink
399
414
 
400
- def is_system(self):
415
+ def is_system(self) -> bool:
401
416
  """Is this file a system file?"""
402
417
  return self.type == FileType.System
403
418
 
404
- def is_rdm(self):
419
+ def is_rdm(self) -> bool:
405
420
  """Is this file a RDM file?"""
406
421
  return self.type == FileType.RDM
407
422
 
408
- def listdir(self):
423
+ def listdir(self) -> dict[str, FileDescriptor]:
409
424
  """A dictionary of the content of this directory, if this file is a directory."""
410
425
  return {n.name: n for n in self.iterdir()}
411
426
 
412
- def iterdir(self):
427
+ def iterdir(self) -> Iterator[FileDescriptor]:
413
428
  """Iterate file descriptors of the directory entries, if this file is a directory."""
414
429
  if not self.is_dir():
415
430
  raise NotADirectoryError(repr(self))
@@ -419,7 +434,7 @@ class FileDescriptor:
419
434
  else:
420
435
  yield from self._iterdir_vmfs6()
421
436
 
422
- def _iterdir_vmfs5(self):
437
+ def _iterdir_vmfs5(self) -> Iterator[FileDescriptor]:
423
438
  buf = self.open()
424
439
 
425
440
  num_entries = self.size // c_vmfs.VMFS5_DIR_ENTRY_SIZE
@@ -430,7 +445,7 @@ class FileDescriptor:
430
445
 
431
446
  yield self.vmfs.file_descriptor(dirent.address, dirent.name.split(b"\x00")[0].decode(), dirent.type)
432
447
 
433
- def _iterdir_vmfs6(self):
448
+ def _iterdir_vmfs6(self) -> Iterator[FileDescriptor]:
434
449
  # Directories in VMFS6 are a bit more complex.
435
450
  # They start out with a header/metadata block, which contains some useful info.
436
451
  # This block also contains the . and .. entries, as well as a bitmap?
@@ -480,7 +495,7 @@ class FileDescriptor:
480
495
 
481
496
  yield self.vmfs.file_descriptor(dirent.address, dirent.name.split(b"\x00")[0].decode(), dirent.type)
482
497
 
483
- def open(self):
498
+ def open(self) -> BytesIO | BlockStream:
484
499
  """Open this file and return a new file-like object."""
485
500
  if self.is_rdm():
486
501
  raise NotImplementedError(f"Can't open RDM file {self}")
@@ -506,7 +521,7 @@ class BlockStream(AlignedStream):
506
521
  LFB (large filesystem block).
507
522
  """
508
523
 
509
- def __init__(self, descriptor):
524
+ def __init__(self, descriptor: FileDescriptor):
510
525
  self.descriptor = descriptor
511
526
  self.vmfs = descriptor.vmfs
512
527
  self.blocks = self.descriptor.blocks
@@ -524,12 +539,12 @@ class BlockStream(AlignedStream):
524
539
 
525
540
  super().__init__(self.descriptor.size)
526
541
 
527
- def _offset_to_block(self, offset):
542
+ def _offset_to_block(self, offset: int) -> int:
528
543
  idx = offset >> self.block_offset_shift
529
544
  if self.zla in (ResourceType.FB, ResourceType.SB):
530
545
  return self.blocks[idx]
531
546
 
532
- elif self.zla == ResourceType.PB:
547
+ if self.zla == ResourceType.PB:
533
548
  # This is equivalent to divmod(idx, addressesPerPb)
534
549
  if self.vmfs.is_vmfs5:
535
550
  # Don't think this really means "vmfs5_extension"
@@ -546,54 +561,51 @@ class BlockStream(AlignedStream):
546
561
  secondary_pb_buf = self.vmfs.resources.pbc.get(secondary_block)
547
562
 
548
563
  return _get_uint32_index(secondary_pb_buf, tertiary_idx)
549
- else:
550
- # Single indirection
551
- primary_idx = (idx >> self.vmfs._pb_index_shift) & ((1 << self.vmfs._pb_index_shift) - 1)
552
- secondary_idx = idx & ((1 << self.vmfs._pb_index_shift) - 1)
564
+ # Single indirection
565
+ primary_idx = (idx >> self.vmfs._pb_index_shift) & ((1 << self.vmfs._pb_index_shift) - 1)
566
+ secondary_idx = idx & ((1 << self.vmfs._pb_index_shift) - 1)
553
567
 
554
- primary_block = self.blocks[primary_idx]
555
- primary_pb_buf = self.vmfs.resources.pbc.get(primary_block)
568
+ primary_block = self.blocks[primary_idx]
569
+ primary_pb_buf = self.vmfs.resources.pbc.get(primary_block)
556
570
 
557
- return _get_uint32_index(primary_pb_buf, secondary_idx)
558
- else:
559
- if self.vmfs5_extension:
560
- # Double indirection
561
- primary_idx = idx >> (2 * self.vmfs._pb_index_shift)
562
- secondary_idx = (idx >> self.vmfs._pb_index_shift) & ((1 << self.vmfs._pbc_index_shift) - 1)
563
- tertiary_idx = idx & ((1 << self.vmfs._pbc_index_shift) - 1)
571
+ return _get_uint32_index(primary_pb_buf, secondary_idx)
572
+ if self.vmfs5_extension:
573
+ # Double indirection
574
+ primary_idx = idx >> (2 * self.vmfs._pb_index_shift)
575
+ secondary_idx = (idx >> self.vmfs._pb_index_shift) & ((1 << self.vmfs._pbc_index_shift) - 1)
576
+ tertiary_idx = idx & ((1 << self.vmfs._pbc_index_shift) - 1)
564
577
 
565
- primary_block = self.blocks[primary_idx]
566
- primary_pb_buf = self.vmfs.resources.sbc.get(primary_block)
578
+ primary_block = self.blocks[primary_idx]
579
+ primary_pb_buf = self.vmfs.resources.sbc.get(primary_block)
567
580
 
568
- # NOTE: can become LFB here?
569
- secondary_block = _get_uint64_index(primary_pb_buf, secondary_idx)
581
+ # NOTE: can become LFB here?
582
+ secondary_block = _get_uint64_index(primary_pb_buf, secondary_idx)
570
583
 
571
- if address_type(secondary_block) == ResourceType.LFB:
572
- return secondary_block
584
+ if address_type(secondary_block) == ResourceType.LFB:
585
+ return secondary_block
573
586
 
574
- secondary_pb_buf = self.vmfs.resources.sbc.get(secondary_block)
587
+ secondary_pb_buf = self.vmfs.resources.sbc.get(secondary_block)
575
588
 
576
- # NOTE: there are some flags that can influence the final index
577
- # NOTE: can become LFB here?
578
- return _get_uint64_index(secondary_pb_buf, tertiary_idx)
579
- else:
580
- # Single indirection
581
- primary_idx = idx >> self.vmfs._pb_index_shift
582
- secondary_idx = idx & ((1 << self.vmfs._pbc_index_shift) - 1)
589
+ # NOTE: there are some flags that can influence the final index
590
+ # NOTE: can become LFB here?
591
+ return _get_uint64_index(secondary_pb_buf, tertiary_idx)
592
+ # Single indirection
593
+ primary_idx = idx >> self.vmfs._pb_index_shift
594
+ secondary_idx = idx & ((1 << self.vmfs._pbc_index_shift) - 1)
583
595
 
584
- # NOTE: can become LFB here?
585
- primary_block = self.blocks[primary_idx]
596
+ # NOTE: can become LFB here?
597
+ primary_block = self.blocks[primary_idx]
586
598
 
587
- if address_type(primary_block) == ResourceType.LFB:
588
- return primary_block
599
+ if address_type(primary_block) == ResourceType.LFB:
600
+ return primary_block
589
601
 
590
- primary_pb_buf = self.vmfs.resources.sbc.get(primary_block)
602
+ primary_pb_buf = self.vmfs.resources.sbc.get(primary_block)
591
603
 
592
- # NOTE: there are some flags that can influence the final index
593
- # NOTE: can become LFB here?
594
- return _get_uint64_index(primary_pb_buf, secondary_idx)
604
+ # NOTE: there are some flags that can influence the final index
605
+ # NOTE: can become LFB here?
606
+ return _get_uint64_index(primary_pb_buf, secondary_idx)
595
607
 
596
- elif self.zla == ResourceType.PB2:
608
+ if self.zla == ResourceType.PB2:
597
609
  # This is equivalent to divmod(idx, addressesPerPb2)
598
610
  primary_idx = idx >> (2 * self.vmfs._pb_index_shift)
599
611
  secondary_idx = idx & ((1 << self.vmfs._pb_index_shift) - 1)
@@ -603,12 +615,10 @@ class BlockStream(AlignedStream):
603
615
 
604
616
  if self.vmfs.is_vmfs5:
605
617
  return _get_uint32_index(primary_pb_buf, secondary_idx)
606
- else:
607
- return _get_uint64_index(primary_pb_buf, secondary_idx)
608
- else:
609
- raise ValueError(f"Unexpected ZLA in {self.descriptor}: {self.zla}")
618
+ return _get_uint64_index(primary_pb_buf, secondary_idx)
619
+ raise ValueError(f"Unexpected ZLA in {self.descriptor}: {self.zla}")
610
620
 
611
- def _read(self, offset, length):
621
+ def _read(self, offset: int, length: int) -> bytes:
612
622
  r = []
613
623
  while length > 0:
614
624
  block_address = self._offset_to_block(offset)
@@ -662,7 +672,7 @@ class BlockStream(AlignedStream):
662
672
  return b"".join(r)
663
673
 
664
674
 
665
- def _read_offset_and_length(offset, length, block_size):
675
+ def _read_offset_and_length(offset: int, length: int, block_size: int) -> tuple[int, int]:
666
676
  """Convenience function to calculate in-block offsets and remaining read sizes."""
667
677
  offset_in_block = offset % block_size
668
678
  remaining_in_block = block_size - offset_in_block
@@ -671,11 +681,11 @@ def _read_offset_and_length(offset, length, block_size):
671
681
  return offset_in_block, read_length
672
682
 
673
683
 
674
- def _get_uint32_index(buf, index):
684
+ def _get_uint32_index(buf: bytes, index: int) -> int:
675
685
  """Convenience function to index into a uint32 sized array."""
676
686
  return struct.unpack("<I", buf[index * 4 : (index * 4) + 4])[0]
677
687
 
678
688
 
679
- def _get_uint64_index(buf, index):
689
+ def _get_uint64_index(buf: bytes, index: int) -> int:
680
690
  """Convenience function to index into a uint64 sized array."""
681
691
  return struct.unpack("<Q", buf[index * 8 : (index * 8) + 8])[0]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dissect.vmfs
3
- Version: 3.10.dev1
3
+ Version: 3.11.dev2
4
4
  Summary: A Dissect module implementing a parser for the VMFS file system, used by VMware virtualization software
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -1,3 +1,4 @@
1
+ .git-blame-ignore-revs
1
2
  COPYRIGHT
2
3
  LICENSE
3
4
  MANIFEST.in
@@ -41,13 +41,56 @@ dev = [
41
41
  "dissect.util>=3.0.dev,<4.0.dev",
42
42
  ]
43
43
 
44
- [tool.black]
44
+ [tool.ruff]
45
45
  line-length = 120
46
+ required-version = ">=0.9.0"
46
47
 
47
- [tool.isort]
48
- profile = "black"
49
- known_first_party = ["dissect.vmfs"]
50
- known_third_party = ["dissect"]
48
+ [tool.ruff.format]
49
+ docstring-code-format = true
50
+
51
+ [tool.ruff.lint]
52
+ select = [
53
+ "F",
54
+ "E",
55
+ "W",
56
+ "I",
57
+ "UP",
58
+ "YTT",
59
+ "ANN",
60
+ "B",
61
+ "C4",
62
+ "DTZ",
63
+ "T10",
64
+ "FA",
65
+ "ISC",
66
+ "G",
67
+ "INP",
68
+ "PIE",
69
+ "PYI",
70
+ "PT",
71
+ "Q",
72
+ "RSE",
73
+ "RET",
74
+ "SLOT",
75
+ "SIM",
76
+ "TID",
77
+ "TCH",
78
+ "PTH",
79
+ "PLC",
80
+ "TRY",
81
+ "FLY",
82
+ "PERF",
83
+ "FURB",
84
+ "RUF",
85
+ ]
86
+ ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
87
+
88
+ [tool.ruff.lint.per-file-ignores]
89
+ "tests/docs/**" = ["INP001"]
90
+
91
+ [tool.ruff.lint.isort]
92
+ known-first-party = ["dissect.vmfs"]
93
+ known-third-party = ["dissect"]
51
94
 
52
95
  [tool.setuptools]
53
96
  license-files = ["LICENSE", "COPYRIGHT"]
@@ -0,0 +1,28 @@
1
+ from __future__ import annotations
2
+
3
+ import gzip
4
+ from pathlib import Path
5
+ from typing import TYPE_CHECKING, BinaryIO
6
+
7
+ import pytest
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterator
11
+
12
+
13
+ def absolute_path(filename: str) -> Path:
14
+ return Path(__file__).parent / filename
15
+
16
+
17
+ @pytest.fixture
18
+ def vmfs5() -> Iterator[BinaryIO]:
19
+ name = "data/vmfs5.bin.gz"
20
+ with gzip.GzipFile(absolute_path(name), "rb") as fh:
21
+ yield fh
22
+
23
+
24
+ @pytest.fixture
25
+ def vmfs6() -> Iterator[BinaryIO]:
26
+ name = "data/vmfs6.bin.gz"
27
+ with gzip.GzipFile(absolute_path(name), "rb") as fh:
28
+ yield fh
@@ -1,10 +1,12 @@
1
+ from __future__ import annotations
2
+
1
3
  from unittest.mock import Mock
2
4
 
3
5
  from dissect.vmfs.c_vmfs import ResourceType
4
6
  from dissect.vmfs.resource import address_fmt, address_type
5
7
 
6
8
 
7
- def test_address_type():
9
+ def test_address_type() -> None:
8
10
  assert address_type(0x00000001) == ResourceType.FB
9
11
  assert address_type(0x00000002) == ResourceType.SB
10
12
  assert address_type(0x00000003) == ResourceType.PB
@@ -14,7 +16,7 @@ def test_address_type():
14
16
  assert address_type(0x00000007) == ResourceType.LFB
15
17
 
16
18
 
17
- def test_address_fmt_vmfs5():
19
+ def test_address_fmt_vmfs5() -> None:
18
20
  mock_vmfs5 = Mock()
19
21
  mock_vmfs5.is_vmfs5 = True
20
22
  mock_vmfs5.is_vmfs6 = False
@@ -61,7 +63,7 @@ def test_address_fmt_vmfs5():
61
63
  assert address_fmt(mock_vmfs5, 0x00000000) == "<Null address>"
62
64
 
63
65
 
64
- def test_address_fmt_vmfs6():
66
+ def test_address_fmt_vmfs6() -> None:
65
67
  mock_vmfs6 = Mock()
66
68
  mock_vmfs6.is_vmfs5 = False
67
69
  mock_vmfs6.is_vmfs6 = True
@@ -1,10 +1,12 @@
1
+ from __future__ import annotations
2
+
1
3
  import pytest
2
4
 
3
5
  from dissect.vmfs import exceptions
4
6
 
5
7
 
6
8
  @pytest.mark.parametrize(
7
- "exc, std",
9
+ ("exc", "std"),
8
10
  [
9
11
  (exceptions.FileNotFoundError, FileNotFoundError),
10
12
  (exceptions.IsADirectoryError, IsADirectoryError),
@@ -1,7 +1,11 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import BinaryIO
4
+
1
5
  from dissect.vmfs import lvm
2
6
 
3
7
 
4
- def test_lvm5(vmfs5):
8
+ def test_lvm5(vmfs5: BinaryIO) -> None:
5
9
  vs = lvm.LVM(vmfs5)
6
10
 
7
11
  assert vs.uuid == "61137dd5-d0727810-7ac2-000c29801686"
@@ -17,7 +21,7 @@ def test_lvm5(vmfs5):
17
21
  assert extent.last_pe == 0
18
22
 
19
23
 
20
- def test_lvm6(vmfs6):
24
+ def test_lvm6(vmfs6: BinaryIO) -> None:
21
25
  vs = lvm.LVM(vmfs6)
22
26
 
23
27
  assert vs.uuid == "6113001e-95afd8fb-d830-000c29801686"
@@ -1,9 +1,12 @@
1
+ from __future__ import annotations
2
+
1
3
  import io
4
+ from typing import BinaryIO
2
5
 
3
6
  from dissect.vmfs import lvm, vmfs
4
7
 
5
8
 
6
- def test_vmfs5(vmfs5):
9
+ def test_vmfs5(vmfs5: BinaryIO) -> None:
7
10
  fh = lvm.LVM(vmfs5)
8
11
  fs = vmfs.VMFS(fh)
9
12
 
@@ -30,7 +33,7 @@ def test_vmfs5(vmfs5):
30
33
  verify_fs_content(fs)
31
34
 
32
35
 
33
- def test_vmfs6(vmfs6):
36
+ def test_vmfs6(vmfs6: BinaryIO) -> None:
34
37
  fh = lvm.LVM(vmfs6)
35
38
  fs = vmfs.VMFS(fh)
36
39
 
@@ -59,7 +62,7 @@ def test_vmfs6(vmfs6):
59
62
  verify_fs_content(fs)
60
63
 
61
64
 
62
- def verify_fs_content(fs):
65
+ def verify_fs_content(fs: vmfs.VMFS) -> None:
63
66
  root_entries = fs.root.listdir()
64
67
 
65
68
  assert ".fbb.sf" in root_entries
@@ -32,32 +32,19 @@ commands =
32
32
  [testenv:fix]
33
33
  package = skip
34
34
  deps =
35
- black==23.1.0
36
- isort==5.11.4
35
+ ruff==0.9.2
37
36
  commands =
38
- black dissect tests
39
- isort dissect tests
37
+ ruff format dissect tests
40
38
 
41
39
  [testenv:lint]
42
40
  package = skip
43
41
  deps =
44
- black==23.1.0
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
- flake8 dissect tests
45
+ ruff check dissect tests
52
46
  vermin -t=3.9- --no-tips --lint dissect tests
53
47
 
54
- [flake8]
55
- max-line-length = 120
56
- extend-ignore =
57
- # See https://github.com/PyCQA/pycodestyle/issues/373
58
- E203,
59
- statistics = True
60
-
61
48
  [testenv:docs-build]
62
49
  allowlist_externals = make
63
50
  deps =
@@ -1,22 +0,0 @@
1
- import gzip
2
- import os
3
-
4
- import pytest
5
-
6
-
7
- def absolute_path(filename):
8
- return os.path.join(os.path.dirname(__file__), filename)
9
-
10
-
11
- @pytest.fixture
12
- def vmfs5():
13
- name = "data/vmfs5.bin.gz"
14
- with gzip.GzipFile(absolute_path(name), "rb") as f:
15
- yield f
16
-
17
-
18
- @pytest.fixture
19
- def vmfs6():
20
- name = "data/vmfs6.bin.gz"
21
- with gzip.GzipFile(absolute_path(name), "rb") as f:
22
- yield f
@@ -9,12 +9,12 @@ from dissect.vmfs.lvm import LVM, Extent
9
9
  from dissect.vmfs.vmfs import VMFS
10
10
 
11
11
  __all__ = [
12
+ "LVM",
13
+ "VMFS",
12
14
  "Error",
15
+ "Extent",
13
16
  "FileNotFoundError",
14
17
  "InvalidHeader",
15
18
  "NotADirectoryError",
16
19
  "NotASymlinkError",
17
- "LVM",
18
- "Extent",
19
- "VMFS",
20
20
  ]