A Ruby script to modify a PE binary, performing several actions:
-
Add the
IMAGE_FILE_LARGE_ADDRESS_AWAREflag to the binary. This flag allows a 32 bit PE binary to address more than 2Gb of address space at run time. -
Add the
IMAGE_DLLCHARACTERISTICS_NX_COMPATflag to the binary. This flag indicates the binary is Data Execution Prevention (DEP) compatible. -
Add the
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASEflag to the binary. This flag indicates the binary can opt into Address Space Layout Randomization (ASLR). -
Remove any symbol information pre-pended to be binary.
-
Calculate the expected
SizeOfHeadersvalue in the PE optional header and update the value if the existing value is wrong. Some linkers produce an incorrectSizeOfHeadersvalue.
This script can be run as part of a build to fixup PE binaries that would benefit from any of the above modifications.
ruby.exe fixup_pe.rb [/flag_laa] [/flag_dep] [/flag_aslr] [/strip_symbols] [/fix_sizeof] c:\\path\\to\\file.exe
Released under the 3-Clause BSD License.