Learning some nasm, and fileformats for my assembly project. I am currently very confused about SizeOfHeaders.
Taking a look at the documentation https://learn.microsoft.com/en-us/previous-versions/ms809762(v=msdn.10)?redirectedfrom=MSDN
The size of the PE header and the section (object) table. The raw data for the sections starts immediately after all the header components.
Lets take a look at another official documentation https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_optional_header32 .
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
Other sources online say
The combined size of an MS‑DOS stub, PE header, and section headers rounded up to a multiple of FileAlignment.
As you can see each source is giving a different explanation of what is comprised of SizeOfHeaders.
What I've tried:
In NASM, the SizeOfHeaders could be computed as such:
dd sections_start - dos_stub_start + (FileAlignment - 1)) // FileAlignment
That would be the example of the implementation of simplest source, and one that I have used, however the second official source that I listed, specifically says the e_lfanew member of the dos header, not the whole dos stub or not any of the dos header or stub at all for the first source.
So that example may very well be incorrect. Looking online, there doesn't seem to be any conclusive information previously recorded on the internet about this issue.