- /* Set up the data to send to the Console Server */
- ReadConsoleRequest->InputHandle = hConsoleInput;
- ReadConsoleRequest->Unicode = bUnicode;
- ReadConsoleRequest->NrCharactersToRead = nNumberOfCharsToRead;
- ReadConsoleRequest->NrCharactersRead = 0;
- ReadConsoleRequest->CtrlWakeupMask = 0;
- if (pInputControl && pInputControl->nLength == sizeof(CONSOLE_READCONSOLE_CONTROL))
+ ReadConsoleRequest->InitialNumBytes = 0;
+ ReadConsoleRequest->CtrlWakeupMask = 0;
+ ReadConsoleRequest->ControlKeyState = 0;
+
+ /*
+ * From MSDN (ReadConsole function), the description
+ * for pInputControl says:
+ * "This parameter requires Unicode input by default.
+ * For ANSI mode, set this parameter to NULL."
+ */
+ _SEH2_TRY
+ {
+ if (bUnicode && pInputControl &&
+ pInputControl->nLength == sizeof(CONSOLE_READCONSOLE_CONTROL))
+ {
+ /* Sanity check */
+ if (pInputControl->nInitialChars <= nNumberOfCharsToRead)
+ {
+ ReadConsoleRequest->InitialNumBytes =
+ pInputControl->nInitialChars * sizeof(WCHAR); // CharSize
+
+ if (pInputControl->nInitialChars != 0)
+ {
+ /*
+ * It is possible here to overwrite the static buffer, in case
+ * the number of bytes to read was smaller than the static buffer.
+ * In this case, this means we are continuing a pending read,
+ * and we do not need in fact the executable name that was
+ * stored in the static buffer because it was first grabbed when
+ * we started the first read.
+ */
+ RtlCopyMemory(ReadConsoleRequest->Buffer,
+ lpBuffer,
+ ReadConsoleRequest->InitialNumBytes);
+ }
+
+ ReadConsoleRequest->CtrlWakeupMask = pInputControl->dwCtrlWakeupMask;
+ }
+ else
+ {
+ // Status = STATUS_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ /* We are in a situation where pInputControl has no meaning */
+ pInputControl = NULL;
+ }
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ // HACK
+ if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
+ SetLastError(ERROR_INVALID_ACCESS);
+ _SEH2_YIELD(return FALSE);
+ }
+ _SEH2_END;
+
+ /* Check for sanity */
+/*
+ if (!NT_SUCCESS(Status) && pInputControl)