mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 12:13:01 +00:00
- Corrected processing import directories to handle case when executable imports the same DLL more times.
svn path=/trunk/; revision=8549
This commit is contained in:
parent
fa714393ca
commit
c3d3178f3e
1 changed files with 105 additions and 96 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: utils.c,v 1.82 2004/01/31 23:53:45 gvg Exp $
|
/* $Id: utils.c,v 1.83 2004/03/06 20:32:06 navaraf Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -1416,25 +1416,26 @@ LdrpGetOrLoadModule(PWCHAR SerachPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
LdrpProcessImportDirectory(PLDR_MODULE Module,
|
LdrpProcessImportDirectory(
|
||||||
|
PLDR_MODULE Module,
|
||||||
PLDR_MODULE ImportedModule,
|
PLDR_MODULE ImportedModule,
|
||||||
|
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory,
|
||||||
PCHAR ImportedName)
|
PCHAR ImportedName)
|
||||||
{
|
{
|
||||||
PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PVOID* ImportAddressList;
|
PVOID* ImportAddressList;
|
||||||
PULONG FunctionNameList;
|
PULONG FunctionNameList;
|
||||||
DWORD pName;
|
|
||||||
WORD pHint;
|
|
||||||
PVOID IATBase;
|
PVOID IATBase;
|
||||||
ULONG OldProtect;
|
ULONG OldProtect;
|
||||||
ULONG Ordinal;
|
ULONG Ordinal;
|
||||||
ULONG IATSize;
|
ULONG IATSize;
|
||||||
PCHAR Name;
|
|
||||||
|
|
||||||
DPRINT("LdrpProcessImportDirectory(%x '%wZ', %x '%wZ', %x '%s')\n",
|
DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
|
||||||
Module, &Module->BaseDllName, ImportedModule,
|
Module, &Module->BaseDllName, ImportedName);
|
||||||
&ImportedModule->BaseDllName, ImportedName, ImportedName);
|
|
||||||
|
if (ImportModuleDirectory == NULL)
|
||||||
|
{
|
||||||
|
PCHAR Name;
|
||||||
|
|
||||||
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
|
ImportModuleDirectory = (PIMAGE_IMPORT_MODULE_DIRECTORY)
|
||||||
RtlImageDirectoryEntryToData(Module->BaseAddress,
|
RtlImageDirectoryEntryToData(Module->BaseAddress,
|
||||||
|
@ -1451,6 +1452,16 @@ LdrpProcessImportDirectory(PLDR_MODULE Module,
|
||||||
Name = (PCHAR)Module->BaseAddress + ImportModuleDirectory->dwRVAModuleName;
|
Name = (PCHAR)Module->BaseAddress + ImportModuleDirectory->dwRVAModuleName;
|
||||||
if (0 == _stricmp(Name, ImportedName))
|
if (0 == _stricmp(Name, ImportedName))
|
||||||
{
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImportModuleDirectory++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImportModuleDirectory->dwRVAModuleName == 0)
|
||||||
|
{
|
||||||
|
return STATUS_UNSUCCESSFUL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the import address list. */
|
/* Get the import address list. */
|
||||||
ImportAddressList = (PVOID *)(Module->BaseAddress + ImportModuleDirectory->dwRVAFunctionAddressList);
|
ImportAddressList = (PVOID *)(Module->BaseAddress + ImportModuleDirectory->dwRVAFunctionAddressList);
|
||||||
|
@ -1486,7 +1497,6 @@ LdrpProcessImportDirectory(PLDR_MODULE Module,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Walk through function list and fixup addresses. */
|
/* Walk through function list and fixup addresses. */
|
||||||
|
|
||||||
while (*FunctionNameList != 0L)
|
while (*FunctionNameList != 0L)
|
||||||
{
|
{
|
||||||
if ((*FunctionNameList) & 0x80000000)
|
if ((*FunctionNameList) & 0x80000000)
|
||||||
|
@ -1496,13 +1506,12 @@ LdrpProcessImportDirectory(PLDR_MODULE Module,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pName = (DWORD) (Module->BaseAddress + *FunctionNameList + 2);
|
IMAGE_IMPORT_BY_NAME *pe_name;
|
||||||
pHint = *(PWORD)(Module->BaseAddress + *FunctionNameList);
|
pe_name = RVA(Module->BaseAddress, *FunctionNameList);
|
||||||
|
*ImportAddressList = LdrGetExportByName(ImportedModule->BaseAddress, pe_name->Name, pe_name->Hint);
|
||||||
*ImportAddressList = LdrGetExportByName(ImportedModule->BaseAddress, (PUCHAR)pName, pHint);
|
|
||||||
if ((*ImportAddressList) == NULL)
|
if ((*ImportAddressList) == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to import %s\n", pName);
|
DPRINT1("Failed to import %s\n", pe_name->Name);
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1521,13 +1530,11 @@ LdrpProcessImportDirectory(PLDR_MODULE Module,
|
||||||
DPRINT1("Failed to protect IAT.\n");
|
DPRINT1("Failed to protect IAT.\n");
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ImportModuleDirectory++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS LdrpAdjustImportDirectory(PLDR_MODULE Module,
|
NTSTATUS LdrpAdjustImportDirectory(PLDR_MODULE Module,
|
||||||
PLDR_MODULE ImportedModule,
|
PLDR_MODULE ImportedModule,
|
||||||
PUCHAR ImportedName)
|
PUCHAR ImportedName)
|
||||||
|
@ -1726,7 +1733,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
|
||||||
{
|
{
|
||||||
TRACE_LDR("%wZ has stale binding to %wZ\n",
|
TRACE_LDR("%wZ has stale binding to %wZ\n",
|
||||||
&Module->BaseDllName, &ImportedModule->BaseDllName);
|
&Module->BaseDllName, &ImportedModule->BaseDllName);
|
||||||
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
|
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("failed to import %s\n", ImportedName);
|
DPRINT1("failed to import %s\n", ImportedName);
|
||||||
|
@ -1787,7 +1794,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
|
||||||
if (WrongForwarder ||
|
if (WrongForwarder ||
|
||||||
ImportedModule->Flags & IMAGE_NOT_AT_BASE)
|
ImportedModule->Flags & IMAGE_NOT_AT_BASE)
|
||||||
{
|
{
|
||||||
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
|
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("failed to import %s\n", ImportedName);
|
DPRINT1("failed to import %s\n", ImportedName);
|
||||||
|
@ -1813,7 +1820,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
|
||||||
*/
|
*/
|
||||||
TRACE_LDR("Stale BIND %s from %wZ\n",
|
TRACE_LDR("Stale BIND %s from %wZ\n",
|
||||||
ImportedName, &Module->BaseDllName);
|
ImportedName, &Module->BaseDllName);
|
||||||
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
|
Status = LdrpProcessImportDirectory(Module, ImportedModule, NULL, ImportedName);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("faild to import %s\n", ImportedName);
|
DPRINT1("faild to import %s\n", ImportedName);
|
||||||
|
@ -1848,9 +1855,10 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
|
||||||
{
|
{
|
||||||
LdrpDecrementLoadCount(Module, FALSE);
|
LdrpDecrementLoadCount(Module, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE_LDR("Initializing imports for %wZ from %s\n",
|
TRACE_LDR("Initializing imports for %wZ from %s\n",
|
||||||
&Module->BaseDllName, ImportedName);
|
&Module->BaseDllName, ImportedName);
|
||||||
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
|
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportModuleDirectoryCurrent, ImportedName);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("failed to import %s\n", ImportedName);
|
DPRINT1("failed to import %s\n", ImportedName);
|
||||||
|
@ -1859,6 +1867,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
|
||||||
ImportModuleDirectoryCurrent++;
|
ImportModuleDirectoryCurrent++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TlsDirectory && TlsSize > 0)
|
if (TlsDirectory && TlsSize > 0)
|
||||||
{
|
{
|
||||||
LdrpAcquireTlsSlot(Module, TlsSize, FALSE);
|
LdrpAcquireTlsSlot(Module, TlsSize, FALSE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue