diff --git a/README.md b/README.md index 5f69996..80dd1f3 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi | LCE Savefile | | [`patterns/lcesave.hexpat`](patterns/lcesave.hexpat) | Minecraft Legacy Console Edition save file | | LZNT1 | | [`patterns/lznt1.hexpat`](patterns/lznt1.hexpat) | LZNT1 compressed data format | | Mach-O | `application/x-mach-binary` | [`patterns/macho.hexpat`](patterns/macho.hexpat) | Mach-O executable | +| MBR & GPT | [`patterns/partition_table.hexpat`](patterns/partition_table.hexpat) | Partition tables with primary focus on GPT | | MIDI | `audio/midi` | [`patterns/midi.hexpat`](patterns/midi.hexpat) | MIDI header, event fields provided | | MiniDump | `application/x-dmp` | [`patterns/minidump.hexpat`](patterns/minidump.hexpat) | Windows MiniDump files | | mp4 | `video/mp4` | [`patterns/mp4.hexpat`](patterns/mp4.hexpat) | MPEG-4 Part 14 digital multimedia container format | diff --git a/patterns/partition_table.hexpat b/patterns/partition_table.hexpat new file mode 100644 index 0000000..1596678 --- /dev/null +++ b/patterns/partition_table.hexpat @@ -0,0 +1,75 @@ +#pragma author RadxaYuntian +#pragma description Master Boot Record & GUID Partition Table +#pragma endian little + +import type.base; +import type.guid; + +#ifndef SECTOR_SIZE +#define SECTOR_SIZE 512 +#endif + +bitfield CHSAddress { + u8 head; + sector : 6; + cylinder: 10; +}; + +struct MBREntry { + u8 status; + CHSAddress first_chs; + u8 type; + CHSAddress last_chs; + u32 first_lba; + u32 sector_count; +}; + +struct MasterBootRecord { + padding[446]; + MBREntry entries[4]; + type::Hex boot_signature; + padding[SECTOR_SIZE - 512]; +}; + +bitfield GPTAttributes { + bool platform_required : 1; + padding : 59; + bool read_only : 1; + bool shadow_copy : 1; + bool hidden : 1; + bool no_drive_letter : 1; +}; + +struct GPTEntry { + type::GUID partition_type; + type::GUID partition_guid; + u64 first_lba; + u64 last_lba; + GPTAttributes attribute; + char16 partition_name[36]; + padding[parent.entry_size - 128]; +}; + +struct GUIDPartitionTable { + char signature[8]; // "EFI PART" + u16 version_minor; + u16 version_major; + u32 header_size; + type::Hex header_crc32; // from 0x0 to 0x5b + u32 reserved; // must be 0 + u64 current_lba; + u64 backup_lba; + u64 first_usable_lba; + u64 last_usable_lba; + type::GUID disk_guid; + u64 entry_lba; + u32 entry_count; + u32 entry_size; + type::Hex entry_crc32; + padding[SECTOR_SIZE - 92]; // end of first LBA + padding[SECTOR_SIZE * (entry_lba - current_lba - 1)]; // non-GPT data + GPTEntry entries[entry_count]; +}; + +MasterBootRecord mbr @ 0 * SECTOR_SIZE; +GUIDPartitionTable gpt @ 1 * SECTOR_SIZE; diff --git a/tests/patterns/test_data/partition_table.hexpat.bin b/tests/patterns/test_data/partition_table.hexpat.bin new file mode 100644 index 0000000..c75fa79 Binary files /dev/null and b/tests/patterns/test_data/partition_table.hexpat.bin differ