[NTDLL:LDR]

- Code cleanup in LdrpLoadDll

svn path=/trunk/; revision=57093
This commit is contained in:
Thomas Faber 2012-08-18 08:19:48 +00:00
parent e812fee585
commit 8b45c713bf

View file

@ -2415,28 +2415,28 @@ LdrpLoadDll(IN BOOLEAN Redirected,
{
PPEB Peb = NtCurrentPeb();
NTSTATUS Status = STATUS_SUCCESS;
PWCHAR p1, p2, p1min;
const WCHAR *p;
BOOLEAN GotExtension;
WCHAR c;
WCHAR NameBuffer[MAX_PATH + 6];
LPWSTR RawDllName;
UNICODE_STRING RawDllNameString;
UNICODE_STRING RawDllName;
PLDR_DATA_TABLE_ENTRY LdrEntry;
BOOLEAN InInit = LdrpInLdrInit;
/* Save the Raw DLL Name */
RawDllName = NameBuffer;
if (DllName->Length >= sizeof(NameBuffer)) return STATUS_NAME_TOO_LONG;
RtlMoveMemory(RawDllName, DllName->Buffer, DllName->Length);
RtlInitEmptyUnicodeString(&RawDllName, NameBuffer, sizeof(NameBuffer));
RtlCopyUnicodeString(&RawDllName, DllName);
/* Find the name without the extension */
p1 = DllName->Buffer + DllName->Length / sizeof(WCHAR) - 1;
p2 = NULL;
for (p1min = DllName->Buffer; p1 >= p1min; p1--)
/* Find the extension, if present */
p = DllName->Buffer + DllName->Length / sizeof(WCHAR) - 1;
GotExtension = FALSE;
while (p >= DllName->Buffer)
{
c = *p1;
c = *p--;
if (c == L'.')
{
p2 = p1;
GotExtension = TRUE;
break;
}
else if (c == L'\\')
@ -2445,8 +2445,8 @@ LdrpLoadDll(IN BOOLEAN Redirected,
}
}
/* Check if no extension was found */
if (!p2)
/* If no extension was found, add the default extension */
if (!GotExtension)
{
/* Check that we have space to add one */
if ((DllName->Length + LdrApiDefaultExtension.Length + sizeof(UNICODE_NULL)) >=
@ -2466,30 +2466,10 @@ LdrpLoadDll(IN BOOLEAN Redirected,
return STATUS_NAME_TOO_LONG;
}
/* FIXME: CLEAN THIS UP WITH Rtl String Functions */
/* Add it */
RtlMoveMemory((PVOID)((ULONG_PTR)RawDllName + DllName->Length),
LdrApiDefaultExtension.Buffer,
LdrApiDefaultExtension.Length);
/* Save the length to a unicode string */
RawDllNameString.Length = DllName->Length + LdrApiDefaultExtension.Length;
/* Null terminate it */
RawDllName[RawDllNameString.Length / sizeof(WCHAR)] = 0;
/* Add it. Needs to be null terminated, thus the length check above */
(VOID)RtlAppendUnicodeStringToString(&RawDllName,
&LdrApiDefaultExtension);
}
else
{
/* Null terminate it */
RawDllName[DllName->Length / sizeof(WCHAR)] = 0;
/* Save the length to a unicode string */
RawDllNameString.Length = DllName->Length;
}
/* Now create a unicode string for the DLL's name */
RawDllNameString.MaximumLength = sizeof(NameBuffer);
RawDllNameString.Buffer = NameBuffer;
/* Check for init flag and acquire lock */
if (!InInit) RtlEnterCriticalSection(&LdrpLoaderLock);
@ -2497,14 +2477,14 @@ LdrpLoadDll(IN BOOLEAN Redirected,
/* Show debug message */
if (ShowSnaps)
{
DPRINT1("LDR: LdrLoadDll, loading %ws from %ws\n",
RawDllName,
DPRINT1("LDR: LdrLoadDll, loading %wZ from %ws\n",
&RawDllName,
DllPath ? DllPath : L"");
}
/* Check if the DLL is already loaded */
if (!LdrpCheckForLoadedDll(DllPath,
&RawDllNameString,
&RawDllName,
FALSE,
Redirected,
&LdrEntry))