0

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.

Hugh McMaster
  • 319
  • 3
  • 10
  • 1
    This is not related to MSDN, the PE file header or windows at all. What you are asking is a simple logic question: how to round a number up to an multiple of x. – Mark Jansen Sep 15 '15 at 11:38
  • @CodeCaster I'm using C. I'll add that tag. – Hugh McMaster Sep 15 '15 at 11:39
  • @MarkJansen That's one way of looking at it. I stumbled on this problem when I was learning about the PE header on Windows, so it's contextual information (for me, at least). – Hugh McMaster Sep 15 '15 at 11:41
  • 2
    @CodeCaster Thanks, that link helps a lot. I was searching with terms such as `section alignment` and didn't find anything. – Hugh McMaster Sep 15 '15 at 11:55

0 Answers0