#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Constructed GPT checksum examples. No device or image input; stdout only.""" import hashlib import json import struct import zlib BLOCK = 512 BLOCKS = 128 HEADER_SIZE = 92 ENTRY_COUNT = 128 ENTRY_SIZE = 128 ARRAY_BYTES = ENTRY_COUNT * ENTRY_SIZE PRIMARY = 1 BACKUP = BLOCKS - 1 PRIMARY_ARRAY = 2 BACKUP_ARRAY = BACKUP - ARRAY_BYTES // BLOCK FIRST_USABLE = PRIMARY_ARRAY + ARRAY_BYTES // BLOCK LAST_USABLE = BACKUP_ARRAY - 1 PAYLOAD_LBA = FIRST_USABLE # Fixed fixture identifiers, not real-device identities. DISK_GUID = bytes.fromhex("00112233445566778899aabbccddeeff") TYPE_GUID = bytes.fromhex("28732ac11ff8d211ba4b00a0c93ec93b") PART_GUID = bytes.fromhex("102132435465768798a9bacbdcedfe0f") def header(my_lba, other_lba, array_lba, entries): data = bytearray(BLOCK) struct.pack_into("<8sIIIIQQQQ16sQIII", data, 0, b"EFI PART", 0x10000, HEADER_SIZE, 0, 0, my_lba, other_lba, FIRST_USABLE, LAST_USABLE, DISK_GUID, array_lba, ENTRY_COUNT, ENTRY_SIZE, zlib.crc32(entries)) struct.pack_into("