I need byte size, IMAGE_OPTIONAL_HEADER.SizeOfImage appears to be rounded up to (unsure) boundary and is greater than real file size.
IMAGE_OPTIONAL_HEADER.SizeOfImage
is the size of the loaded executable/dll in virtual memory.
It is not the same as the size on disk.
You can calculate it with VirtualAddress + VirtualSize
of the last section.
IMAGE_OPTIONAL_HEADER.SizeOfImage
is that value rounded up to the value of IMAGE_OPTIONAL_HEADER.SectionAlignment
(usually the same as the page size).