@@ -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
5858parser 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