From 04719148b0023fb4a0365b53cd6ac01f96d9f2e8 Mon Sep 17 00:00:00 2001 From: Gunnar Dalsnes Date: Mon, 17 Mar 2003 23:05:07 +0000 Subject: [PATCH] LdrGetExportByOrdinal was broken LdrGetExportByName: fixed bug visible when number of exported functions > number of exported names + check for zero symbol name export table svn path=/trunk/; revision=4328 --- reactos/lib/ntdll/ldr/utils.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/reactos/lib/ntdll/ldr/utils.c b/reactos/lib/ntdll/ldr/utils.c index be37d0c174e..4715af52305 100644 --- a/reactos/lib/ntdll/ldr/utils.c +++ b/reactos/lib/ntdll/ldr/utils.c @@ -1,4 +1,4 @@ -/* $Id: utils.c,v 1.59 2003/01/31 21:49:11 hbirr Exp $ +/* $Id: utils.c,v 1.60 2003/03/17 23:05:07 gdalsnes Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -659,9 +659,9 @@ LdrGetExportByOrdinal ( DbgPrint( "LdrGetExportByOrdinal(Ordinal %d) = %x\n", Ordinal, - ExFunctions[ExOrdinals[Ordinal - ExportDir->Base]] + RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] ) ); - return(ExFunctions[ExOrdinals[Ordinal - ExportDir->Base]]); + return(RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )); } @@ -678,6 +678,8 @@ LdrGetExportByOrdinal ( * REVISIONS * * NOTE + * AddressOfNames and AddressOfNameOrdinals are paralell tables, + * both with NumberOfNames entries. * */ static PVOID @@ -708,7 +710,15 @@ LdrGetExportByName(PVOID BaseAddress, DbgPrint("LdrGetExportByName(): no export directory!\n"); return NULL; } - + + + //The symbol names may be missing entirely + if (ExportDir->AddressOfNames == 0) + { + DPRINT("LdrGetExportByName(): symbol names missing entirely\n"); + return NULL; + } + /* * Get header pointers */ @@ -722,7 +732,7 @@ LdrGetExportByName(PVOID BaseAddress, /* * Check the hint first */ - if (Hint < ExportDir->NumberOfFunctions) + if (Hint < ExportDir->NumberOfNames) { ExName = RVA(BaseAddress, ExNames[Hint]); if (strcmp(ExName, SymbolName) == 0) @@ -744,7 +754,7 @@ LdrGetExportByName(PVOID BaseAddress, * Try a binary search first */ minn = 0; - maxn = ExportDir->NumberOfFunctions; + maxn = ExportDir->NumberOfNames; while (minn <= maxn) { ULONG mid; @@ -786,7 +796,7 @@ LdrGetExportByName(PVOID BaseAddress, * Fall back on a linear search */ DPRINT("LdrGetExportByName(): Falling back on a linear search of export table\n"); - for (i = 0; i < ExportDir->NumberOfFunctions; i++) + for (i = 0; i < ExportDir->NumberOfNames; i++) { ExName = RVA(BaseAddress, ExNames[i]); if (strcmp(ExName,SymbolName) == 0)