Implement the magic flag in RtlImageDirectoryEntryToData and make the Size parameter non-optional.

svn path=/trunk/; revision=16918
This commit is contained in:
Filip Navara 2005-07-31 10:22:29 +00:00
parent 5b7fe4e1d2
commit d6820f5fff
3 changed files with 27 additions and 18 deletions

View file

@ -237,6 +237,7 @@ LdrpInitializeTlsForProccess(VOID)
PLDR_DATA_TABLE_ENTRY Module;
PIMAGE_TLS_DIRECTORY TlsDirectory;
PTLS_DATA TlsData;
ULONG Size;
DPRINT("LdrpInitializeTlsForProccess() called for %wZ\n", &ExeModule->BaseDllName);
@ -263,7 +264,7 @@ LdrpInitializeTlsForProccess(VOID)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_TLS,
NULL);
&Size);
ASSERT(Module->TlsIndex < LdrpTlsCount);
TlsData = &LdrpTlsArray[Module->TlsIndex];
TlsData->StartAddressOfRawData = (PVOID)TlsDirectory->StartAddressOfRawData;
@ -1476,6 +1477,7 @@ LdrpProcessImportDirectory(
NTSTATUS Status;
PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
PCHAR Name;
ULONG Size;
DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
Module, &Module->BaseDllName, ImportedName);
@ -1485,7 +1487,7 @@ LdrpProcessImportDirectory(
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
&Size);
if (ImportModuleDirectory == NULL)
{
return STATUS_UNSUCCESSFUL;
@ -1529,6 +1531,7 @@ LdrpAdjustImportDirectory(PLDR_DATA_TABLE_ENTRY Module,
ULONG IATSize;
PIMAGE_NT_HEADERS NTHeaders;
PCHAR Name;
ULONG Size;
DPRINT("LdrpAdjustImportDirectory(Module %x '%wZ', %x '%wZ', %x '%s')\n",
Module, &Module->BaseDllName, ImportedModule, &ImportedModule->BaseDllName, ImportedName);
@ -1537,7 +1540,7 @@ LdrpAdjustImportDirectory(PLDR_DATA_TABLE_ENTRY Module,
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
&Size);
if (ImportModuleDirectory == NULL)
{
return STATUS_UNSUCCESSFUL;
@ -1647,6 +1650,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
NTSTATUS Status;
PLDR_DATA_TABLE_ENTRY ImportedModule;
PCHAR ImportedName;
ULONG Size;
DPRINT("LdrFixupImports(SearchPath %x, Module %x)\n", SearchPath, Module);
@ -1655,7 +1659,7 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_TLS,
NULL);
&Size);
if (TlsDirectory)
{
TlsSize = TlsDirectory->EndAddressOfRawData
@ -1676,13 +1680,13 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
&Size);
BoundImportDescriptor = (PIMAGE_BOUND_IMPORT_DESCRIPTOR)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
NULL);
&Size);
if (BoundImportDescriptor != NULL && ImportModuleDirectory == NULL)
{
@ -2142,7 +2146,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
PLDR_DATA_TABLE_ENTRY ImportedModule;
NTSTATUS Status;
LONG LoadCount;
ULONG Size;
if (Unload)
{
@ -2163,7 +2167,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
NULL);
&Size);
if (BoundImportDescriptor)
{
/* dereferencing all imported modules, use the bound import descriptor */
@ -2197,7 +2201,7 @@ LdrpUnloadModule(PLDR_DATA_TABLE_ENTRY Module,
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
&Size);
if (ImportModuleDirectory)
{
/* dereferencing all imported modules, use the import descriptor */

View file

@ -49,7 +49,7 @@ PVOID
STDCALL
RtlImageDirectoryEntryToData (
PVOID BaseAddress,
BOOLEAN bFlag,
BOOLEAN bMappedAsImage,
ULONG Directory,
PULONG Size
)
@ -59,7 +59,11 @@ RtlImageDirectoryEntryToData (
/* Magic flag for non-mapped images. */
if ((ULONG_PTR)BaseAddress & 1)
BaseAddress = (PVOID)((ULONG_PTR)BaseAddress & ~1);
{
BaseAddress = (PVOID)((ULONG_PTR)BaseAddress & ~1);
bMappedAsImage = FALSE;
}
NtHeader = RtlImageNtHeader (BaseAddress);
if (NtHeader == NULL)
@ -72,10 +76,9 @@ RtlImageDirectoryEntryToData (
if (Va == 0)
return NULL;
if (Size)
*Size = NtHeader->OptionalHeader.DataDirectory[Directory].Size;
*Size = NtHeader->OptionalHeader.DataDirectory[Directory].Size;
if (bFlag)
if (bMappedAsImage || Va < NtHeader->OptionalHeader.SizeOfHeaders)
return (PVOID)((ULONG_PTR)BaseAddress + Va);
/* image mapped as ordinary file, we must find raw pointer */

View file

@ -161,8 +161,8 @@ LdrpLoadImage (
if (ModuleBase)
*ModuleBase = ModuleObject->DllBase;
//if (SectionPointer)
// *SectionPointer = ModuleObject->
if (SectionPointer)
*SectionPointer = ModuleObject;
if (EntryPoint)
*EntryPoint = ModuleObject->EntryPoint;
@ -204,7 +204,7 @@ LdrpLoadAndCallImage ( PUNICODE_STRING ModuleName )
DriverEntry = (PDRIVER_INITIALIZE)ModuleObject->EntryPoint;
RtlZeroMemory(&DriverObject, sizeof(DriverObject));
DriverObject.DriverStart = ModuleObject->DllBase;
// DriverObject.DriverStart = ModuleObject->DllBase;
Status = DriverEntry(&DriverObject, NULL);
if (!NT_SUCCESS(Status))
@ -768,6 +768,7 @@ LdrPEProcessModule(
}
RtlCopyUnicodeString(&CreatedModuleObject->FullDllName, FileName);
CreatedModuleObject->FullDllName.Buffer[FileName->Length / sizeof(WCHAR)] = 0;
LdrpBuildModuleBaseName(&CreatedModuleObject->BaseDllName,
&CreatedModuleObject->FullDllName);
@ -1482,13 +1483,14 @@ LdrPEFixupImports ( PLDR_DATA_TABLE_ENTRY Module )
PCHAR ImportedName;
PLDR_DATA_TABLE_ENTRY ImportedModule;
NTSTATUS Status;
ULONG Size;
/* Process each import module */
ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
NULL);
&Size);
DPRINT("Processeing import directory at %p\n", ImportModuleDirectory);
while (ImportModuleDirectory->Name)
{