From 1963a0a6d7398a426d0701f90a5bc796e32899ae Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 02:55:10 +0200 Subject: feat(rsboot): initial commit — UEFI bootloader extracted from RNG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fix_pe_simple.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 fix_pe_simple.py (limited to 'fix_pe_simple.py') diff --git a/fix_pe_simple.py b/fix_pe_simple.py new file mode 100644 index 0000000..77b1366 --- /dev/null +++ b/fix_pe_simple.py @@ -0,0 +1,64 @@ +#!/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) -- cgit v1.2.3