mirror of
https://github.com/reactos/reactos.git
synced 2025-06-26 07:29:43 +00:00
Implemented binary search of the export tables
svn path=/trunk/; revision=1605
This commit is contained in:
parent
b2fe7525bf
commit
bcc1b4e9a5
1 changed files with 72 additions and 67 deletions
|
@ -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,73 +638,77 @@ 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;
|
||||||
PDWORD * ExNames;
|
PDWORD * ExNames;
|
||||||
USHORT * ExOrdinals;
|
USHORT * ExOrdinals;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
PVOID ExName;
|
PVOID ExName;
|
||||||
ULONG Ordinal;
|
ULONG Ordinal;
|
||||||
|
ULONG minn, maxn;
|
||||||
|
|
||||||
// DPRINT(
|
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
|
||||||
// "LdrFindExport(Module %x, SymbolName %s)\n",
|
RtlImageDirectoryEntryToData (BaseAddress,
|
||||||
// Module,
|
TRUE,
|
||||||
// SymbolName
|
IMAGE_DIRECTORY_ENTRY_EXPORT,
|
||||||
// );
|
NULL);
|
||||||
|
|
||||||
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
|
/*
|
||||||
RtlImageDirectoryEntryToData (BaseAddress,
|
* Get header pointers
|
||||||
TRUE,
|
*/
|
||||||
IMAGE_DIRECTORY_ENTRY_EXPORT,
|
ExNames = (PDWORD *)RVA(BaseAddress,
|
||||||
NULL);
|
ExportDir->AddressOfNames);
|
||||||
|
ExOrdinals = (USHORT *)RVA(BaseAddress,
|
||||||
|
ExportDir->AddressOfNameOrdinals);
|
||||||
|
ExFunctions = (PDWORD *)RVA(BaseAddress,
|
||||||
|
ExportDir->AddressOfFunctions);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get header pointers
|
* Try a binary search first
|
||||||
*/
|
*/
|
||||||
ExNames = (PDWORD *)
|
minn = 0, maxn = ExportDir->NumberOfFunctions;
|
||||||
RVA(
|
while (minn <= maxn)
|
||||||
BaseAddress,
|
{
|
||||||
ExportDir->AddressOfNames
|
ULONG mid;
|
||||||
);
|
LONG res;
|
||||||
ExOrdinals = (USHORT *)
|
|
||||||
RVA(
|
mid = (minn + maxn) / 2;
|
||||||
BaseAddress,
|
|
||||||
ExportDir->AddressOfNameOrdinals
|
ExName = RVA(BaseAddress, ExNames[mid]);
|
||||||
);
|
res = strcmp(ExName, SymbolName);
|
||||||
ExFunctions = (PDWORD *)
|
if (res == 0)
|
||||||
RVA(
|
|
||||||
BaseAddress,
|
|
||||||
ExportDir->AddressOfFunctions
|
|
||||||
);
|
|
||||||
for ( i = 0;
|
|
||||||
( i < ExportDir->NumberOfFunctions);
|
|
||||||
i++
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ExName = RVA(
|
Ordinal = ExOrdinals[mid];
|
||||||
BaseAddress,
|
return(RVA(BaseAddress, ExFunctions[Ordinal]));
|
||||||
ExNames[i]
|
|
||||||
);
|
|
||||||
// DPRINT(
|
|
||||||
// "Comparing '%s' '%s'\n",
|
|
||||||
// ExName,
|
|
||||||
// SymbolName
|
|
||||||
// );
|
|
||||||
if (strcmp(ExName,SymbolName) == 0)
|
|
||||||
{
|
|
||||||
Ordinal = ExOrdinals[i];
|
|
||||||
return(RVA(BaseAddress, ExFunctions[Ordinal]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (res > 0)
|
||||||
|
{
|
||||||
|
maxn = mid - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
minn = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Fall back on a linear search
|
||||||
|
*/
|
||||||
|
|
||||||
DbgPrint("LdrGetExportByName() = failed to find %s\n",SymbolName);
|
DbgPrint("LDR: Falling back on a linear search of export table\n");
|
||||||
|
for (i = 0; i < ExportDir->NumberOfFunctions; i++)
|
||||||
return NULL;
|
{
|
||||||
|
ExName = RVA(BaseAddress, ExNames[i]);
|
||||||
|
if (strcmp(ExName,SymbolName) == 0)
|
||||||
|
{
|
||||||
|
Ordinal = ExOrdinals[i];
|
||||||
|
return(RVA(BaseAddress, ExFunctions[Ordinal]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DbgPrint("LdrGetExportByName() = failed to find %s\n",SymbolName);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1016,12 +1020,13 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
|
||||||
*/
|
*/
|
||||||
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase)
|
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase)
|
||||||
{
|
{
|
||||||
Status = LdrPerformRelocations(NTHeaders, ImageBase);
|
DbgPrint("LDR: Performing relocations\n");
|
||||||
if (!NT_SUCCESS(Status))
|
Status = LdrPerformRelocations(NTHeaders, ImageBase);
|
||||||
{
|
if (!NT_SUCCESS(Status))
|
||||||
DbgPrint("LdrPerformRelocations() failed\n");
|
{
|
||||||
return NULL;
|
DbgPrint("LdrPerformRelocations() failed\n");
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue