Skip to content

Commit

Permalink
patterns/vhdx: Various improvements (#154)
Browse files Browse the repository at this point in the history
* Replaced right_to_left to bitfield_order

* Fixed type of ParentLocatorEntry (char -> char16)

* Fixed item address of MetadataTableEntry

* Improved RegionTableEntry# Please enter the commit message for your changes. Lines starting
  • Loading branch information
nitoyon authored Sep 10, 2023
1 parent b6e0557 commit 81f4978
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions patterns/vhdx.hexpat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <type/guid.pat>
#include <type/size.pat>

using BitfieldOrder = std::core::BitfieldOrder;

struct FileTypeIdentifier {
char signature[8];
char16 creator[256];
Expand Down Expand Up @@ -60,7 +62,7 @@ bitfield BAT {
State : 3;
padding : 17;
FileOffsetMB : 44;
} [[right_to_left]];
} [[bitfield_order(BitfieldOrder::LeastToMostSignificant, 64)]];

bitfield MetadataEntryFlags {
IsUser : 1;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 81f4978

Please sign in to comment.