- Split LdrpProcessImportDirectory into LdrpProcessImportDirectory and

LdrpProcessImportDirectoryEntry. Sometimes it is necessary to process
  a single entry from import directory and sometimes it is necessary
  to process all entries with the same name.

svn path=/trunk/; revision=8684
This commit is contained in:
Hartmut Birr 2004-03-13 18:14:04 +00:00
parent 05825a6aab
commit c417fd21b1

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.83 2004/03/06 20:32:06 navaraf Exp $
/* $Id: utils.c,v 1.84 2004/03/13 18:14:04 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -1416,11 +1416,10 @@ LdrpGetOrLoadModule(PWCHAR SerachPath,
}
static NTSTATUS
LdrpProcessImportDirectory(
LdrpProcessImportDirectoryEntry(
PLDR_MODULE Module,
PLDR_MODULE ImportedModule,
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory,
PCHAR ImportedName)
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory)
{
NTSTATUS Status;
PVOID* ImportAddressList;
@ -1430,39 +1429,11 @@ LdrpProcessImportDirectory(
ULONG Ordinal;
ULONG IATSize;
DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
Module, &Module->BaseDllName, ImportedName);
if (ImportModuleDirectory == NULL)
{
PCHAR Name;
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
RtlImageDirectoryEntryToData(Module->BaseAddress,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
if (ImportModuleDirectory == NULL)
if (ImportModuleDirectory == NULL || ImportModuleDirectory->dwRVAModuleName == 0)
{
return STATUS_UNSUCCESSFUL;
}
while (ImportModuleDirectory->dwRVAModuleName)
{
Name = (PCHAR)Module->BaseAddress + ImportModuleDirectory->dwRVAModuleName;
if (0 == _stricmp(Name, ImportedName))
{
break;
}
ImportModuleDirectory++;
}
if (ImportModuleDirectory->dwRVAModuleName == 0)
{
return STATUS_UNSUCCESSFUL;
}
}
/* Get the import address list. */
ImportAddressList = (PVOID *)(Module->BaseAddress + ImportModuleDirectory->dwRVAFunctionAddressList);
@ -1534,8 +1505,53 @@ LdrpProcessImportDirectory(
return STATUS_SUCCESS;
}
static NTSTATUS
LdrpProcessImportDirectory(
PLDR_MODULE Module,
PLDR_MODULE ImportedModule,
PCHAR ImportedName)
{
NTSTATUS Status;
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
PCHAR Name;
NTSTATUS LdrpAdjustImportDirectory(PLDR_MODULE Module,
DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
Module, &Module->BaseDllName, ImportedName);
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
RtlImageDirectoryEntryToData(Module->BaseAddress,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
if (ImportModuleDirectory == NULL)
{
return STATUS_UNSUCCESSFUL;
}
while (ImportModuleDirectory->dwRVAModuleName)
{
Name = (PCHAR)Module->BaseAddress + ImportModuleDirectory->dwRVAModuleName;
if (0 == _stricmp(Name, ImportedName))
{
Status = LdrpProcessImportDirectoryEntry(Module,
ImportedModule,
ImportModuleDirectory);
if (!NT_SUCCESS(Status))
{
return Status;
}
}
ImportModuleDirectory++;
}
return STATUS_SUCCESS;
}
static NTSTATUS
LdrpAdjustImportDirectory(PLDR_MODULE Module,
PLDR_MODULE ImportedModule,
PUCHAR ImportedName)
{
@ -1733,7 +1749,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
{
TRACE_LDR("%wZ has stale binding to %wZ\n",
&Module->BaseDllName, &ImportedModule->BaseDllName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
if (!NT_SUCCESS(Status))
{
DPRINT1("failed to import %s\n", ImportedName);
@ -1794,7 +1810,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
if (WrongForwarder ||
ImportedModule->Flags & IMAGE_NOT_AT_BASE)
{
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
if (!NT_SUCCESS(Status))
{
DPRINT1("failed to import %s\n", ImportedName);
@ -1820,7 +1836,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
*/
TRACE_LDR("Stale BIND %s from %wZ\n",
ImportedName, &Module->BaseDllName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
if (!NT_SUCCESS(Status))
{
DPRINT1("faild to import %s\n", ImportedName);
@ -1858,7 +1874,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
TRACE_LDR("Initializing imports for %wZ from %s\n",
&Module->BaseDllName, ImportedName);
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportModuleDirectoryCurrent, ImportedName);
Status = LdrpProcessImportDirectoryEntry(Module, ImportedModule, ImportModuleDirectoryCurrent);
if (!NT_SUCCESS(Status))
{
DPRINT1("failed to import %s\n", ImportedName);