Skip to content

Commit

Permalink
Fix detection of vdi harddisks inside a vbox file. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
twiggler authored Sep 8, 2024
1 parent 4f8dae8 commit 98a9a66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dissect/hypervisor/descriptor/vbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, fh: IO):
self._xml: Element = ElementTree.fromstring(fh.read())

def disks(self) -> Iterator[str]:
for hdd_elem in self._xml.findall(
f".//{self.VBOX_XML_NAMESPACE}HardDisk[@location][@format='VDI'][@type='Normal']"
):
yield hdd_elem.attrib["location"]
for hdd_elem in self._xml.findall(f".//{self.VBOX_XML_NAMESPACE}HardDisk[@location][@type='Normal']"):
# Allow format specifier to be case-insensitive (i.e. VDI, vdi)
if (format := hdd_elem.get("format")) and format.lower() == "vdi":
yield hdd_elem.attrib["location"]
21 changes: 20 additions & 1 deletion tests/test_vbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dissect.hypervisor.descriptor.vbox import VBox


def test_vbox():
def test_vbox() -> None:
xml = """
<?xml version="1.0"?>
<VirtualBox xmlns="http://www.virtualbox.org/">
Expand All @@ -20,3 +20,22 @@ def test_vbox():
with StringIO(xml.strip()) as fh:
vbox = VBox(fh)
assert next(vbox.disks()) == "os2warp4.vdi"


def test_vbox_lowercase_disk_format() -> None:
xml = """
<?xml version="1.0"?>
<VirtualBox xmlns="http://www.virtualbox.org/">
<Machine>
<MediaRegistry>
<HardDisks>
<HardDisk location="WinDev2407Eval-disk001.vdi" format="vdi" type="Normal" />
</HardDisks>
</MediaRegistry>
</Machine>
</VirtualBox>
"""

with StringIO(xml.strip()) as fh:
vbox = VBox(fh)
assert next(vbox.disks()) == "WinDev2407Eval-disk001.vdi"

0 comments on commit 98a9a66

Please sign in to comment.