|
2 | 2 |
|
3 | 3 | from dissect.cstruct import cstruct |
4 | 4 |
|
5 | | -# https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Storage/VDICore.h |
6 | | -# https://forums.virtualbox.org/viewtopic.php?t=8046 |
7 | | -# 0000 3C 3C 3C 20 53 75 6E 20 78 56 4D 20 56 69 72 74 <<< Sun xVM Virt |
8 | | -# 0010 75 61 6C 42 6F 78 20 44 69 73 6B 20 49 6D 61 67 ualBox Disk Imag |
9 | | -# 0020 65 20 3E 3E 3E 0A 00 00 00 00 00 00 00 00 00 00 e >>> |
10 | | -# 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
11 | | -# |
12 | | -# 0040 7F 10 DA BE Image Signature |
13 | | -# 01 00 01 00 Version 1.1 |
14 | | -# 90 01 00 00 Size of Header(0x190) |
15 | | -# 01 00 00 00 Image Type (Dynamic VDI) |
16 | | -# 0050 00 00 00 00 Image Flags |
17 | | -# 00 00 00 00 00 00 00 00 00 00 00 00 Image Description |
18 | | -# 0060-001F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
19 | | -# 0150 00 00 00 00 |
20 | | -# 00 02 00 00 offsetBlocks |
21 | | -# 00 20 00 00 offsetData |
22 | | -# 00 00 00 00 #Cylinders (0) |
23 | | -# 0160 00 00 00 00 #Heads (0) |
24 | | -# 00 00 00 00 #Sectors (0) |
25 | | -# 00 02 00 00 SectorSize (512) |
26 | | -# 00 00 00 00 -- unused -- |
27 | | -# 0170 00 00 00 78 00 00 00 00 DiskSize (Bytes) |
28 | | -# 00 00 10 00 BlockSize |
29 | | -# 00 00 00 00 Block Extra Data (0) |
30 | | -# 0180 80 07 00 00 #BlocksInHDD |
31 | | -# 0B 02 00 00 #BlocksAllocated |
32 | | -# 5A 08 62 27 A8 B6 69 44 UUID of this VDI |
33 | | -# 0190 A1 57 E2 B2 43 A5 8F CB |
34 | | -# 0C 5C B1 E3 C5 73 ED 40 UUID of last SNAP |
35 | | -# 01A0 AE F7 06 D6 20 69 0C 96 |
36 | | -# 00 00 00 00 00 00 00 00 UUID link |
37 | | -# 01B0 00 00 00 00 00 00 00 00 |
38 | | -# 00 00 00 00 00 00 00 00 UUID Parent |
39 | | -# 01C0 00 00 00 00 00 00 00 00 |
40 | | -# CF 03 00 00 00 00 00 00 -- garbage / unused -- |
41 | | -# 01D0 3F 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 -- garbage / unused -- |
42 | | -# 01E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -- unused -- |
43 | | -# 01F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -- unused -- |
44 | | - |
| 5 | +# https://github.com/VirtualBox/virtualbox/blob/main/src/VBox/Storage/VDICore.h |
45 | 6 | vdi_def = """ |
46 | | -enum ImageType : uint32 { |
47 | | - Dynamic = 0x01, |
48 | | - Fixed = 0x02, |
49 | | - Undo = 0x03, |
50 | | - Differencing = 0x04 |
| 7 | +enum VDI_IMAGE_TYPE { |
| 8 | + /** Normal dynamically growing base image file. */ |
| 9 | + NORMAL = 1, |
| 10 | + /** Preallocated base image file of a fixed size. */ |
| 11 | + FIXED, |
| 12 | + /** Dynamically growing image file for undo/commit changes support. */ |
| 13 | + UNDO, |
| 14 | + /** Dynamically growing image file for differencing support. */ |
| 15 | + DIFF, |
51 | 16 | }; |
52 | 17 |
|
53 | | -flag ImageFlags : uint32 { |
54 | | - None = 0x00000000, |
55 | | - Split2G = 0x00000001, |
56 | | - ZeroExpand = 0x00000002 |
| 18 | +flag VDI_IMAGE_FLAGS { |
| 19 | + /** Fill new blocks with zeroes while expanding image file. Only valid |
| 20 | + * for newly created images, never set for opened existing images. */ |
| 21 | + ZERO_EXPAND = 0x0100, |
57 | 22 | }; |
58 | 23 |
|
59 | | -struct HeaderDescriptor { |
60 | | - char FileInfo[64]; |
61 | | - uint32 Signature; |
62 | | - uint32 Version; |
63 | | - uint32 HeaderSize; |
64 | | - ImageType ImageType; |
65 | | - ImageFlags ImageFlags; |
66 | | - char ImageDescription[256]; |
67 | | - uint32 BlocksOffset; |
68 | | - uint32 DataOffset; |
69 | | - uint32 NumCylinders; |
70 | | - uint32 NumHeads; |
71 | | - uint32 NumSectors; |
72 | | - uint32 SectorSize; |
73 | | - uint32 Unused1; |
74 | | - uint64 DiskSize; |
75 | | - uint32 BlockSize; |
76 | | - uint32 BlockExtraData; |
77 | | - uint32 BlocksInHDD; |
78 | | - uint32 BlocksAllocated; |
79 | | - char UUIDVDI[16]; |
80 | | - char UUIDSNAP[16]; |
81 | | - char UUIDLink[16]; |
82 | | - char UUIDParent[16]; |
83 | | -}; |
| 24 | +typedef struct VDIDISKGEOMETRY { |
| 25 | + /** Cylinders. */ |
| 26 | + uint32_t Cylinders; |
| 27 | + /** Heads. */ |
| 28 | + uint32_t Heads; |
| 29 | + /** Sectors per track. */ |
| 30 | + uint32_t Sectors; |
| 31 | + /** Sector size. (bytes per sector) */ |
| 32 | + uint32_t Sector; |
| 33 | +} VDIDISKGEOMETRY, *PVDIDISKGEOMETRY; |
| 34 | +
|
| 35 | +typedef struct VDIPREHEADER { |
| 36 | + /** Just text info about image type, for eyes only. */ |
| 37 | + char szFileInfo[64]; |
| 38 | + /** The image signature (VDI_IMAGE_SIGNATURE). */ |
| 39 | + uint32_t u32Signature; |
| 40 | + /** The image version (VDI_IMAGE_VERSION). */ |
| 41 | + uint32_t u32Version; |
| 42 | +} VDIPREHEADER, *PVDIPREHEADER; |
| 43 | +
|
| 44 | +/** |
| 45 | + * Size of Comment field of HDD image header. |
| 46 | + */ |
| 47 | +#define VDI_IMAGE_COMMENT_SIZE 256 |
| 48 | +
|
| 49 | +/* NOTE: All the header versions are additive, so just use the latest one. */ |
| 50 | +typedef struct VDIHEADER1PLUS { |
| 51 | + /** Size of this structure in bytes. */ |
| 52 | + uint32_t cbHeader; |
| 53 | + /** The image type (VDI_IMAGE_TYPE_*). */ |
| 54 | + VDI_IMAGE_TYPE u32Type; |
| 55 | + /** Image flags (VDI_IMAGE_FLAGS_*). */ |
| 56 | + VDI_IMAGE_FLAGS fFlags; |
| 57 | + /** Image comment. (UTF-8) */ |
| 58 | + char szComment[VDI_IMAGE_COMMENT_SIZE]; |
| 59 | + /** Offset of blocks array from the beginning of image file. |
| 60 | + * Should be sector-aligned for HDD access optimization. */ |
| 61 | + uint32_t offBlocks; |
| 62 | + /** Offset of image data from the beginning of image file. |
| 63 | + * Should be sector-aligned for HDD access optimization. */ |
| 64 | + uint32_t offData; |
| 65 | + /** Legacy image geometry (previous code stored PCHS there). */ |
| 66 | + VDIDISKGEOMETRY LegacyGeometry; |
| 67 | + /** Was BIOS HDD translation mode, now unused. */ |
| 68 | + uint32_t u32Dummy; |
| 69 | + /** Size of disk (in bytes). */ |
| 70 | + uint64_t cbDisk; |
| 71 | + /** Block size. (For instance VDI_IMAGE_BLOCK_SIZE.) Should be a power of 2! */ |
| 72 | + uint32_t cbBlock; |
| 73 | + /** Size of additional service information of every data block. |
| 74 | + * Prepended before block data. May be 0. |
| 75 | + * Should be a power of 2 and sector-aligned for optimization reasons. */ |
| 76 | + uint32_t cbBlockExtra; |
| 77 | + /** Number of blocks. */ |
| 78 | + uint32_t cBlocks; |
| 79 | + /** Number of allocated blocks. */ |
| 80 | + uint32_t cBlocksAllocated; |
| 81 | + /** UUID of image. */ |
| 82 | + char uuidCreate[16]; |
| 83 | + /** UUID of image's last modification. */ |
| 84 | + char uuidModify[16]; |
| 85 | + /** Only for secondary images - UUID of previous image. */ |
| 86 | + char uuidLinkage[16]; |
| 87 | + /** Only for secondary images - UUID of previous image's last modification. */ |
| 88 | + char uuidParentModify[16]; |
| 89 | + /** LCHS image geometry (new field in VDI1.2 version. */ |
| 90 | + VDIDISKGEOMETRY Geometry; |
| 91 | +} VDIHEADER1PLUS, *PVDIHEADER1PLUS; |
84 | 92 | """ |
85 | 93 |
|
86 | 94 | c_vdi = cstruct().load(vdi_def) |
87 | 95 |
|
88 | | -VDI_SIGNATURE = 0xBEDA107F |
89 | | - |
90 | | -UNALLOCATED = -1 |
91 | | -SPARSE = -2 |
| 96 | +VDI_IMAGE_SIGNATURE = 0xBEDA107F |
| 97 | +VDI_IMAGE_BLOCK_FREE = ~0 |
| 98 | +VDI_IMAGE_BLOCK_ZERO = ~1 |
0 commit comments