#!/usr/bin/env python3 """ hunt_pe.py -- static protocol hunt for the Borland PE game binaries (RPL4OPT/BTL4OPT under 32RTM), the PE counterpart of hunt_actions.py (LE). Find an error-string's data VA, locate the code xref (32-bit immediate), and disassemble the surrounding function to read off the protocol constants (expected reply actions, request sizes) that the DOS-side source never had. python hunt_pe.py [--back N] [--fwd N] """ import struct import sys import capstone def pe_sections(data): e_lfanew = struct.unpack_from(' 0 and data[s0 - 1] != 0: s0 -= 1 va = file_to_va(secs, base, s0) print(f"\nstring @ file {s0:#x} va {va:#x}: " f"{data[s0:s0+70].rstrip(bytes(1))!r}") if va is None: continue pat = struct.pack('