Skip to content

Commit f787f5a

Browse files
authored
Update vbox loader and virtualbox child for the VirtualBox descriptor update (#1523)
Updates the loader and child plugin with the changes in to https://github.com/fox-it/dissect.hypervisor/pull/71/files
1 parent 4eeb069 commit f787f5a

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

dissect/target/loaders/vbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ def detect(path: Path) -> bool:
2626
return path.suffix.lower() == ".vbox"
2727

2828
def map(self, target: Target) -> None:
29-
for disk in self.vbox.disks():
30-
target.disks.add(container.open(self.base_path.joinpath(disk)))
29+
for disk in self.vbox.hardware.disks:
30+
target.disks.add(container.open(self.base_path.joinpath(disk.location)))

dissect/target/plugins/child/virtualbox.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from defusedxml import ElementTree
6-
from dissect.hypervisor.descriptor.vbox import VBox
6+
from dissect.hypervisor.descriptor.vbox import NS
77

88
from dissect.target.exceptions import UnsupportedPluginError
99
from dissect.target.helpers.record import ChildTargetRecord
@@ -45,7 +45,6 @@ def __init__(self, target: Target):
4545
def find_vms(self) -> Iterator[Path]:
4646
"""Yield Oracle VirtualBox ``.vbox`` file(s) found on the target."""
4747
seen = set()
48-
4948
for user_details in self.target.user_details.all_with_home():
5049
# Yield `.vbox` from default locations and add to seen.
5150
for default_path in self.DEFAULT_PATHS:
@@ -70,7 +69,7 @@ def find_vms(self) -> Iterator[Path]:
7069
continue
7170

7271
# Parse MachineEntries
73-
for machine in config.findall(f".//{VBox.VBOX_XML_NAMESPACE}MachineEntry"):
72+
for machine in config.findall(f".//{NS}MachineEntry"):
7473
if (
7574
(src := machine.get("src"))
7675
and (src_path := self.target.fs.path(src)).exists()
@@ -80,7 +79,7 @@ def find_vms(self) -> Iterator[Path]:
8079
yield src_path
8180

8281
# Glob for SystemProperties defaultMachineFolder
83-
for system_properties in config.findall(f".//{VBox.VBOX_XML_NAMESPACE}SystemProperties"):
82+
for system_properties in config.findall(f".//{NS}SystemProperties"):
8483
if (folder_str := system_properties.get("defaultMachineFolder")) and (
8584
folder_dir := self.target.fs.path(folder_str)
8685
).is_dir():
@@ -97,7 +96,7 @@ def list_children(self) -> Iterator[ChildTargetRecord]:
9796
for vbox in self.vboxes:
9897
try:
9998
config = ElementTree.fromstring(vbox.read_bytes())
100-
name = config.find(f".//{VBox.VBOX_XML_NAMESPACE}Machine").attrib["name"]
99+
name = config.find(f".//{NS}Machine").attrib["name"]
101100
except Exception as e:
102101
self.target.log.error("Failed to parse name from VirtualBox XML: %s", vbox) # noqa: TRY400
103102
self.target.log.debug("", exc_info=e)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"dissect.database>=1.1.dev3,<2", # TODO: update on release!
3131
"dissect.eventlog>=3,<4",
3232
"dissect.evidence>=3.13.dev2,<4", # TODO: update on release!
33-
"dissect.hypervisor>=3.20,<4",
33+
"dissect.hypervisor>=3.21.dev3,<4", # TODO: update on release!
3434
"dissect.ntfs>=3.16.dev,<4",
3535
"dissect.regf>=3.13,<4",
3636
"dissect.util>=3,<4",
@@ -93,7 +93,7 @@ dev = [
9393
"dissect.fat[dev]>=3.0.dev,<4.0.dev",
9494
"dissect.ffs[dev]>=3.0.dev,<4.0.dev",
9595
"dissect.fve[dev]>=4.5.dev,<5.0.dev",
96-
"dissect.hypervisor[dev]>=3.20.dev,<4.0.dev",
96+
"dissect.hypervisor[dev]>=3.21.dev3,<4.0.dev", # TODO: update on release!
9797
"dissect.jffs[dev]>=1.5.dev,<2.0.dev",
9898
"dissect.ntfs[dev]>=3.16.dev,<4.0.dev",
9999
"dissect.qnxfs[dev]>=1.1.dev,<2.0.dev",

tests/loaders/test_vbox.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING
4-
from unittest.mock import patch
4+
from unittest.mock import Mock, patch
55

66
import pytest
77

@@ -32,7 +32,7 @@ def test_target_open(opener: Callable[[str | Path], Target], tmp_path: Path) ->
3232
patch("dissect.target.target.Target.apply"),
3333
):
3434
mock_vbox.return_value = mock_vbox
35-
mock_vbox.disks.return_value = ["mock.vdi"]
35+
mock_vbox.hardware.disks = [Mock(location="mock.vdi")]
3636

3737
target = opener(path)
3838
assert isinstance(target._loader, VBoxLoader)
@@ -48,7 +48,7 @@ def test_loader(tmp_path: Path) -> None:
4848
patch("dissect.target.container.open") as mock_container_open,
4949
):
5050
mock_vbox.return_value = mock_vbox
51-
mock_vbox.disks.return_value = ["mock.vdi"]
51+
mock_vbox.hardware.disks = [Mock(location="mock.vdi")]
5252

5353
loader = loader_open(path)
5454
assert isinstance(loader, VBoxLoader)

0 commit comments

Comments
 (0)