Reputation: 830
I'm currently writing a library that reads and writes from PE files. As far as I understand from the specification, the Optional Header is not generally used in object files. However, it contains the field that specifies between PE32 and PE32+ variants. Does PE allow for PE32+ object files?
The specification specifically says:
An object file may have an optional header, but generally this header has no function in an object file except to increase size.
This seems slightly ambiguous to me. I'm inclined to read this as "the optional header is ignored in object files and only bloats the file." However, it could be read as "the optional header can be used in object files to increase the size from 32 to 64 bits." Which is meant by this?
Edit: According to the specification, a value of 0x10b indicates 32-bit, a value of 0x20b indicates 64-bit, and a value of 0x107 indicates a ROM image. Are ROM images always 32-bit?
Upvotes: 2
Views: 3683
Reputation: 20130
the Optional Header is not generally used in object files
that's correct
However, it contains the field that specifies between PE32 and PE32+ variants.
correct as well
Does PE allow for PE32+ object files?
If you mean could you compile PE32 .obj and link it to PE32+ app, it is wrong thing to do anyway due to different size of pointer to begin with.
I'm inclined to read this as "the optional header is ignored in object files and only bloats the file."
that's correct, I believe.
Optional header is a must for an image (a.k.a. exe or dll).
You could gather all this information by yourself by doing dumpbin /header
on your .obj or .exe file. Dumpbin is distributed with every VC++ intallation. For example, small text project
dumpbin.exe /headers PE.exe | findstr PE
will produce
Dump of file PE.exe
PE signature found
20B magic # (PE32+)
but using dumpbin
on .obj file will produce nothing, there is no Optional Header.
Are ROM images always 32-bit?
I suspect so, but, frankly, have no idea, never worked with ROM images
PS All stated above, I believe, is true for files compiled with Visual C++
Upvotes: 2