From ab4c64a4093b98ca7a74ec29a9d947333791b26d Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 18 Feb 2020 17:01:59 +0100 Subject: [PATCH] dbghelp: Support 32 and 64-bit binaries in ImageDirectoryEntryToDataEx. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/dbghelp/pe_module.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/dlls/dbghelp/pe_module.c b/dlls/dbghelp/pe_module.c index 4b7c7baaae4..b046b987bd1 100644 --- a/dlls/dbghelp/pe_module.c +++ b/dlls/dbghelp/pe_module.c @@ -853,11 +853,25 @@ PVOID WINAPI ImageDirectoryEntryToDataEx( PVOID base, BOOLEAN image, USHORT dir, if (section) *section = NULL; if (!(nt = RtlImageNtHeader( base ))) return NULL; - if (dir >= nt->OptionalHeader.NumberOfRvaAndSizes) return NULL; - if (!(addr = nt->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL; + if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) + { + const IMAGE_NT_HEADERS64 *nt64 = (const IMAGE_NT_HEADERS64 *)nt; - *size = nt->OptionalHeader.DataDirectory[dir].Size; - if (image || addr < nt->OptionalHeader.SizeOfHeaders) return (char *)base + addr; + if (dir >= nt64->OptionalHeader.NumberOfRvaAndSizes) return NULL; + if (!(addr = nt64->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL; + *size = nt64->OptionalHeader.DataDirectory[dir].Size; + if (image || addr < nt64->OptionalHeader.SizeOfHeaders) return (char *)base + addr; + } + else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) + { + const IMAGE_NT_HEADERS32 *nt32 = (const IMAGE_NT_HEADERS32 *)nt; + + if (dir >= nt32->OptionalHeader.NumberOfRvaAndSizes) return NULL; + if (!(addr = nt32->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL; + *size = nt32->OptionalHeader.DataDirectory[dir].Size; + if (image || addr < nt32->OptionalHeader.SizeOfHeaders) return (char *)base + addr; + } + else return NULL; return RtlImageRvaToVa( nt, base, addr, section ); }