Skip to content

Commit 98a9a66

Browse files
authored
Fix detection of vdi harddisks inside a vbox file. (#42)
1 parent 4f8dae8 commit 98a9a66

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

dissect/hypervisor/descriptor/vbox.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, fh: IO):
1111
self._xml: Element = ElementTree.fromstring(fh.read())
1212

1313
def disks(self) -> Iterator[str]:
14-
for hdd_elem in self._xml.findall(
15-
f".//{self.VBOX_XML_NAMESPACE}HardDisk[@location][@format='VDI'][@type='Normal']"
16-
):
17-
yield hdd_elem.attrib["location"]
14+
for hdd_elem in self._xml.findall(f".//{self.VBOX_XML_NAMESPACE}HardDisk[@location][@type='Normal']"):
15+
# Allow format specifier to be case-insensitive (i.e. VDI, vdi)
16+
if (format := hdd_elem.get("format")) and format.lower() == "vdi":
17+
yield hdd_elem.attrib["location"]

tests/test_vbox.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dissect.hypervisor.descriptor.vbox import VBox
44

55

6-
def test_vbox():
6+
def test_vbox() -> None:
77
xml = """
88
<?xml version="1.0"?>
99
<VirtualBox xmlns="http://www.virtualbox.org/">
@@ -20,3 +20,22 @@ def test_vbox():
2020
with StringIO(xml.strip()) as fh:
2121
vbox = VBox(fh)
2222
assert next(vbox.disks()) == "os2warp4.vdi"
23+
24+
25+
def test_vbox_lowercase_disk_format() -> None:
26+
xml = """
27+
<?xml version="1.0"?>
28+
<VirtualBox xmlns="http://www.virtualbox.org/">
29+
<Machine>
30+
<MediaRegistry>
31+
<HardDisks>
32+
<HardDisk location="WinDev2407Eval-disk001.vdi" format="vdi" type="Normal" />
33+
</HardDisks>
34+
</MediaRegistry>
35+
</Machine>
36+
</VirtualBox>
37+
"""
38+
39+
with StringIO(xml.strip()) as fh:
40+
vbox = VBox(fh)
41+
assert next(vbox.disks()) == "WinDev2407Eval-disk001.vdi"

0 commit comments

Comments
 (0)