The MSDN page for IMAGE_OPTIONAL_HEADER mentions file and section alignment.
Then the description of the SizeOfHeaders
member reads as follows:
The combined size of the following items, rounded to a multiple of the value specified in the FileAlignment member.
- e_lfanew member of IMAGE_DOS_HEADER
- 4 byte signature
- size of IMAGE_FILE_HEADER
- size of optional header
- size of all section headers
Calculating the combined size is simple enough, but how do I round the total to a multiple of the FileAlignment
member value (512 bytes, for example)?
EDIT
I've got the combined total of the various headers. I'm then using modulus with 512 to get the remainder. I guess this remainder needs to be padded somehow.