[FORMATTING]

Apply indentation of 4 spaces.

svn path=/trunk/; revision=50091
This commit is contained in:
Timo Kreuzer 2010-12-22 13:00:47 +00:00
parent 10bab36870
commit 372bbf2a73

View file

@ -73,7 +73,7 @@ LdrMappedAsDataFile(PVOID *BaseAddress)
{ {
if (0 != ((DWORD_PTR) *BaseAddress & (PAGE_SIZE - 1))) if (0 != ((DWORD_PTR) *BaseAddress & (PAGE_SIZE - 1)))
{ {
*BaseAddress = (PVOID) ((DWORD_PTR) *BaseAddress & ~ ((DWORD_PTR) PAGE_SIZE - 1)); *BaseAddress = (PVOID)((DWORD_PTR)*BaseAddress & ~((DWORD_PTR) PAGE_SIZE - 1));
return TRUE; return TRUE;
} }
@ -570,7 +570,9 @@ LdrAddModuleEntry(PVOID ImageBase,
{ {
/* loading while app is running */ /* loading while app is running */
Module->LoadCount = 1; Module->LoadCount = 1;
} else { }
else
{
/* /*
* loading while app is initializing * loading while app is initializing
* dll must not be unloaded * dll must not be unloaded
@ -1051,7 +1053,7 @@ LdrFindEntryForName(PUNICODE_STRING Name,
if (LdrpLastModule) if (LdrpLastModule)
{ {
if ((! ContainsPath && if ((!ContainsPath &&
0 == RtlCompareUnicodeString(&LdrpLastModule->BaseDllName, &AdjustedName, TRUE)) || 0 == RtlCompareUnicodeString(&LdrpLastModule->BaseDllName, &AdjustedName, TRUE)) ||
(ContainsPath && (ContainsPath &&
0 == RtlCompareUnicodeString(&LdrpLastModule->FullDllName, &AdjustedName, TRUE))) 0 == RtlCompareUnicodeString(&LdrpLastModule->FullDllName, &AdjustedName, TRUE)))
@ -1072,7 +1074,7 @@ LdrFindEntryForName(PUNICODE_STRING Name,
DPRINT("Scanning %wZ %wZ\n", &ModulePtr->BaseDllName, &AdjustedName); DPRINT("Scanning %wZ %wZ\n", &ModulePtr->BaseDllName, &AdjustedName);
if ((! ContainsPath && if ((!ContainsPath &&
0 == RtlCompareUnicodeString(&ModulePtr->BaseDllName, &AdjustedName, TRUE)) || 0 == RtlCompareUnicodeString(&ModulePtr->BaseDllName, &AdjustedName, TRUE)) ||
(ContainsPath && (ContainsPath &&
0 == RtlCompareUnicodeString(&ModulePtr->FullDllName, &AdjustedName, TRUE))) 0 == RtlCompareUnicodeString(&ModulePtr->FullDllName, &AdjustedName, TRUE)))
@ -1137,10 +1139,7 @@ LdrFixupForward(PCHAR ForwardName)
*/ */
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
Status = LdrLoadDll(NULL, Status = LdrLoadDll(NULL, NULL, &DllName, &BaseAddress);
NULL,
&DllName,
&BaseAddress);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = LdrFindEntryForName (&DllName, &Module, FALSE); Status = LdrFindEntryForName (&DllName, &Module, FALSE);
@ -1181,7 +1180,7 @@ static PVOID
LdrGetExportByOrdinal ( LdrGetExportByOrdinal (
PVOID BaseAddress, PVOID BaseAddress,
ULONG Ordinal ULONG Ordinal
) )
{ {
PIMAGE_EXPORT_DIRECTORY ExportDir; PIMAGE_EXPORT_DIRECTORY ExportDir;
ULONG ExportDirSize; ULONG ExportDirSize;
@ -1195,16 +1194,9 @@ LdrGetExportByOrdinal (
&ExportDirSize); &ExportDirSize);
ExFunctions = (PDWORD *) ExFunctions = (PDWORD*)RVA(BaseAddress, ExportDir->AddressOfFunctions);
RVA( DPRINT("LdrGetExportByOrdinal(Ordinal %lu) = %p\n",
BaseAddress, Ordinal, RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base]));
ExportDir->AddressOfFunctions
);
DPRINT(
"LdrGetExportByOrdinal(Ordinal %lu) = %p\n",
Ordinal,
RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )
);
Function = (0 != ExFunctions[Ordinal - ExportDir->Base] Function = (0 != ExFunctions[Ordinal - ExportDir->Base]
? RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] ) ? RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )
@ -1244,9 +1236,9 @@ LdrGetExportByName(PVOID BaseAddress,
WORD Hint) WORD Hint)
{ {
PIMAGE_EXPORT_DIRECTORY ExportDir; PIMAGE_EXPORT_DIRECTORY ExportDir;
PDWORD * ExFunctions; PDWORD *ExFunctions;
PDWORD * ExNames; PDWORD *ExNames;
USHORT * ExOrdinals; USHORT *ExOrdinals;
PVOID ExName; PVOID ExName;
ULONG Ordinal; ULONG Ordinal;
PVOID Function; PVOID Function;
@ -1278,12 +1270,9 @@ LdrGetExportByName(PVOID BaseAddress,
/* /*
* Get header pointers * Get header pointers
*/ */
ExNames = (PDWORD *)RVA(BaseAddress, ExNames = (PDWORD *)RVA(BaseAddress, ExportDir->AddressOfNames);
ExportDir->AddressOfNames); ExOrdinals = (USHORT *)RVA(BaseAddress, ExportDir->AddressOfNameOrdinals);
ExOrdinals = (USHORT *)RVA(BaseAddress, ExFunctions = (PDWORD *)RVA(BaseAddress, ExportDir->AddressOfFunctions);
ExportDir->AddressOfNameOrdinals);
ExFunctions = (PDWORD *)RVA(BaseAddress,
ExportDir->AddressOfFunctions);
/* /*
* Check the hint first * Check the hint first
@ -1581,16 +1570,19 @@ LdrpProcessImportDirectoryEntry(PLDR_DATA_TABLE_ENTRY Module,
} }
/* Get the import address list. */ /* Get the import address list. */
ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk); ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->FirstThunk);
/* Get the list of functions to import. */ /* Get the list of functions to import. */
if (ImportModuleDirectory->OriginalFirstThunk != 0) if (ImportModuleDirectory->OriginalFirstThunk != 0)
{ {
FunctionNameList = (PULONG) ((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk); FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
} }
else else
{ {
FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk); FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->FirstThunk);
} }
/* Get the size of IAT. */ /* Get the size of IAT. */
@ -1623,10 +1615,12 @@ LdrpProcessImportDirectoryEntry(PLDR_DATA_TABLE_ENTRY Module,
if ((*FunctionNameList) & 0x80000000) if ((*FunctionNameList) & 0x80000000)
{ {
Ordinal = (*FunctionNameList) & 0x7fffffff; Ordinal = (*FunctionNameList) & 0x7fffffff;
*ImportAddressList = LdrGetExportByOrdinal(ImportedModule->DllBase, Ordinal); *ImportAddressList = LdrGetExportByOrdinal(ImportedModule->DllBase,
Ordinal);
if ((*ImportAddressList) == NULL) if ((*ImportAddressList) == NULL)
{ {
DPRINT1("Failed to import #%ld from %wZ\n", Ordinal, &ImportedModule->FullDllName); DPRINT1("Failed to import #%ld from %wZ\n",
Ordinal, &ImportedModule->FullDllName);
RtlpRaiseImportNotFound(NULL, Ordinal, &ImportedModule->FullDllName); RtlpRaiseImportNotFound(NULL, Ordinal, &ImportedModule->FullDllName);
return STATUS_ENTRYPOINT_NOT_FOUND; return STATUS_ENTRYPOINT_NOT_FOUND;
} }
@ -1635,11 +1629,16 @@ LdrpProcessImportDirectoryEntry(PLDR_DATA_TABLE_ENTRY Module,
{ {
IMAGE_IMPORT_BY_NAME *pe_name; IMAGE_IMPORT_BY_NAME *pe_name;
pe_name = RVA(Module->DllBase, *FunctionNameList); pe_name = RVA(Module->DllBase, *FunctionNameList);
*ImportAddressList = LdrGetExportByName(ImportedModule->DllBase, pe_name->Name, pe_name->Hint); *ImportAddressList = LdrGetExportByName(ImportedModule->DllBase,
pe_name->Name,
pe_name->Hint);
if ((*ImportAddressList) == NULL) if ((*ImportAddressList) == NULL)
{ {
DPRINT1("Failed to import %s from %wZ\n", pe_name->Name, &ImportedModule->FullDllName); DPRINT1("Failed to import %s from %wZ\n",
RtlpRaiseImportNotFound((CHAR*)pe_name->Name, 0, &ImportedModule->FullDllName); pe_name->Name, &ImportedModule->FullDllName);
RtlpRaiseImportNotFound((CHAR*)pe_name->Name,
0,
&ImportedModule->FullDllName);
return STATUS_ENTRYPOINT_NOT_FOUND; return STATUS_ENTRYPOINT_NOT_FOUND;
} }
} }
@ -1747,16 +1746,19 @@ LdrpAdjustImportDirectory(PLDR_DATA_TABLE_ENTRY Module,
{ {
/* Get the import address list. */ /* Get the import address list. */
ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk); ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->FirstThunk);
/* Get the list of functions to import. */ /* Get the list of functions to import. */
if (ImportModuleDirectory->OriginalFirstThunk != 0) if (ImportModuleDirectory->OriginalFirstThunk != 0)
{ {
FunctionNameList = (PULONG) ((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk); FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
} }
else else
{ {
FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk); FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase +
(ULONG_PTR)ImportModuleDirectory->FirstThunk);
} }
/* Get the size of IAT. */ /* Get the size of IAT. */
@ -1907,7 +1909,8 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
BoundImportDescriptorCurrent = BoundImportDescriptor; BoundImportDescriptorCurrent = BoundImportDescriptor;
while (BoundImportDescriptorCurrent->OffsetModuleName) while (BoundImportDescriptorCurrent->OffsetModuleName)
{ {
ImportedName = (PCHAR)BoundImportDescriptor + BoundImportDescriptorCurrent->OffsetModuleName; ImportedName = (PCHAR)BoundImportDescriptor +
BoundImportDescriptorCurrent->OffsetModuleName;
TRACE_LDR("%wZ bound to %s\n", &Module->BaseDllName, ImportedName); TRACE_LDR("%wZ bound to %s\n", &Module->BaseDllName, ImportedName);
Status = LdrpGetOrLoadModule(SearchPath, ImportedName, &ImportedModule, TRUE); Status = LdrpGetOrLoadModule(SearchPath, ImportedName, &ImportedModule, TRUE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -1952,9 +1955,12 @@ LdrFixupImports(IN PWSTR SearchPath OPTIONAL,
PCHAR ForwarderName; PCHAR ForwarderName;
BoundForwarderRef = (PIMAGE_BOUND_FORWARDER_REF)(BoundImportDescriptorCurrent + 1); BoundForwarderRef = (PIMAGE_BOUND_FORWARDER_REF)(BoundImportDescriptorCurrent + 1);
for (i = 0; i < BoundImportDescriptorCurrent->NumberOfModuleForwarderRefs; i++, BoundForwarderRef++) for (i = 0;
i < BoundImportDescriptorCurrent->NumberOfModuleForwarderRefs;
i++, BoundForwarderRef++)
{ {
ForwarderName = (PCHAR)BoundImportDescriptor + BoundForwarderRef->OffsetModuleName; ForwarderName = (PCHAR)BoundImportDescriptor +
BoundForwarderRef->OffsetModuleName;
TRACE_LDR("%wZ bound to %s via forwardes from %s\n", TRACE_LDR("%wZ bound to %s via forwardes from %s\n",
&Module->BaseDllName, ForwarderName, ImportedName); &Module->BaseDllName, ForwarderName, ImportedName);
Status = LdrpGetOrLoadModule(SearchPath, ForwarderName, &ForwarderModule, TRUE); Status = LdrpGetOrLoadModule(SearchPath, ForwarderName, &ForwarderModule, TRUE);
@ -2153,7 +2159,7 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
* one the DLL is actually loaded, perform any * one the DLL is actually loaded, perform any
* relocation. * relocation.
*/ */
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase) if (ImageBase != (PVOID)NTHeaders->OptionalHeader.ImageBase)
{ {
DPRINT("LDR: Performing relocations\n"); DPRINT("LDR: Performing relocations\n");
Status = LdrPerformRelocations(NTHeaders, ImageBase); Status = LdrPerformRelocations(NTHeaders, ImageBase);
@ -2291,7 +2297,8 @@ LdrpLoadModule(IN PWSTR SearchPath OPTIONAL,
} }
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("Failed to create or open dll section of '%wZ' (Status %lx)\n", &AdjustedName, Status); DPRINT1("Failed to create or open dll section of '%wZ' (Status %lx)\n",
&AdjustedName, Status);
RtlFreeUnicodeString(&AdjustedName); RtlFreeUnicodeString(&AdjustedName);
return Status; return Status;
} }
@ -2795,7 +2802,9 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
{ {
TRACE_LDR("Unload %wZ - Calling entry point at %x\n", TRACE_LDR("Unload %wZ - Calling entry point at %x\n",
&Module->BaseDllName, Module->EntryPoint); &Module->BaseDllName, Module->EntryPoint);
LdrpCallDllEntry(Module, DLL_PROCESS_DETACH, (PVOID)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0)); LdrpCallDllEntry(Module,
DLL_PROCESS_DETACH,
(PVOID)(Module->LoadCount == LDRP_PROCESS_CREATION_TIME ? 1 : 0));
} }
else else
{ {
@ -3050,7 +3059,7 @@ LdrQueryProcessModuleInformation(IN PRTL_PROCESS_MODULES ModuleInformation OPTIO
PCHAR p; PCHAR p;
DPRINT("LdrQueryProcessModuleInformation() called\n"); DPRINT("LdrQueryProcessModuleInformation() called\n");
// FIXME: This code is ultra-duplicated. see lib\rtl\dbgbuffer.c // FIXME: This code is ultra-duplicated. see lib\rtl\dbgbuffer.c
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock); RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
if (ModuleInformation == NULL || Size == 0) if (ModuleInformation == NULL || Size == 0)
@ -3204,7 +3213,9 @@ LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders)
SectionHeader = (PIMAGE_SECTION_HEADER)((char *) &NTHeaders->OptionalHeader SectionHeader = (PIMAGE_SECTION_HEADER)((char *) &NTHeaders->OptionalHeader
+ NTHeaders->FileHeader.SizeOfOptionalHeader); + NTHeaders->FileHeader.SizeOfOptionalHeader);
ResidentSize = 0; ResidentSize = 0;
for (SectionIndex = 0; SectionIndex < NTHeaders->FileHeader.NumberOfSections; SectionIndex++) for (SectionIndex = 0;
SectionIndex < NTHeaders->FileHeader.NumberOfSections;
SectionIndex++)
{ {
if (0 == (SectionHeader->Characteristics & IMAGE_SCN_LNK_REMOVE) if (0 == (SectionHeader->Characteristics & IMAGE_SCN_LNK_REMOVE)
&& ResidentSize < SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize) && ResidentSize < SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize)
@ -3282,7 +3293,7 @@ LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
return Status; return Status;
} }
Status = NtQueryInformationFile (FileHandle, Status = NtQueryInformationFile(FileHandle,
&IoStatusBlock, &IoStatusBlock,
&FileInfo, &FileInfo,
sizeof (FILE_STANDARD_INFORMATION), sizeof (FILE_STANDARD_INFORMATION),
@ -3290,23 +3301,23 @@ LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("NtMapViewOfSection() failed (Status %lx)\n", Status); DPRINT1 ("NtMapViewOfSection() failed (Status %lx)\n", Status);
NtUnmapViewOfSection (NtCurrentProcess (), NtUnmapViewOfSection (NtCurrentProcess(),
BaseAddress); BaseAddress);
NtClose (SectionHandle); NtClose (SectionHandle);
return Status; return Status;
} }
Result = LdrpCheckImageChecksum (BaseAddress, Result = LdrpCheckImageChecksum(BaseAddress,
FileInfo.EndOfFile.u.LowPart); FileInfo.EndOfFile.u.LowPart);
if (Result == FALSE) if (Result == FALSE)
{ {
Status = STATUS_IMAGE_CHECKSUM_MISMATCH; Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
} }
NtUnmapViewOfSection (NtCurrentProcess (), NtUnmapViewOfSection (NtCurrentProcess(),
BaseAddress); BaseAddress);
NtClose (SectionHandle); NtClose(SectionHandle);
return Status; return Status;
} }
@ -3329,7 +3340,7 @@ LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
* @implemented * @implemented
*/ */
NTSTATUS NTAPI NTSTATUS NTAPI
LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey, LdrQueryImageFileExecutionOptions(IN PUNICODE_STRING SubKey,
IN PCWSTR ValueName, IN PCWSTR ValueName,
IN ULONG Type, IN ULONG Type,
OUT PVOID Buffer, OUT PVOID Buffer,
@ -3363,13 +3374,13 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
RtlInitUnicodeString (&KeyName, RtlInitUnicodeString (&KeyName,
NameBuffer); NameBuffer);
InitializeObjectAttributes (&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&KeyName, &KeyName,
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = NtOpenKey (&KeyHandle, Status = NtOpenKey(&KeyHandle,
KEY_READ, KEY_READ,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -3381,9 +3392,9 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
KeyInfoSize = sizeof(KeyInfoBuffer); KeyInfoSize = sizeof(KeyInfoBuffer);
KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfoBuffer; KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfoBuffer;
RtlInitUnicodeString (&ValueNameString, RtlInitUnicodeString(&ValueNameString,
(PWSTR)ValueName); (PWSTR)ValueName);
Status = NtQueryValueKey (KeyHandle, Status = NtQueryValueKey(KeyHandle,
&ValueNameString, &ValueNameString,
KeyValuePartialInformation, KeyValuePartialInformation,
KeyInfo, KeyInfo,