Skip to content

Commit

Permalink
Compatibility with cstruct v4 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Jun 4, 2024
1 parent 30857ff commit f01a1d2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 32 deletions.
5 changes: 2 additions & 3 deletions dissect/hypervisor/backup/c_vma.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dissect import cstruct
from dissect.cstruct import cstruct

vma_def = """
#define VMA_BLOCK_BITS 12
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions dissect/hypervisor/descriptor/c_hyperv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dissect import cstruct
from dissect.cstruct import cstruct

hyperv_def = """
/* ======== File header ======== */
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions dissect/hypervisor/disk/c_hdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions dissect/hypervisor/disk/c_qcow2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dissect import cstruct
from dissect.cstruct import cstruct

qcow2_def = """
#define MIN_CLUSTER_BITS 9
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions dissect/hypervisor/disk/c_vdi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -81,8 +81,7 @@
};
"""

c_vdi = cstruct.cstruct()
c_vdi.load(vdi_def)
c_vdi = cstruct().load(vdi_def)

VDI_SIGNATURE = 0xBEDA107F

Expand Down
9 changes: 4 additions & 5 deletions dissect/hypervisor/disk/c_vhd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dissect import cstruct
from dissect.cstruct import cstruct

vhd_def = """
struct footer {
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions dissect/hypervisor/disk/c_vhdx.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions dissect/hypervisor/disk/c_vmdk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import struct

from dissect import cstruct
from dissect.cstruct import cstruct

vmdk_def = """
typedef struct {
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions dissect/hypervisor/util/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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>=4.dev,<5",
"dissect.util>=3,<4",
]
dynamic = ["version"]

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ minversion = 4.4.3
requires = virtualenv>=20.16.6

[testenv]
extras = full
extras = dev
deps =
pytest
pytest-cov
Expand Down

0 comments on commit f01a1d2

Please sign in to comment.