dbghelp: Support 32 and 64-bit binaries in ImageDirectoryEntryToDataEx.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-02-18 17:01:59 +01:00 committed by Alexandre Julliard
parent c60b21926e
commit ab4c64a409
1 changed files with 18 additions and 4 deletions

View File

@ -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 );
}