#!/usr/bin/env python2.7 import sys import struct import os import binascii e_lfanew_OFFSET = 0x40 SizeOfHeaders_OFFSET = 0x04 + 0x14 + 0x3C # sizeof(PE_sig) + sizeof(COFF_hdr) + Optional_hdr->SizeOfHeaders SizeOfHeaders_DEFAULT = 0x400 # default value for GCC def main(argv): found = 0 absfound = 0 buf = bytearray() with open(argv[0], "rb") as fin: for line in fin: buf += line if buf[0:2] != '\x4d\x5a': return False e_lfanew = struct.unpack(" SizeOfHeaders_DEFAULT or SizeOfHeaders <= 0: return False newstart = (e_lfanew - dosStubSiz) if newstart <= 0: return False newstart = struct.pack("