-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
vhdx.hexpat
190 lines (157 loc) · 4.26 KB
/
vhdx.hexpat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma author WerWolv
#pragma description Microsoft Hyper-V Virtual Hard Disk
import std.io;
import std.ptr;
import std.core;
import type.guid;
import type.size;
using BitfieldOrder = std::core::BitfieldOrder;
struct FileTypeIdentifier {
char signature[8];
char16 creator[256];
padding[0x1'0000 - sizeof(signature) - sizeof(creator)];
};
struct DataSector {
u32 sequenceHigh;
u8 data[4084];
u32 sequenceLow;
} [[static]];
struct ZeroDescriptor {
padding[4];
u64 zeroLength;
DataSector *dataSector : u64;
u64 sequenceNumber;
} [[static]];
struct DataDescriptor {
u32 trailingBytes;
u64 leadingBytes;
DataSector *dataSector : u64;
u64 sequenceNumber;
} [[static]];
struct LogDescriptor {
char signature[4];
if (signature == "zero")
ZeroDescriptor descriptor [[inline]];
else if (signature == "desc")
DataDescriptor descriptor [[inline]];
};
struct LogEntry {
char signature[4];
u32 checksum;
type::Size32 entryLength;
u32 tail;
u64 sequenceNumber;
u32 descriptorCount;
padding[4];
type::GUID logGuid;
u64 flushedFileOffset;
u64 lastFileOffset;
} [[static]];
bitfield BAT {
State : 3;
padding : 17;
FileOffsetMB : 44;
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 64)]];
bitfield MetadataEntryFlags {
IsUser : 1;
IsVirtualDisk : 1;
IsRequired : 1;
padding : 29;
};
bitfield FileParameterFlags {
LeaveBlockAllocated : 1;
HasParent : 1;
padding : 30;
};
struct MetadataFileParameters {
type::Size32 blockSize;
FileParameterFlags flags;
};
struct MetadataVirtualDiskSize {
type::Size64 virtualDiskSize;
};
struct MetadataVirtualDiskID {
type::GUID virtualDiskID;
};
struct MetadataLogicalSectorSize {
type::Size32 logicalSectorSize;
};
struct MetadataPhysicalSectorSize {
type::Size32 physicalSectorSize;
};
struct ParentLocatorEntry {
u32 keyOffset;
u32 valueOffset;
u16 keyLength;
u16 valueLength;
char16 key[keyLength / 2] @ addressof(parent) + keyOffset;
char16 value[valueLength / 2] @ addressof(parent) + valueOffset;
};
struct MetadataParentLocator {
type::GUID locatorType;
padding[2];
u16 keyValueCount;
ParentLocatorEntry entries[keyValueCount];
};
struct MetadataTableEntry {
type::GUID itemID;
u32 dataOffset;
type::Size32 length;
MetadataEntryFlags flags;
padding[4];
if (std::core::formatted_value(itemID) == "{CAA16737-FA36-4D43-B3B6-33F0AA44E76B}")
MetadataFileParameters fileParameters @ addressof(parent) + dataOffset;
else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}")
MetadataVirtualDiskSize virtualDiskSize @ addressof(parent) + dataOffset;
else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}")
MetadataVirtualDiskID virtualDiskId @ addressof(parent) + dataOffset;
else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}")
MetadataLogicalSectorSize logicalSectorSize @ addressof(parent) + dataOffset;
else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}")
MetadataPhysicalSectorSize physicalSectorSize @ addressof(parent) + dataOffset;
else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}")
MetadataParentLocator parentLocator @ addressof(parent) + dataOffset;
};
struct MetadataRegion {
char signature[8];
padding[2];
u16 entryCount;
padding[20];
MetadataTableEntry entries[entryCount];
};
struct RegionTableEntry {
type::GUID guid;
u64 fileOffset;
type::Size32 length;
u32 required;
if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}")
BAT bat @ fileOffset;
else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}")
MetadataRegion metadata @ fileOffset;
};
struct RegionTable {
char signature[4];
u32 checksum;
u32 entryCount;
padding[4];
RegionTableEntry entries[entryCount];
};
struct Header {
char signature[4];
u32 checksum;
u64 sequenceNumber;
type::GUID fileWriteGuid, dataWriteGuid, logGuid;
u16 logVersion;
u16 version;
type::Size32 logLength;
LogEntry *log : u64;
padding[4016];
};
struct VHDX {
FileTypeIdentifier fileTypeIdentifier;
Header header @ 0x1'0000;
Header headerBackup @ 0x2'0000;
RegionTable regionTable @ 0x3'0000;
RegionTable regionTableBackup @ 0x4'0000;
};
VHDX vhdx @ 0x00;