Implemented binary search of the export tables

svn path=/trunk/; revision=1605
This commit is contained in:
David Welch 2001-02-06 02:03:35 +00:00
parent b2fe7525bf
commit bcc1b4e9a5

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.36 2001/01/23 04:37:13 phreak Exp $ /* $Id: utils.c,v 1.37 2001/02/06 02:03:35 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -638,10 +638,8 @@ LdrGetExportByOrdinal (
* *
*/ */
static PVOID static PVOID
LdrGetExportByName ( LdrGetExportByName (PVOID BaseAddress,
PVOID BaseAddress, PUCHAR SymbolName)
PUCHAR SymbolName
)
{ {
PIMAGE_EXPORT_DIRECTORY ExportDir; PIMAGE_EXPORT_DIRECTORY ExportDir;
PDWORD * ExFunctions; PDWORD * ExFunctions;
@ -650,12 +648,7 @@ LdrGetExportByName (
ULONG i; ULONG i;
PVOID ExName; PVOID ExName;
ULONG Ordinal; ULONG Ordinal;
ULONG minn, maxn;
// DPRINT(
// "LdrFindExport(Module %x, SymbolName %s)\n",
// Module,
// SymbolName
// );
ExportDir = (PIMAGE_EXPORT_DIRECTORY) ExportDir = (PIMAGE_EXPORT_DIRECTORY)
RtlImageDirectoryEntryToData (BaseAddress, RtlImageDirectoryEntryToData (BaseAddress,
@ -666,44 +659,55 @@ LdrGetExportByName (
/* /*
* Get header pointers * Get header pointers
*/ */
ExNames = (PDWORD *) ExNames = (PDWORD *)RVA(BaseAddress,
RVA( ExportDir->AddressOfNames);
BaseAddress, ExOrdinals = (USHORT *)RVA(BaseAddress,
ExportDir->AddressOfNames ExportDir->AddressOfNameOrdinals);
); ExFunctions = (PDWORD *)RVA(BaseAddress,
ExOrdinals = (USHORT *) ExportDir->AddressOfFunctions);
RVA(
BaseAddress, /*
ExportDir->AddressOfNameOrdinals * Try a binary search first
); */
ExFunctions = (PDWORD *) minn = 0, maxn = ExportDir->NumberOfFunctions;
RVA( while (minn <= maxn)
BaseAddress,
ExportDir->AddressOfFunctions
);
for ( i = 0;
( i < ExportDir->NumberOfFunctions);
i++
)
{ {
ExName = RVA( ULONG mid;
BaseAddress, LONG res;
ExNames[i]
); mid = (minn + maxn) / 2;
// DPRINT(
// "Comparing '%s' '%s'\n", ExName = RVA(BaseAddress, ExNames[mid]);
// ExName, res = strcmp(ExName, SymbolName);
// SymbolName if (res == 0)
// ); {
Ordinal = ExOrdinals[mid];
return(RVA(BaseAddress, ExFunctions[Ordinal]));
}
else if (res > 0)
{
maxn = mid - 1;
}
else
{
minn = mid + 1;
}
}
/*
* Fall back on a linear search
*/
DbgPrint("LDR: Falling back on a linear search of export table\n");
for (i = 0; i < ExportDir->NumberOfFunctions; i++)
{
ExName = RVA(BaseAddress, ExNames[i]);
if (strcmp(ExName,SymbolName) == 0) if (strcmp(ExName,SymbolName) == 0)
{ {
Ordinal = ExOrdinals[i]; Ordinal = ExOrdinals[i];
return(RVA(BaseAddress, ExFunctions[Ordinal])); return(RVA(BaseAddress, ExFunctions[Ordinal]));
} }
} }
DbgPrint("LdrGetExportByName() = failed to find %s\n",SymbolName); DbgPrint("LdrGetExportByName() = failed to find %s\n",SymbolName);
return NULL; return NULL;
} }
@ -1016,6 +1020,7 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
*/ */
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase) if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase)
{ {
DbgPrint("LDR: Performing relocations\n");
Status = LdrPerformRelocations(NTHeaders, ImageBase); Status = LdrPerformRelocations(NTHeaders, ImageBase);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {