pe_set_laa.py 592 B

123456789101112131415
  1. """Sets IMAGE_FILE_LARGE_ADDRESS_AWARE (0x20) in a PE file's COFF header (round 176a: LYNX-bridge32.exe; zig's linker has
  2. no flag for it). A 32-bit process on 64-bit Windows then gets 4 GB of address space instead of 2 GB.
  3. usage: pe_set_laa.py <exe>"""
  4. import struct, sys
  5. with open(sys.argv[1], "r+b") as f:
  6. f.seek(0x3C)
  7. pe = struct.unpack("<I", f.read(4))[0]
  8. f.seek(pe)
  9. if f.read(4) != b"PE\0\0":
  10. sys.exit("pe_set_laa: not a PE file")
  11. f.seek(pe + 22)
  12. flags = struct.unpack("<H", f.read(2))[0]
  13. f.seek(pe + 22)
  14. f.write(struct.pack("<H", flags | 0x20))