dissect.hypervisor 3.16.dev2__py3-none-any.whl → 3.16.dev3__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.
@@ -1,5 +1,3 @@
1
- from __future__ import annotations
2
-
3
1
  import ctypes
4
2
  import io
5
3
  import logging
@@ -7,7 +5,6 @@ import os
7
5
  import textwrap
8
6
  import zlib
9
7
  from bisect import bisect_right
10
- from dataclasses import dataclass
11
8
  from functools import lru_cache
12
9
  from pathlib import Path
13
10
 
@@ -62,13 +59,13 @@ class VMDK(AlignedStream):
62
59
  if self.descriptor.attr["parentCID"] != "ffffffff":
63
60
  self.parent = open_parent(path.parent, self.descriptor.attr["parentFileNameHint"])
64
61
 
65
- for extent in self.descriptor.extents:
66
- if extent.type in ["SPARSE", "VMFSSPARSE", "SESPARSE"]:
67
- sdisk_fh = path.with_name(extent.filename).open("rb")
62
+ for _, size, extent_type, filename in self.descriptor.extents:
63
+ if extent_type in ["SPARSE", "VMFSSPARSE", "SESPARSE"]:
64
+ sdisk_fh = path.with_name(filename).open("rb")
68
65
  self.disks.append(SparseDisk(sdisk_fh, parent=self.parent))
69
- elif extent.type in ["VMFS", "FLAT"]:
70
- rdisk_fh = path.with_name(extent.filename).open("rb")
71
- self.disks.append(RawDisk(rdisk_fh, extent.sectors * SECTOR_SIZE))
66
+ elif extent_type in ["VMFS", "FLAT"]:
67
+ rdisk_fh = path.with_name(filename).open("rb")
68
+ self.disks.append(RawDisk(rdisk_fh, size * SECTOR_SIZE))
72
69
 
73
70
  elif magic in (COWD_MAGIC, VMDK_MAGIC, SESPARSE_MAGIC):
74
71
  sparse_disk = SparseDisk(fh)
@@ -401,37 +398,8 @@ class SparseExtentHeader:
401
398
  return getattr(self.hdr, attr)
402
399
 
403
400
 
404
- @dataclass
405
- class ExtentDescriptor:
406
- access_mode: str
407
- sectors: int
408
- type: str
409
- filename: str | None = None
410
- start_sector: int | None = None
411
- partition_uuid: str | None = None
412
- device_identifier: str | None = None
413
-
414
- def __post_init__(self) -> None:
415
- self._raw = " ".join(map(str, [v for v in self.__dict__.values() if v is not None]))
416
- self.sectors = int(self.sectors)
417
-
418
- if self.filename:
419
- self.filename = self.filename.strip('"')
420
-
421
- if self.start_sector:
422
- self.start_sector = int(self.start_sector)
423
-
424
- def __repr__(self) -> str:
425
- return f"<ExtentDescriptor {self._raw}>"
426
-
427
- def __str__(self) -> str:
428
- return self._raw
429
-
430
-
431
401
  class DiskDescriptor:
432
- def __init__(
433
- self, attr: dict, extents: list[ExtentDescriptor], disk_db: dict, sectors: int, raw_config: str | None = None
434
- ):
402
+ def __init__(self, attr, extents, disk_db, sectors, raw_config=None):
435
403
  self.attr = attr
436
404
  self.extents = extents
437
405
  self.ddb = disk_db
@@ -439,15 +407,9 @@ class DiskDescriptor:
439
407
  self.raw = raw_config
440
408
 
441
409
  @classmethod
442
- def parse(cls, vmdk_config: str) -> DiskDescriptor:
443
- """Return :class:`DiskDescriptor` based on the provided ``vmdk_config``.
444
-
445
- Resources:
446
- - https://github.com/libyal/libvmdk/blob/main/documentation/VMWare%20Virtual%20Disk%20Format%20(VMDK).asciidoc
447
- """ # noqa: E501
448
-
410
+ def parse(cls, vmdk_config):
449
411
  descriptor_settings = {}
450
- extents: list[ExtentDescriptor] = []
412
+ extents = []
451
413
  disk_db = {}
452
414
  sectors = 0
453
415
 
@@ -458,16 +420,11 @@ class DiskDescriptor:
458
420
  continue
459
421
 
460
422
  if line.startswith("RW ") or line.startswith("RDONLY ") or line.startswith("NOACCESS "):
461
- # Extent descriptors can have up to seven values according to libvmdk documentation.
462
- parts = line.split(" ", maxsplit=6)
463
-
464
- if len(parts) < 3:
465
- log.warning("Unexpected ExtentDescriptor format in vmdk config: %s, ignoring", line)
466
- continue
467
-
468
- extent = ExtentDescriptor(*parts)
469
- sectors += extent.sectors
470
- extents.append(extent)
423
+ access_type, size, extent_type, filename = line.split(" ", 3)
424
+ filename = filename.strip('"')
425
+ size = int(size)
426
+ sectors += size
427
+ extents.append([access_type, size, extent_type, filename])
471
428
  continue
472
429
 
473
430
  setting, _, value = line.partition("=")
@@ -481,33 +438,35 @@ class DiskDescriptor:
481
438
 
482
439
  return cls(descriptor_settings, extents, disk_db, sectors, vmdk_config)
483
440
 
484
- def __str__(self) -> str:
485
- str_template = textwrap.dedent(
486
- """\
487
- # Disk DescriptorFile
488
- version=1
489
- {}
490
-
491
- # Extent Description
492
- {}
441
+ def __str__(self):
442
+ str_template = """\
443
+ # Disk DescriptorFile
444
+ version=1
445
+ {}
493
446
 
494
- # The Disk Data Base
495
- #DDB
447
+ # Extent Description
448
+ {}
496
449
 
497
- {}"""
498
- )
450
+ # The Disk Data Base
451
+ #DDB
499
452
 
453
+ {}"""
454
+ str_template = textwrap.dedent(str_template)
500
455
  descriptor_settings = []
501
456
  for setting, value in self.attr.items():
502
- if setting != "version":
503
- descriptor_settings.append(f"{setting}={value}")
457
+ if setting == "version":
458
+ continue
459
+ descriptor_settings.append("{}={}".format(setting, value))
504
460
  descriptor_settings = "\n".join(descriptor_settings)
505
461
 
506
- extents = "\n".join(map(str, self.extents))
462
+ extents = []
463
+ for access_type, size, extent_type, filename in self.extents:
464
+ extents.append('{} {} {} "{}"'.format(access_type, size, extent_type, filename))
465
+ extents = "\n".join(extents)
507
466
 
508
467
  disk_db = []
509
468
  for setting, value in self.ddb.items():
510
- disk_db.append(f'{setting} = "{value}"')
469
+ disk_db.append('{} = "{}"'.format(setting, value))
511
470
  disk_db = "\n".join(disk_db)
512
471
 
513
472
  return str_template.format(descriptor_settings, extents, disk_db)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dissect.hypervisor
3
- Version: 3.16.dev2
3
+ Version: 3.16.dev3
4
4
  Summary: A Dissect module implementing parsers for various hypervisor disk, backup and configuration files
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -19,16 +19,16 @@ dissect/hypervisor/disk/qcow2.py,sha256=K4zstjte7SxX2psSbAj4YqwGeplfIvfbq5ScP4mz
19
19
  dissect/hypervisor/disk/vdi.py,sha256=_kX7ZGOVo_98ckMaiaDEmw4VjNgM57cY4YUSYrk2JGs,1851
20
20
  dissect/hypervisor/disk/vhd.py,sha256=OqSdEO2NGMI5DjgxWFbtZp8bPjSon7moMJn_5152MbI,3660
21
21
  dissect/hypervisor/disk/vhdx.py,sha256=FVGTY5mUKFb7oRNKNiLGd5ngGfaGvERtFCGhAlyZD_k,12631
22
- dissect/hypervisor/disk/vmdk.py,sha256=nXDWHziwbN1dxD-ehasuFG98mmhrf1Y9rNil0nAcUtI,19104
22
+ dissect/hypervisor/disk/vmdk.py,sha256=KSz_76X_QcInImHNGfCJdN6nF4TmUZ7vqsbZtuUMgbg,18126
23
23
  dissect/hypervisor/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  dissect/hypervisor/tools/envelope.py,sha256=6_RLtKmFnZ69fx8HlvFgsjDjNrfnXD73dgszpG1mYQE,967
25
25
  dissect/hypervisor/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  dissect/hypervisor/util/envelope.py,sha256=6nEJfgsxj696qxaLOQ2k5MrVWA2uLkbB5zxxRAvboF4,10405
27
27
  dissect/hypervisor/util/vmtar.py,sha256=oNJ-qTvQVOl7al_vExpg_T4LnGyE72O9hjOmQBiTKSA,1469
28
- dissect.hypervisor-3.16.dev2.dist-info/COPYRIGHT,sha256=EOOoIwk_inOMUD4c1ylpzMtYLjGzmc-MLEVAEdLLr20,305
29
- dissect.hypervisor-3.16.dev2.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
30
- dissect.hypervisor-3.16.dev2.dist-info/METADATA,sha256=GXm75ZMxlXG4RfswMFCG2Mgflmpt0TMIfOdrxrIf7wA,3420
31
- dissect.hypervisor-3.16.dev2.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
32
- dissect.hypervisor-3.16.dev2.dist-info/entry_points.txt,sha256=oM21bFD0YBHKjgCBk-DQ2398PUZdKV2VNR_IWzd1yog,76
33
- dissect.hypervisor-3.16.dev2.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
34
- dissect.hypervisor-3.16.dev2.dist-info/RECORD,,
28
+ dissect.hypervisor-3.16.dev3.dist-info/COPYRIGHT,sha256=EOOoIwk_inOMUD4c1ylpzMtYLjGzmc-MLEVAEdLLr20,305
29
+ dissect.hypervisor-3.16.dev3.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
30
+ dissect.hypervisor-3.16.dev3.dist-info/METADATA,sha256=kNdewiPG4XwfRU8k2lRLqAbPL5QWlTnRi4SJCmtILlQ,3420
31
+ dissect.hypervisor-3.16.dev3.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
32
+ dissect.hypervisor-3.16.dev3.dist-info/entry_points.txt,sha256=oM21bFD0YBHKjgCBk-DQ2398PUZdKV2VNR_IWzd1yog,76
33
+ dissect.hypervisor-3.16.dev3.dist-info/top_level.txt,sha256=Mn-CQzEYsAbkxrUI0TnplHuXnGVKzxpDw_po_sXpvv4,8
34
+ dissect.hypervisor-3.16.dev3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.5.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5