#!/usr/bin/env python3 """fix_pe_simple.py — PE header fixup for PIE-built UEFI bootloader The -fPIE-built bootloader uses only PC-relative addressing, so it needs zero absolute fixups. This script just sets proper PE flags: - ImageBase (env IMAGE_BASE, default 0x10000000) - Characteristics = 0x022e (RELOCS_STRIPPED) - DllChar = 0x0160 (NX | DYNAMIC_BASE | HIGH_ENTROPY_VA) - Clears .reloc DD (no relocations needed) - Clears checksum (not signed) """ import struct, os, sys def fix_pe(path): try: with open(path, 'rb') as f: d = bytearray(f.read()) except IOError as e: print(f" ERROR: cannot read {path}: {e}") return False po = struct.unpack('") sys.exit(1) if not fix_pe(sys.argv[1]): sys.exit(1)