From c39e28edfb1c89bb40e2ece0de3d8abf54ebd804 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 25 Sep 2009 12:46:39 +0200 Subject: [PATCH] ntdll: Support both 32-bit and 64-bit modules in RtlImageDirectoryEntryToData. --- dlls/ntdll/loader.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 76f0e5dad3..cc9904b7d9 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2522,10 +2522,25 @@ PVOID WINAPI RtlImageDirectoryEntryToData( HMODULE module, BOOL image, WORD dir, image = FALSE; } if (!(nt = RtlImageNtHeader( module ))) return NULL; - if (dir >= nt->OptionalHeader.NumberOfRvaAndSizes) return NULL; - if (!(addr = nt->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL; - *size = nt->OptionalHeader.DataDirectory[dir].Size; - if (image || addr < nt->OptionalHeader.SizeOfHeaders) return (char *)module + addr; + if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) + { + const IMAGE_NT_HEADERS64 *nt64 = (IMAGE_NT_HEADERS64 *)nt; + + 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 *)module + addr; + } + else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) + { + const IMAGE_NT_HEADERS32 *nt32 = (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 *)module + addr; + } + else return NULL; /* not mapped as image, need to find the section containing the virtual address */ return RtlImageRvaToVa( nt, module, addr, NULL ); -- 2.32.0.93.g670b81a890