diff --git a/patterns/vhdx.hexpat b/patterns/vhdx.hexpat index 9dbf6893..e2b4bb1b 100644 --- a/patterns/vhdx.hexpat +++ b/patterns/vhdx.hexpat @@ -8,6 +8,8 @@ #include #include +using BitfieldOrder = std::core::BitfieldOrder; + struct FileTypeIdentifier { char signature[8]; char16 creator[256]; @@ -60,7 +62,7 @@ bitfield BAT { State : 3; padding : 17; FileOffsetMB : 44; -} [[right_to_left]]; +} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 64)]]; bitfield MetadataEntryFlags { IsUser : 1; @@ -102,8 +104,8 @@ struct ParentLocatorEntry { u16 keyLength; u16 valueLength; - char key[keyLength] @ addressof(parent) + keyOffset; - char value[valueLength] @ addressof(parent) + valueOffset; + char16 key[keyLength / 2] @ addressof(parent) + keyOffset; + char16 value[valueLength / 2] @ addressof(parent) + valueOffset; }; struct MetadataParentLocator { @@ -113,31 +115,25 @@ struct MetadataParentLocator { ParentLocatorEntry entries[keyValueCount]; }; -fn metadata_relative(u128 offset) { - return addressof(parent.parent); -}; - 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 *data : u32 [[pointer_base("metadata_relative")]]; + MetadataFileParameters fileParameters @ addressof(parent) + dataOffset; else if (std::core::formatted_value(itemID) == "{2FA54224-CD1B-4876-B211-5DBED83BF4B8}") - MetadataVirtualDiskSize *data : u32 [[pointer_base("metadata_relative")]]; + MetadataVirtualDiskSize virtualDiskSize @ addressof(parent) + dataOffset; else if (std::core::formatted_value(itemID) == "{BECA12AB-B2E6-4523-93EF-C309E000C746}") - MetadataVirtualDiskID *data : u32 [[pointer_base("metadata_relative")]]; + MetadataVirtualDiskID virtualDiskId @ addressof(parent) + dataOffset; else if (std::core::formatted_value(itemID) == "{8141BF1D-A96F-4709-BA47-F233A8FAAB5F}") - MetadataLogicalSectorSize *data : u32 [[pointer_base("metadata_relative")]]; + MetadataLogicalSectorSize logicalSectorSize @ addressof(parent) + dataOffset; else if (std::core::formatted_value(itemID) == "{CDA348C7-445D-4471-9CC9-E9885251C556}") - MetadataPhysicalSectorSize *data : u32 [[pointer_base("metadata_relative")]]; + MetadataPhysicalSectorSize physicalSectorSize @ addressof(parent) + dataOffset; else if (std::core::formatted_value(itemID) == "{A8D35F2D-B30B-454D-ABF7-D3D84834AB0C}") - MetadataParentLocator *data : u32 [[pointer_base("metadata_relative")]]; - else - u32 dataOffset; - - type::Size32 length; - MetadataEntryFlags flags; - padding[4]; + MetadataParentLocator parentLocator @ addressof(parent) + dataOffset; }; struct MetadataRegion { @@ -150,16 +146,14 @@ struct MetadataRegion { struct RegionTableEntry { type::GUID guid; - - if (std::core::formatted_value(guid) == "{2DC27766-F623-4200-9D64-115E9BFD4A08}") - BAT *bat : u64; - else if (std::core::formatted_value(guid) == "{8B7CA206-4790-4B9A-B8FE-575F050F886E}") - MetadataRegion *metadata : u64; - else - u64 fileOffset; - + 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 {