https://git.reactos.org/?p=reactos.git;a=commitdiff;h=883ae6d93bff097e76cbe…
commit 883ae6d93bff097e76cbef4ac27babbd9c6ae483
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sun Oct 4 20:07:34 2020 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Dec 6 16:37:57 2020 +0100
[RTL] Fix RtlImageDirectoryEntryToData to support both 32 and 64 bit images
---
sdk/lib/rtl/image.c | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/sdk/lib/rtl/image.c b/sdk/lib/rtl/image.c
index 5ae6f679f72..9efb3d19744 100644
--- a/sdk/lib/rtl/image.c
+++ b/sdk/lib/rtl/image.c
@@ -289,17 +289,38 @@ RtlImageDirectoryEntryToData(
if (NtHeader == NULL)
return NULL;
- if (Directory >= SWAPD(NtHeader->OptionalHeader.NumberOfRvaAndSizes))
- return NULL;
+ if (NtHeader->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
+ {
+ PIMAGE_OPTIONAL_HEADER64 OptionalHeader =
(PIMAGE_OPTIONAL_HEADER64)&NtHeader->OptionalHeader;
- Va = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress);
- if (Va == 0)
- return NULL;
+ if (Directory >= SWAPD(OptionalHeader->NumberOfRvaAndSizes))
+ return NULL;
+
+ Va = SWAPD(OptionalHeader->DataDirectory[Directory].VirtualAddress);
+ if (Va == 0)
+ return NULL;
+
+ *Size = SWAPD(OptionalHeader->DataDirectory[Directory].Size);
+
+ if (MappedAsImage || Va < SWAPD(OptionalHeader->SizeOfHeaders))
+ return (PVOID)((ULONG_PTR)BaseAddress + Va);
+ }
+ else
+ {
+ PIMAGE_OPTIONAL_HEADER32 OptionalHeader =
(PIMAGE_OPTIONAL_HEADER32)&NtHeader->OptionalHeader;
+
+ if (Directory >= SWAPD(OptionalHeader->NumberOfRvaAndSizes))
+ return NULL;
+
+ Va = SWAPD(OptionalHeader->DataDirectory[Directory].VirtualAddress);
+ if (Va == 0)
+ return NULL;
- *Size = SWAPD(NtHeader->OptionalHeader.DataDirectory[Directory].Size);
+ *Size = SWAPD(OptionalHeader->DataDirectory[Directory].Size);
- if (MappedAsImage || Va < SWAPD(NtHeader->OptionalHeader.SizeOfHeaders))
- return (PVOID)((ULONG_PTR)BaseAddress + Va);
+ if (MappedAsImage || Va < SWAPD(OptionalHeader->SizeOfHeaders))
+ return (PVOID)((ULONG_PTR)BaseAddress + Va);
+ }
/* Image mapped as ordinary file, we must find raw pointer */
return RtlImageRvaToVa(NtHeader, BaseAddress, Va, NULL);