Skip to content

Commit

Permalink
Add support for Parallels PVS
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Apr 9, 2023
1 parent 8db70c6 commit da42607
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dissect/hypervisor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dissect.hypervisor.backup import vma, wim, xva
from dissect.hypervisor.descriptor import hyperv, ovf, vbox, vmx
from dissect.hypervisor.descriptor import hyperv, ovf, pvs, vbox, vmx
from dissect.hypervisor.disk import hdd, qcow2, vdi, vhd, vhdx, vmdk
from dissect.hypervisor.util import envelope, vmtar

Expand All @@ -8,6 +8,7 @@
"hdd",
"hyperv",
"ovf",
"pvs",
"qcow2",
"vbox",
"vdi",
Expand Down
25 changes: 25 additions & 0 deletions dissect/hypervisor/descriptor/pvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import IO, Iterator
from xml.etree.ElementTree import Element

try:
from defusedxml import ElementTree
except ImportError:
from xml.etree import ElementTree


class PVS:
"""Parallels VM settings file.
Args:
fh: The file-like object to a PVS file.
"""

def __init__(self, fh: IO):
self._xml: Element = ElementTree.fromstring(fh.read())

def disks(self) -> Iterator[str]:
"""Yield the disk file names."""
for hdd_elem in self._xml.iterfind(".//Hdd"):
system_name = hdd_elem.find("SystemName")
if system_name is not None:
yield system_name.text
14 changes: 10 additions & 4 deletions dissect/hypervisor/descriptor/vbox.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from xml.etree import ElementTree
from typing import IO, Iterator
from xml.etree.ElementTree import Element

try:
from defusedxml import ElementTree
except ImportError:
from xml.etree import ElementTree


class VBox:
VBOX_XML_NAMESPACE = "{http://www.virtualbox.org/}"

def __init__(self, fh):
self._xml = ElementTree.fromstring(fh.read())
def __init__(self, fh: IO):
self._xml: Element = ElementTree.fromstring(fh.read())

def disks(self):
def disks(self) -> Iterator[str]:
for hdd_elem in self._xml.findall(
f".//{self.VBOX_XML_NAMESPACE}HardDisk[@location][@format='VDI'][@type='Normal']"
):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_pvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from io import StringIO

from dissect.hypervisor.descriptor.pvs import PVS


def test_pvs():
xml = """
<?xml version="1.0" encoding="UTF-8"?>
<ParallelsVirtualMachine dyn_lists="VirtualAppliance 0" schemaVersion="1.0">
<Hardware dyn_lists="Fdd 0 CdRom 1 Hdd 9 Serial 0 Parallel 0 Printer 1 NetworkAdapter 4 Sound 1 USB 1 PciVideoAdapter 0 GenericDevice 0 GenericPciDevice 0 GenericScsiDevice 0 GenericNvmeDevice 0">
<Hdd dyn_lists="Partition 0" id="0">
<SystemName>Fedora-0.hdd</SystemName>
</Hdd>
</Hardware>
</ParallelsVirtualMachine>
""" # noqa: E501

with StringIO(xml.strip()) as fh:
pvs = PVS(fh)
assert next(pvs.disks()) == "Fedora-0.hdd"

0 comments on commit da42607

Please sign in to comment.