allowing non-i386 printer drivers
Andy Polyakov
appro at fy.chalmers.se
Mon Mar 19 18:27:19 GMT 2007
Hi,
>> Hi! Attached patch allows to add non-i386 printer
>> drivers by relaxing COFF parser and making it
>> COFF+/64-bit neutral. PE_HEADER_*_VER_OFFSET
>> are removed because they are not used anywhere
>> and corresponding values reside at different locations
>> in COFF+. If they're required, then one would have
>> to look at beginning of so called optional header, the one
>> that is suggested to skip over. Cheers. A.
>
> Do you have a link to the docs describing the header information
> referred to above?
Well, I simply used Platform SDK headers and consulted PECOFF
specification... I mean I don't have a link, but I can guide you through
relevant structures in WinNT.h [from Platform SDK]. It starts with
IMAGE_DOS_HEADER structure, e_lfanew member, but this part is unchanged.
Then you "slide" to IMAGE_NT_HEADERS, which is essentially DWORD
Signature followed by IMAGE_FILE_HEADER and IMAGE_OPTIONAL_HEADER. The
"slide" part is not changed, only how many bytes are read. Now,
IMAGE_FILE_HEADER is *common* for 32- and 64-bit modules. Among other
things (most notably WORD NumberOfSections) it contains 16-bit value
denoting size of following IMAGE_OPTIONAL_HEADER, WORD
SizeOfOptionalHeader. The latter is actually allowed to be zero in .obj
files. But zero or not, COFF specification says that if you skip over
this amount of bytes, you land on section headers table. This is also
common for 32- and 64-bit modules, therefore lseek from SEEK_CUR with
compensation for difference between amount of read bytes,
NE_HEADER_SIZE, and size of IMAGE_FILE_HEADER + Signature. Then the
point is that the format for IMAGE_SECTION_HEADERs table is again same
for 32- and 64-bit modules and its parsing is not touched by proposed
patch. Needless to mention that this, same format for section headers
table, means that no executable module can be larger than 4GB[-1byte],
but it's hardly a limitation.
As for [skipped] IMAGE_OPTIONAL_HEADER. Its first element is WORD Magic,
which effectively denotes either IMAGE_OPTIONAL_HEADER structure
(IMAGE_NT_OPTIONAL_HDR32_MAGIC, value 0x10b, referred to as COFF or
PE32) or IMAGE_OPTIONAL_HEADER64 structure
(IMAGE_NT_OPTIONAL_HDR64_MAGIC, value 0x20b, referred to as COFF+ or
PE32+). Difference between these two is [void *] ImageBase and [size_t]
members describing initial stack and heap reservation. Naturally on
Win64 these values have to be 64-bit and therefore all values
*following* their position in structure will then be shifted in memory
layout. In other words PE_HEADER_*_VER_OFFSET values would be different
depending on Magic value (+4 for HDR64_MAGIC to be precise). But once
again, they are not used anywhere and I suggested to remove them, so
that those who would get the idea to use them later would be explicitly
motivated to consider this difference between Win32 and Win64 modules.
Does it answer the question? A.
More information about the samba-technical
mailing list