/* INCLUDES *****************************************************************/
#include <ntdll.h>
+
#define NDEBUG
#include <debug.h>
ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
ctx.hModule = module->DllBase;
ctx.lpResourceName = (LPCWSTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
- status = RtlCreateActivationContext( &module->EntryPointActivationContext, &ctx );
+ status = RtlCreateActivationContext(0, (PVOID)&ctx, 0, NULL, NULL, &module->EntryPointActivationContext);
}
return status;
}
/* Show snaps */
if (ShowSnaps)
{
- DPRINT1("LDR: Flags %d %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
+ DPRINT1("LDR: Flags %lu %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
}
}
/* Show snaps */
if (ShowSnaps)
{
- DPRINT1("LDR: Flags %d %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
+ DPRINT1("LDR: Flags %lu %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
}
}
/* Show snaps */
if (ShowSnaps)
{
- DPRINT1("LDR: Flags %d %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
+ DPRINT1("LDR: Flags %lu %wZ (%lx)\n", Flags, ImportNameUnic, Entry->LoadCount);
}
}
ImageBase = (ULONG_PTR)NtHeaders->OptionalHeader.ImageBase;
ImageEnd = ImageBase + ViewSize;
- DPRINT1("LDR: LdrpMapDll Relocating Image Name %ws (%p -> %p)\n", DllName, ImageBase, ViewBase);
+ DPRINT1("LDR: LdrpMapDll Relocating Image Name %ws (%p -> %p)\n", DllName, (PVOID)ImageBase, ViewBase);
/* Scan all the modules */
ListHead = &Peb->Ldr->InLoadOrderModuleList;
PVOID ViewBase = NULL;
SIZE_T ViewSize = 0;
PIMAGE_NT_HEADERS NtHeader, NtHeader2;
- DPRINT("LdrpCheckForLoadedDll('%S' '%wZ' %d %d %p)\n", DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L"", DllName, Flag, RedirectedDll, LdrEntry);
+ DPRINT("LdrpCheckForLoadedDll('%S' '%wZ' %u %u %p)\n", DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L"", DllName, Flag, RedirectedDll, LdrEntry);
/* Check if a dll name was provided */
if (!(DllName->Buffer) || !(DllName->Buffer[0])) return FALSE;
/* FIXME: Warning, "Flag" is used as magic instead of "Static" */
/* FIXME: Warning, code does not support redirection at all */
-
+
/* Look in the hash table if flag was set */
lookinhash:
if (Flag)
if (ShowSnaps)
{
- DPRINT1("LDR: LdrpCheckForLoadedDll - Unable To Locate %ws: 0x%08x\n",
- DllName->Buffer, Length);
+ DPRINT1("LDR: LdrpCheckForLoadedDll - Unable To Locate %wZ: 0x%08x\n",
+ &DllName, Length);
}
/* Return failure */
Flag = TRUE;
goto lookinhash;
}
-
+
/* FIXME: Warning, activation context missing */
/* NOTE: From here on down, everything looks good */
/* Check if it's in the process of being unloaded */
if (!CurEntry->InMemoryOrderModuleList.Flink) continue;
-
+
/* The header is untrusted, use SEH */
_SEH2_TRY
{
}
/* Check if our buffer is large enough */
- if (Name->Length > sizeof(ImportBuffer))
+ if (Length > sizeof(ImportBuffer))
{
/* Allocate from heap, plus 2 bytes for the Hint */
ImportName = RtlAllocateHeap(RtlGetProcessHeap(),
if (!ExportDir)
{
- DPRINT1("Image %wZ has no exports, but were trying to get procedure %s. BaseAddress asked %p, got entry BA %p\n", &LdrEntry->BaseDllName, Name ? Name->Buffer : NULL, BaseAddress, LdrEntry->DllBase);
+ DPRINT1("Image %wZ has no exports, but were trying to get procedure %Z. BaseAddress asked 0x%p, got entry BA 0x%p\n",
+ &LdrEntry->BaseDllName, &Name, BaseAddress, LdrEntry->DllBase);
Status = STATUS_PROCEDURE_NOT_FOUND;
_SEH2_YIELD(goto Quickie;)
}
{
PPEB Peb = NtCurrentPeb();
NTSTATUS Status = STATUS_SUCCESS;
- PWCHAR p1, p2;
+ const WCHAR *p;
+ BOOLEAN GotExtension;
WCHAR c;
- WCHAR NameBuffer[266];
- LPWSTR RawDllName;
- UNICODE_STRING RawDllNameString;
+ WCHAR NameBuffer[MAX_PATH + 6];
+ UNICODE_STRING RawDllName;
PLDR_DATA_TABLE_ENTRY LdrEntry;
BOOLEAN InInit = LdrpInLdrInit;
- /* Find the name without the extension */
- p1 = DllName->Buffer;
- p2 = NULL;
- while (*p1)
+ /* Save the Raw DLL Name */
+ if (DllName->Length >= sizeof(NameBuffer)) return STATUS_NAME_TOO_LONG;
+ RtlInitEmptyUnicodeString(&RawDllName, NameBuffer, sizeof(NameBuffer));
+ RtlCopyUnicodeString(&RawDllName, DllName);
+
+ /* 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'\\')
{
- p2 = NULL;
+ break;
}
}
- /* Save the Raw DLL Name */
- RawDllName = NameBuffer;
- if (DllName->Length >= sizeof(NameBuffer)) return STATUS_NAME_TOO_LONG;
- RtlMoveMemory(RawDllName, DllName->Buffer, DllName->Length);
-
- /* Check if no extension was found or if we got a slash */
- if (!(p2) || (*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)) >=
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;
- }
- else
- {
- /* Null terminate it */
- RawDllName[DllName->Length / sizeof(WCHAR)] = 0;
-
- /* Save the length to a unicode string */
- RawDllNameString.Length = DllName->Length;
+ /* Add it. Needs to be null terminated, thus the length check above */
+ (VOID)RtlAppendUnicodeStringToString(&RawDllName,
+ &LdrApiDefaultExtension);
}
- /* 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);
/* 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))
Redirected,
&LdrEntry);
if (!NT_SUCCESS(Status)) goto Quickie;
-
+
/* FIXME: Need to mark the DLL range for the stack DB */
//RtlpStkMarkDllRange(LdrEntry);
/* Cancel the load */
LdrpClearLoadInProgress();
-
+
/* Unload the DLL */
if (ShowSnaps)
{
//ShimLoadCallback = RtlDecodeSystemPointer(g_pfnSE_DllLoaded);
//ShimLoadCallback(LdrEntry);
}
-
+
/* Run the init routine */
Status = LdrpRunInitializeRoutines(NULL);
if (!NT_SUCCESS(Status))