On Tue, 3 Dec 2024, Pali Rohár wrote:
On Tuesday 03 December 2024 16:35:38 Martin Storsjö wrote:
On Fri, 29 Nov 2024, Pali Rohár wrote:
PE format allows to have variable length of Data Directories in PE Optional
Header. The exact number of Data Directories is stored in NumberOfRvaAndSizes
field. Size of the optional header depends on the number of Data Directories.
Constants IMAGE_SIZEOF_NT_OPTIONAL32_HEADER and
IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
are for PE images with all 16 Data Directories. And so cannot be used for
checking validity of SizeOfOptionalHeader.
Older PE linkers were generating PE binaries with less number of Data
Directories than 16 if trailing entries were empty. And gendef cannot
recognize such PE binaries.
Relax check for PE SizeOfOptionalHeader field. Allow any number of Data
Directories in PE Optional Header, including zero.
---
mingw-w64-tools/gendef/src/gendef.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mingw-w64-tools/gendef/src/gendef.c
b/mingw-w64-tools/gendef/src/gendef.c
index 7440d60f35df..ae9603fe1a3a 100644
--- a/mingw-w64-tools/gendef/src/gendef.c
+++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -313,19 +313,19 @@ load_pep (void)
gPEDta = NULL;
return 0;
}
- if (gPEDta->FileHeader.SizeOfOptionalHeader ==
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
+ if (gPEDta->FileHeader.SizeOfOptionalHeader >=
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER-sizeof(gPEDta->OptionalHeader.DataDirectory)
This looks ok, but the expression
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER -
sizeof(gPEDta->OptionalHeader.DataDirectory)
feels somewhat clumsy; is there any more concise way of expressing this,
like some sort of offsetof() or so?
Via offsetof() it can be expressed as:
offsetof(IMAGE_OPTIONAL_HEADER32, DataDirectory)
Ok, I think this is much more readable than the previous subtraction
expression, so I'd be ok with the patch in that form.
Can you do that change and test it, and post an updated patch? Thanks!
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public