+ /*
+ * Validate the message buffer if we do not use a process' heap buffer
+ * (CsrAllocateCaptureBuffer succeeded because we haven't allocated
+ * a too large (>= 64 kB, size of the CSR heap) data buffer).
+ */
+ if (!WriteOutputRequest->UseVirtualMemory)
+ {
+ /*
+ * For optimization purposes, Windows (and hence ReactOS, too, for
+ * compatibility reasons) uses a static buffer if no more than one
+ * cell is written. Otherwise a new buffer is used.
+ * The client-side expects that we know this behaviour.
+ */
+ if (NumCells <= 1)
+ {
+ /*
+ * Adjust the internal pointer, because its old value points to
+ * the static buffer in the original ApiMessage structure.
+ */
+ // WriteOutputRequest->CharInfo = &WriteOutputRequest->StaticBuffer;
+ CharInfo = &WriteOutputRequest->StaticBuffer;
+ }
+ else
+ {
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&WriteOutputRequest->CharInfo,
+ NumCells,
+ sizeof(CHAR_INFO)))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ goto Quit;
+ }
+
+ CharInfo = WriteOutputRequest->CharInfo;
+ }
+ }
+ else
+ {
+ /*
+ * This was not the case: we use a heap buffer. Retrieve its contents.
+ */
+ ULONG Size = NumCells * sizeof(CHAR_INFO);
+
+ CharInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY, Size);
+ if (CharInfo == NULL)
+ {
+ Status = STATUS_NO_MEMORY;
+ goto Quit;
+ }
+
+ Status = NtReadVirtualMemory(Process->ProcessHandle,
+ WriteOutputRequest->CharInfo,
+ CharInfo,
+ Size,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ ConsoleFreeHeap(CharInfo);
+ // Status = STATUS_NO_MEMORY;
+ goto Quit;
+ }
+ }
+