From 007c4035de233a001d86f4cc2e706a7e502bc386 Mon Sep 17 00:00:00 2001 From: Schamper <1254028+Schamper@users.noreply.github.com> Date: Fri, 24 May 2024 10:44:48 +0200 Subject: [PATCH 1/2] Compatibility with cstruct v4 --- dissect/hypervisor/backup/c_vma.py | 5 ++--- dissect/hypervisor/descriptor/c_hyperv.py | 5 ++--- dissect/hypervisor/disk/c_hdd.py | 5 ++--- dissect/hypervisor/disk/c_qcow2.py | 5 ++--- dissect/hypervisor/disk/c_vdi.py | 5 ++--- dissect/hypervisor/disk/c_vhd.py | 9 ++++----- dissect/hypervisor/disk/c_vhdx.py | 5 ++--- dissect/hypervisor/disk/c_vmdk.py | 5 ++--- dissect/hypervisor/util/envelope.py | 5 ++--- pyproject.toml | 4 ++-- tox.ini | 8 +++++++- 11 files changed, 29 insertions(+), 32 deletions(-) diff --git a/dissect/hypervisor/backup/c_vma.py b/dissect/hypervisor/backup/c_vma.py index b0ae542..a071709 100644 --- a/dissect/hypervisor/backup/c_vma.py +++ b/dissect/hypervisor/backup/c_vma.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct vma_def = """ #define VMA_BLOCK_BITS 12 @@ -53,8 +53,7 @@ }; """ -c_vma = cstruct.cstruct(endian=">") -c_vma.load(vma_def) +c_vma = cstruct(endian=">").load(vma_def) VMA_MAGIC = b"VMA\x00" diff --git a/dissect/hypervisor/descriptor/c_hyperv.py b/dissect/hypervisor/descriptor/c_hyperv.py index daefa3e..02165cd 100644 --- a/dissect/hypervisor/descriptor/c_hyperv.py +++ b/dissect/hypervisor/descriptor/c_hyperv.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct hyperv_def = """ /* ======== File header ======== */ @@ -112,8 +112,7 @@ }; """ -c_hyperv = cstruct.cstruct() -c_hyperv.load(hyperv_def) +c_hyperv = cstruct().load(hyperv_def) ObjectEntryType = c_hyperv.ObjectEntryType KeyDataType = c_hyperv.KeyDataType diff --git a/dissect/hypervisor/disk/c_hdd.py b/dissect/hypervisor/disk/c_hdd.py index 94fab02..afe7044 100644 --- a/dissect/hypervisor/disk/c_hdd.py +++ b/dissect/hypervisor/disk/c_hdd.py @@ -3,7 +3,7 @@ # - https://github.com/qemu/qemu/blob/master/docs/interop/parallels.txt -from dissect import cstruct +from dissect.cstruct import cstruct hdd_def = """ /* Compressed disk v1 signature */ @@ -62,7 +62,6 @@ }; """ -c_hdd = cstruct.cstruct() -c_hdd.load(hdd_def) +c_hdd = cstruct().load(hdd_def) SECTOR_SIZE = c_hdd.SECTOR_SIZE diff --git a/dissect/hypervisor/disk/c_qcow2.py b/dissect/hypervisor/disk/c_qcow2.py index af33817..dda10b0 100644 --- a/dissect/hypervisor/disk/c_qcow2.py +++ b/dissect/hypervisor/disk/c_qcow2.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct qcow2_def = """ #define MIN_CLUSTER_BITS 9 @@ -136,8 +136,7 @@ }; """ -c_qcow2 = cstruct.cstruct(endian=">") -c_qcow2.load(qcow2_def) +c_qcow2 = cstruct(endian=">").load(qcow2_def) QCOW2_MAGIC = 0x514649FB QCOW2_MAGIC_BYTES = c_qcow2.uint32.dumps(QCOW2_MAGIC) diff --git a/dissect/hypervisor/disk/c_vdi.py b/dissect/hypervisor/disk/c_vdi.py index 07d2f03..2b3dace 100644 --- a/dissect/hypervisor/disk/c_vdi.py +++ b/dissect/hypervisor/disk/c_vdi.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct # https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Storage/VDICore.h # https://forums.virtualbox.org/viewtopic.php?t=8046 @@ -81,8 +81,7 @@ }; """ -c_vdi = cstruct.cstruct() -c_vdi.load(vdi_def) +c_vdi = cstruct().load(vdi_def) VDI_SIGNATURE = 0xBEDA107F diff --git a/dissect/hypervisor/disk/c_vhd.py b/dissect/hypervisor/disk/c_vhd.py index bf9f817..2a1b434 100644 --- a/dissect/hypervisor/disk/c_vhd.py +++ b/dissect/hypervisor/disk/c_vhd.py @@ -1,4 +1,4 @@ -from dissect import cstruct +from dissect.cstruct import cstruct vhd_def = """ struct footer { @@ -38,14 +38,13 @@ uint32 checksum; char parent_unique_id[16]; uint32 parent_timestamp; - uint32 reserved; + uint32 reserved1; char parent_unicode_name[512]; parent_locator parent_locators[8]; - char reserved[256]; + char reserved2[256]; }; """ -c_vhd = cstruct.cstruct(endian=">") -c_vhd.load(vhd_def) +c_vhd = cstruct(endian=">").load(vhd_def) SECTOR_SIZE = 512 diff --git a/dissect/hypervisor/disk/c_vhdx.py b/dissect/hypervisor/disk/c_vhdx.py index afbe960..e44b604 100644 --- a/dissect/hypervisor/disk/c_vhdx.py +++ b/dissect/hypervisor/disk/c_vhdx.py @@ -1,6 +1,6 @@ from uuid import UUID -from dissect import cstruct +from dissect.cstruct import cstruct vhdx_def = """ #define PAYLOAD_BLOCK_NOT_PRESENT 0 @@ -99,8 +99,7 @@ }; """ -c_vhdx = cstruct.cstruct() -c_vhdx.load(vhdx_def) +c_vhdx = cstruct().load(vhdx_def) ALIGNMENT = 64 * 1024 MB = 1024 * 1024 diff --git a/dissect/hypervisor/disk/c_vmdk.py b/dissect/hypervisor/disk/c_vmdk.py index 75623ef..7694bb7 100644 --- a/dissect/hypervisor/disk/c_vmdk.py +++ b/dissect/hypervisor/disk/c_vmdk.py @@ -1,6 +1,6 @@ import struct -from dissect import cstruct +from dissect.cstruct import cstruct vmdk_def = """ typedef struct { @@ -132,8 +132,7 @@ #define GRAIN_MARKER_PROGRESS 4 """ -c_vmdk = cstruct.cstruct() -c_vmdk.load(vmdk_def) +c_vmdk = cstruct().load(vmdk_def) SECTOR_SIZE = 512 diff --git a/dissect/hypervisor/util/envelope.py b/dissect/hypervisor/util/envelope.py index 4ddf216..206a84f 100644 --- a/dissect/hypervisor/util/envelope.py +++ b/dissect/hypervisor/util/envelope.py @@ -25,7 +25,7 @@ except ImportError: HAS_PYCRYPTODOME = False -from dissect import cstruct +from dissect.cstruct import cstruct from dissect.util.stream import RangeStream c_def = """ @@ -69,8 +69,7 @@ Bytes = 0xC }; """ -c_envelope = cstruct.cstruct() -c_envelope.load(c_def) +c_envelope = cstruct().load(c_def) FILE_HEADER_MAGIC = b"DataTransformEnvelope" FOOTER_AEAD_MAGIC = b"DataTransformAeadFooter" diff --git a/pyproject.toml b/pyproject.toml index 035ed61..2684e29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ ] dependencies = [ "defusedxml", - "dissect.cstruct>=3.0.dev,<4.0.dev", - "dissect.util>=3.0.dev,<4.0.dev", + "dissect.cstruct>3,<5", + "dissect.util>2,<4", ] dynamic = ["version"] diff --git a/tox.ini b/tox.ini index 1fa283f..5bea6cd 100644 --- a/tox.ini +++ b/tox.ini @@ -11,11 +11,17 @@ minversion = 4.4.3 requires = virtualenv>=20.16.6 [testenv] -extras = full deps = pytest pytest-cov coverage +# Unfortunately, tox does not allow separate installation flags for the project +# dependencies and the test dependencies. When running tox, we want to install the +# project dependencies with the --pre flag, so that we get the latest version of all +# dependencies. We do the installation step ourselves for this reason. +skip_install = true +commands_pre = + pip install --pre -e .[full] commands = pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests} coverage report From 84289ac4e3e5ade7c23501e22d7521e7ad27da5d Mon Sep 17 00:00:00 2001 From: pyrco <105293448+pyrco@users.noreply.github.com> Date: Thu, 30 May 2024 14:31:20 +0200 Subject: [PATCH 2/2] Use a dev extra instead of installing with --pre --- pyproject.toml | 9 +++++++-- tox.ini | 8 +------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2684e29..5a47764 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,8 @@ classifiers = [ ] dependencies = [ "defusedxml", - "dissect.cstruct>3,<5", - "dissect.util>2,<4", + "dissect.cstruct>=4.dev,<5", + "dissect.util>=3,<4", ] dynamic = ["version"] @@ -41,6 +41,11 @@ full = [ "pycryptodome", "rich", ] +dev = [ + "dissect.hypervisor[full]", + "dissect.cstruct>=4.0.dev,<5.0.dev", + "dissect.util>=3.0.dev,<4.0.dev", +] [project.scripts] vma-extract = "dissect.hypervisor.tools.vma:main" diff --git a/tox.ini b/tox.ini index 5bea6cd..7bd2890 100644 --- a/tox.ini +++ b/tox.ini @@ -11,17 +11,11 @@ minversion = 4.4.3 requires = virtualenv>=20.16.6 [testenv] +extras = dev deps = pytest pytest-cov coverage -# Unfortunately, tox does not allow separate installation flags for the project -# dependencies and the test dependencies. When running tox, we want to install the -# project dependencies with the --pre flag, so that we get the latest version of all -# dependencies. We do the installation step ourselves for this reason. -skip_install = true -commands_pre = - pip install --pre -e .[full] commands = pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests} coverage report