Beispiel #1
0
BOOL MyCreateRemoteThread
(
HANDLE hProcess,
LPTHREAD_START_ROUTINE pThreadProc,
LPVOID pRemoteBuf
)
{
	HANDLE      hThread = NULL;
	FARPROC     pFunc = NULL;

	if (IsVistaLater())    // Vista, 7, Server2008
	{
		pFunc = GetProcAddress(GetModuleHandle(L"ntdll.dll"),
			"NtCreateThreadEx");
		if (pFunc == NULL)
		{
			wsprintf(buf, L"MyCreateRemoteThread() : "\
				L"GetProcAddress(\"NtCreateThreadEx\") failed!!! [%d]\n",
				GetLastError());
			MessageBox(NULL, buf, L"error", MB_OK);
			return FALSE;
		}

		((PFNTCREATETHREADEX)pFunc)(&hThread,
			0x1FFFFF,
			NULL,
			hProcess,
			pThreadProc,
			pRemoteBuf,
			FALSE,
			NULL,
			NULL,
			NULL,
			NULL);
		if (hThread == NULL)
		{
			wsprintf(buf, L"MyCreateRemoteThread() : NtCreateThreadEx() failed!!! [%d]\n",
				GetLastError());
			MessageBox(NULL, buf, L"error", MB_OK);
			return FALSE;
		}
	}
	else                    // 2000, XP, Server2003
	{
		hThread = CreateRemoteThread(hProcess, NULL, 0,
			pThreadProc, pRemoteBuf, 0, NULL);
		if (hThread == NULL)
		{
			wsprintf(buf, L"MyCreateRemoteThread() : CreateRemoteThread() failed!!! [%d]\n",
				GetLastError());
			MessageBox(NULL, buf, L"error", MB_OK);
			return FALSE;
		}
	}

	if (WAIT_FAILED == WaitForSingleObject(hThread, INFINITE))
	{
		wsprintf(buf, L"MyCreateRemoteThread() : WaitForSingleObject() failed!!! [%d]\n",
			GetLastError());
		MessageBox(NULL, buf, L"error", MB_OK);
		return FALSE;
	}

	return TRUE;
}
Beispiel #2
0
static bool IsVistaLaterCache()
{
    static bool isVistaLater = IsVistaLater();
    return isVistaLater;
}