# ProxyWorkItemLoadLibrary

<pre><code>typedef NTSTATUS(NTAPI* NTWAITFORSINGLEOBJECT)(HANDLE, BOOL, PLARGE_INTEGER);
typedef NTSTATUS(NTAPI* RTLQUEUEWORKITEM)(PRTL_WORK_ITEM_ROUTINE, PVOID, ULONG);

<strong>HMODULE ProxyWorkItemLoadLibraryW(_In_ LPCWSTR lpModuleName)
</strong>{
	NTWAITFORSINGLEOBJECT NtWaitForSingleObject = NULL;
	RTLQUEUEWORKITEM RtlQueueWorkItem = NULL;
	NTSTATUS Status = STATUS_SUCCESS;
	LARGE_INTEGER Timeout = { 0 };

	NtWaitForSingleObject = (NTWAITFORSINGLEOBJECT)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtWaitForSingleObject");
	RtlQueueWorkItem = (RTLQUEUEWORKITEM)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueueWorkItem");

	if (!NtWaitForSingleObject || !RtlQueueWorkItem)
		return NULL;

	if(RtlQueueWorkItem((PRTL_WORK_ITEM_ROUTINE)&#x26;LoadLibraryW, (PVOID)lpModuleName, WT_EXECUTEDEFAULT) != STATUS_SUCCESS)
		return NULL;

	Timeout.QuadPart = -500000;

	NtWaitForSingleObject(GetCurrentProcessNoForward(), FALSE, &#x26;Timeout);

	return GetModuleHandleW(lpModuleName);
}

HMODULE ProxyWorkItemLoadLibraryA(_In_ LPCSTR lpModuleName)
{
	NTWAITFORSINGLEOBJECT NtWaitForSingleObject = NULL;
	RTLQUEUEWORKITEM RtlQueueWorkItem = NULL;
	NTSTATUS Status = STATUS_SUCCESS;
	LARGE_INTEGER Timeout = { 0 };

	NtWaitForSingleObject = (NTWAITFORSINGLEOBJECT)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtWaitForSingleObject");
	RtlQueueWorkItem = (RTLQUEUEWORKITEM)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueueWorkItem");

	if (!NtWaitForSingleObject || !RtlQueueWorkItem)
		return NULL;

	if(RtlQueueWorkItem((PRTL_WORK_ITEM_ROUTINE)&#x26;LoadLibraryA, (PVOID)lpModuleName, WT_EXECUTEDEFAULT) != STATUS_SUCCESS)
		return NULL;

	Timeout.QuadPart = -500000;

	NtWaitForSingleObject(GetCurrentProcessNoForward(), FALSE, &#x26;Timeout);

	return GetModuleHandleA(lpModuleName);
}
</code></pre>

