Skip to content

Commit 46576a8

Browse files
committed
Add documentation for loading QCOW2 snapshots
Add a section on how to use QCOW2 module to load images that are based on backing files. This is related to changes on: fox-it/dissect.hypervisor#64 Signed-off-by: Andreia Ocanoaia <andreia.ocanoaia@gmail.com>
1 parent 5b79cc9 commit 46576a8

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

  • docs/source/projects/dissect.hypervisor

docs/source/projects/dissect.hypervisor/index.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,49 @@ a VMDK for reading:
5757
Many of the parsers in this package behave in a very similar way, so check the API reference to see how to utilize the
5858
parser you need.
5959

60+
Open QCOW2 snapshots
61+
~~~~~~~~~~~~~~~~~~~~
62+
63+
For `qcow2` images there is support for backing-files and it can either be automatically loaded when opening a target.
64+
The backing-file will automatically be read from the `qcow2` headers and dissect will attempt to load it.
65+
66+
.. code-block:: python
67+
target = Target.open(target_path)
68+
print(target.users())
69+
70+
Or, for more control, the path to the backing file can be passed when initializing a `qcow2` disk:
71+
72+
.. code-block:: python
73+
def open_qcow2_with_backing_file(snapshot_path: Path, backing_path: Path):
74+
# Open base QCOW2 image
75+
backing_fh = backing_path.open("rb")
76+
base_qcow2 = qcow2.QCow2(backing_fh)
77+
base_stream = base_qcow2.open()
78+
79+
# Open snapshot QCOW2 image with base as backing file
80+
snapshot_fh = snapshot_path.open("rb")
81+
snapshot_qcow2 = qcow2.QCow2(
82+
snapshot_fh,
83+
backing_file=base_stream
84+
)
85+
snapshot_stream = snapshot_qcow2.open()
86+
87+
return snapshot_stream, snapshot_fh, backing_fh, base_stream
88+
89+
def analyze_image(snapshot_path: Path, backing_path: Path):
90+
# Open the QCOW2 snapshot along with its backing file and get file/stream handles
91+
snapshot_stream, snapshot_fh, backing_fh, base_stream = open_qcow2_with_backing_file(snapshot_path, backing_path)
92+
93+
# Create a new Dissect target to analyze the disk image
94+
target = Target()
95+
# Add the snapshot stream to the target’s disks
96+
target.disks.add(snapshot_stream)
97+
# Resolve all disks, volumes and filesystems and load an operating system on the current
98+
target.apply()
99+
100+
# Collect data from the snapshot
101+
print(target.users())
102+
60103
Tools
61104
-----
62105

0 commit comments

Comments
 (0)