Author: hbelusca
Date: Mon Nov 19 23:26:36 2012
New Revision: 57740
URL:
http://svn.reactos.org/svn/reactos?rev=57740&view=rev
Log:
[KERNEL32/CONSRV]
- Merge IntWriteConsoleOutputCharacter and WriteConsoleOutputAttribute functions into
IntWriteConsoleOutputCode helper functions, which is used inside
WriteConsoleOutputAttribute and WriteConsoleOutputCharacterW/A.
- In server-side, merge CsrWriteConsoleOutputChar and CsrWriteConsoleOutputAttrib into the
server API SrvWriteConsoleOutputString.
- The structures CSRSS_WRITE_CONSOLE_OUTPUT_CHAR and CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB are
merged into CSRSS_WRITE_CONSOLE_OUTPUT_CODE.
[CONSRV]
- Add a CsrValidateMessageBuffer usage.
Modified:
branches/ros-csrss/dll/win32/kernel32/client/console/readwrite.c
branches/ros-csrss/include/reactos/subsys/win/conmsg.h
branches/ros-csrss/win32ss/user/consrv/conoutput.c
Modified: branches/ros-csrss/dll/win32/kernel32/client/console/readwrite.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/dll/win32/kernel32/cl…
==============================================================================
--- branches/ros-csrss/dll/win32/kernel32/client/console/readwrite.c [iso-8859-1]
(original)
+++ branches/ros-csrss/dll/win32/kernel32/client/console/readwrite.c [iso-8859-1] Mon Nov
19 23:26:36 2012
@@ -436,6 +436,7 @@
ULONG /* SizeBytes, */ CharSize;
// DWORD Written = 0;
+ /* Determine the needed size */
CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
WriteConsoleRequest->BufferSize = nNumberOfCharsToWrite * CharSize;
@@ -654,75 +655,109 @@
static
BOOL
-IntWriteConsoleOutputCharacter(HANDLE hConsoleOutput,
- PVOID lpCharacter,
- DWORD nLength,
- COORD dwWriteCoord,
- LPDWORD lpNumberOfCharsWritten,
- BOOL bUnicode)
-{
- PCSR_API_MESSAGE Request;
- ULONG CsrRequest;
+IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
+ CODE_TYPE CodeType,
+ CONST VOID *pCode,
+ DWORD nLength,
+ COORD dwWriteCoord,
+ LPDWORD lpNumberOfCodesWritten)
+{
NTSTATUS Status;
- ULONG CharSize, nChars;
- //ULONG SizeBytes;
- DWORD Written = 0;
-
- CharSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
-
- nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CharSize);
- //SizeBytes = nChars * CharSize;
-
- Request = RtlAllocateHeap(RtlGetProcessHeap(), 0,
- max(sizeof(CSR_API_MESSAGE),
-
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR)
- + min (nChars, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR /
CharSize) * CharSize));
- if (Request == NULL)
- {
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCSRSS_WRITE_CONSOLE_OUTPUT_CODE WriteConsoleOutputCodeRequest =
&ApiMessage.Data.WriteConsoleOutputCodeRequest;
+ PCSR_CAPTURE_BUFFER CaptureBuffer;
+ ULONG CodeSize; //, nChars;
+ // ULONG SizeBytes;
+ // DWORD Written = 0;
+
+ /* Determine the needed size */
+/*
+ CodeSize = (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ nChars = min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR / CodeSize);
+ SizeBytes = nChars * CodeSize;
+*/
+ switch (CodeType)
+ {
+ case CODE_ASCII:
+ CodeSize = sizeof(CHAR);
+ break;
+
+ case CODE_UNICODE:
+ CodeSize = sizeof(WCHAR);
+ break;
+
+ case CODE_ATTRIBUTE:
+ CodeSize = sizeof(WORD);
+ break;
+
+ default:
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+ WriteConsoleOutputCodeRequest->BufferSize = nLength * CodeSize;
+
+ /* Allocate a Capture Buffer */
+ CaptureBuffer = CsrAllocateCaptureBuffer(1,
WriteConsoleOutputCodeRequest->BufferSize);
+ if (CaptureBuffer == NULL)
+ {
+ DPRINT1("CsrAllocateCaptureBuffer failed!\n");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
- CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT_CHAR);
- Request->Data.WriteConsoleOutputCharRequest.Coord = dwWriteCoord;
-
- while (nLength > 0)
- {
- DWORD BytesWrite;
-
- Request->Data.WriteConsoleOutputCharRequest.ConsoleHandle = hConsoleOutput;
- Request->Data.WriteConsoleOutputCharRequest.Unicode = bUnicode;
- Request->Data.WriteConsoleOutputCharRequest.Length = (WORD)min(nLength,
nChars);
- BytesWrite = Request->Data.WriteConsoleOutputCharRequest.Length * CharSize;
-
- memcpy(Request->Data.WriteConsoleOutputCharRequest.String, lpCharacter,
BytesWrite);
-
- Status = CsrClientCallServer(Request,
- NULL,
- CsrRequest,
- max(sizeof(CSR_API_MESSAGE),
-
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR) + BytesWrite));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
+/*
+ /\* Allocate space in the Buffer *\/
+ CsrAllocateMessagePointer(CaptureBuffer,
+ SizeBytes,
+
(PVOID*)&WriteConsoleOutputCodeRequest->pCode.pCode);
+*/
+ /* Capture the buffer to write */
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)pCode,
+ WriteConsoleOutputCodeRequest->BufferSize,
+ (PVOID*)&WriteConsoleOutputCodeRequest->pCode.pCode);
+
+ /* Start writing */
+ WriteConsoleOutputCodeRequest->ConsoleHandle = hConsoleOutput;
+ WriteConsoleOutputCodeRequest->CodeType = CodeType;
+ WriteConsoleOutputCodeRequest->Coord = dwWriteCoord;
+
+ /**
+ ** TODO: HACK: Surely it has to go into CONSRV !!
+ **/
+ // while (nLength > 0)
+ {
+ // DWORD BytesWrite;
+
+ WriteConsoleOutputCodeRequest->Length = nLength; // (WORD)min(nLength,
nChars);
+ // BytesWrite = WriteConsoleOutputCodeRequest->Length * CodeSize;
+
+ // memcpy(WriteConsoleOutputCodeRequest->pCode.pCode, pCode, BytesWrite);
+
+ Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX,
ConsolepWriteConsoleOutputString),
+ sizeof(CSRSS_WRITE_CONSOLE_OUTPUT_CODE));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
{
- RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
+ CsrFreeCaptureBuffer(CaptureBuffer);
BaseSetLastNTError(Status);
return FALSE;
}
- nLength -= Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
- lpCharacter = (PVOID)((ULONG_PTR)lpCharacter +
(ULONG_PTR)(Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten *
CharSize));
- Written += Request->Data.WriteConsoleOutputCharRequest.NrCharactersWritten;
-
- Request->Data.WriteConsoleOutputCharRequest.Coord =
Request->Data.WriteConsoleOutputCharRequest.EndCoord;
- }
-
- if (lpNumberOfCharsWritten != NULL)
- {
- *lpNumberOfCharsWritten = Written;
- }
-
- RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
+ // nLength -= WriteConsoleOutputCodeRequest->NrCharactersWritten;
+ // pCode = (PVOID)((ULONG_PTR)pCode +
/*(ULONG_PTR)(*/WriteConsoleOutputCodeRequest->NrCharactersWritten * CodeSize/*)*/);
+ // Written += WriteConsoleOutputCodeRequest->NrCharactersWritten;
+
+ WriteConsoleOutputCodeRequest->Coord =
WriteConsoleOutputCodeRequest->EndCoord;
+ }
+
+ if (lpNumberOfCodesWritten != NULL)
+ // *lpNumberOfCodesWritten = Written;
+ // *lpNumberOfCodesWritten =
WriteConsoleOutputCodeRequest->NrCharactersWritten;
+ *lpNumberOfCodesWritten = WriteConsoleOutputCodeRequest->Length;
+
+ CsrFreeCaptureBuffer(CaptureBuffer);
return TRUE;
}
@@ -778,7 +813,7 @@
if (lpNumberOfCodesWritten)
*lpNumberOfCodesWritten = FillOutputRequest->Length;
- // *lpNumberOfCharsWritten = Request.Data.FillOutputRequest.NrCharactersWritten;
+ // *lpNumberOfCodesWritten = Request.Data.FillOutputRequest.NrCharactersWritten;
return TRUE;
}
@@ -1191,12 +1226,12 @@
COORD dwWriteCoord,
LPDWORD lpNumberOfCharsWritten)
{
- return IntWriteConsoleOutputCharacter(hConsoleOutput,
- (PVOID)lpCharacter,
- nLength,
- dwWriteCoord,
- lpNumberOfCharsWritten,
- TRUE);
+ return IntWriteConsoleOutputCode(hConsoleOutput,
+ CODE_UNICODE,
+ lpCharacter,
+ nLength,
+ dwWriteCoord,
+ lpNumberOfCharsWritten);
}
@@ -1213,12 +1248,12 @@
COORD dwWriteCoord,
LPDWORD lpNumberOfCharsWritten)
{
- return IntWriteConsoleOutputCharacter(hConsoleOutput,
- (PVOID)lpCharacter,
- nLength,
- dwWriteCoord,
- lpNumberOfCharsWritten,
- FALSE);
+ return IntWriteConsoleOutputCode(hConsoleOutput,
+ CODE_ASCII,
+ lpCharacter,
+ nLength,
+ dwWriteCoord,
+ lpNumberOfCharsWritten);
}
@@ -1235,54 +1270,12 @@
COORD dwWriteCoord,
LPDWORD lpNumberOfAttrsWritten)
{
- PCSR_API_MESSAGE Request;
- ULONG CsrRequest;
- NTSTATUS Status;
- WORD Size;
-
- Request = RtlAllocateHeap(RtlGetProcessHeap(),
- 0,
- max(sizeof(CSR_API_MESSAGE),
-
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB)
- + min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB /
sizeof(WORD)) * sizeof(WORD)));
- if (Request == NULL)
- {
- SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
- }
-
- CsrRequest = CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT_ATTRIB);
- Request->Data.WriteConsoleOutputAttribRequest.Coord = dwWriteCoord;
-
- if (lpNumberOfAttrsWritten)
- *lpNumberOfAttrsWritten = nLength;
- while (nLength)
- {
- Size = (WORD)min(nLength, CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB / sizeof(WORD));
- Request->Data.WriteConsoleOutputAttribRequest.ConsoleHandle = hConsoleOutput;
- Request->Data.WriteConsoleOutputAttribRequest.Length = Size;
- memcpy(Request->Data.WriteConsoleOutputAttribRequest.Attribute, lpAttribute,
Size * sizeof(WORD));
-
- Status = CsrClientCallServer(Request,
- NULL,
- CsrRequest,
- max(sizeof(CSR_API_MESSAGE),
-
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB) + Size * sizeof(WORD)));
-
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request->Status))
- {
- RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
- BaseSetLastNTError (Status);
- return FALSE;
- }
- nLength -= Size;
- lpAttribute += Size;
- Request->Data.WriteConsoleOutputAttribRequest.Coord =
Request->Data.WriteConsoleOutputAttribRequest.EndCoord;
- }
-
- RtlFreeHeap(RtlGetProcessHeap(), 0, Request);
-
- return TRUE;
+ return IntWriteConsoleOutputCode(hConsoleOutput,
+ CODE_ATTRIBUTE,
+ lpAttribute,
+ nLength,
+ dwWriteCoord,
+ lpNumberOfAttrsWritten);
}
Modified: branches/ros-csrss/include/reactos/subsys/win/conmsg.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsy…
==============================================================================
--- branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] (original)
+++ branches/ros-csrss/include/reactos/subsys/win/conmsg.h [iso-8859-1] Mon Nov 19
23:26:36 2012
@@ -26,7 +26,7 @@
ConsolepReadConsoleOutput,
ConsolepWriteConsoleOutput,
ConsolepReadConsoleOutputString,
- // ConsolepWriteConsoleOutputString,
+ ConsolepWriteConsoleOutputString,
ConsolepFillConsoleOutput,
ConsolepGetMode,
// ConsolepGetNumberOfFonts,
@@ -112,13 +112,6 @@
} CONSRV_API_NUMBER, *PCONSRV_API_NUMBER;
-#define CSR_API_MESSAGE_HEADER_SIZE(Type) (FIELD_OFFSET(CSR_API_MESSAGE, Data) +
sizeof(Type))
-#define CSRSS_MAX_WRITE_CONSOLE (LPC_MAX_DATA_LENGTH -
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE))
-#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH -
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR))
-#define CSRSS_MAX_WRITE_CONSOLE_OUTPUT_ATTRIB (LPC_MAX_DATA_LENGTH -
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB))
-#define CSRSS_MAX_READ_CONSOLE_OUTPUT_CHAR (LPC_MAX_DATA_LENGTH -
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_CHAR))
-#define CSRSS_MAX_READ_CONSOLE_OUTPUT_ATTRIB (LPC_MAX_DATA_LENGTH -
CSR_API_MESSAGE_HEADER_SIZE(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB))
-
#define CONSOLE_INPUT_MODE_VALID (0x0f)
#define CONSOLE_OUTPUT_MODE_VALID (0x03)
@@ -150,12 +143,12 @@
WORD NrCharactersRead;
HANDLE EventHandle;
- PVOID Buffer;
- ULONG BufferSize;
-
UNICODE_STRING ExeName;
DWORD CtrlWakeupMask;
DWORD ControlKeyState;
+
+ ULONG BufferSize;
+ PVOID Buffer;
} CSRSS_READ_CONSOLE, *PCSRSS_READ_CONSOLE;
typedef struct
@@ -184,26 +177,6 @@
HANDLE ConsoleHandle;
COORD Position;
} CSRSS_SET_CURSOR_POSITION, *PCSRSS_SET_CURSOR_POSITION;
-
-typedef struct
-{
- HANDLE ConsoleHandle;
- BOOL Unicode;
- WORD Length;
- COORD Coord;
- COORD EndCoord;
- ULONG NrCharactersWritten;
- CHAR String[0];
-} CSRSS_WRITE_CONSOLE_OUTPUT_CHAR, *PCSRSS_WRITE_CONSOLE_OUTPUT_CHAR;
-
-typedef struct
-{
- HANDLE ConsoleHandle;
- WORD Length;
- COORD Coord;
- COORD EndCoord;
- WORD Attribute[0];
-} CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB, *PCSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB;
typedef struct
{
@@ -304,6 +277,28 @@
typedef struct
{
HANDLE ConsoleHandle;
+ USHORT CodeType;
+
+ ULONG BufferSize;
+ WORD Length;
+ COORD Coord;
+ COORD EndCoord;
+
+ ULONG NrCharactersWritten;
+
+ union
+ {
+ // PVOID String;
+ PVOID pCode;
+ PCHAR AsciiChar;
+ PWCHAR UnicodeChar;
+ PWORD Attribute;
+ } pCode; // Either a pointer to a character or to an attribute.
+} CSRSS_WRITE_CONSOLE_OUTPUT_CODE, *PCSRSS_WRITE_CONSOLE_OUTPUT_CODE;
+
+typedef struct
+{
+ HANDLE ConsoleHandle;
CODE_TYPE CodeType;
union
@@ -588,8 +583,7 @@
CSRSS_WRITE_CONSOLE WriteConsoleRequest; // SrvWriteConsole /
WriteConsole
CSRSS_WRITE_CONSOLE_INPUT WriteConsoleInputRequest;
CSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest;
- CSRSS_WRITE_CONSOLE_OUTPUT_CHAR WriteConsoleOutputCharRequest;
- CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB WriteConsoleOutputAttribRequest;
+ CSRSS_WRITE_CONSOLE_OUTPUT_CODE WriteConsoleOutputCodeRequest;
CSRSS_FILL_OUTPUT FillOutputRequest;
CSRSS_SET_ATTRIB SetAttribRequest;
Modified: branches/ros-csrss/win32ss/user/consrv/conoutput.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-csrss/win32ss/user/consrv/c…
==============================================================================
--- branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] (original)
+++ branches/ros-csrss/win32ss/user/consrv/conoutput.c [iso-8859-1] Mon Nov 19 23:26:36
2012
@@ -469,6 +469,11 @@
DPRINT("SrvReadConsoleOutput\n");
+ CharInfo = ReadConsoleOutputRequest->CharInfo;
+ ReadRegion = ReadConsoleOutputRequest->ReadRegion;
+ BufferSize = ReadConsoleOutputRequest->BufferSize;
+ BufferCoord = ReadConsoleOutputRequest->BufferCoord;
+
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&ReadConsoleOutputRequest->CharInfo,
BufferSize.X * BufferSize.Y,
@@ -479,11 +484,6 @@
Status = ConioLockScreenBuffer(ProcessData,
ReadConsoleOutputRequest->ConsoleHandle, &Buff, GENERIC_READ);
if (!NT_SUCCESS(Status)) return Status;
-
- CharInfo = ReadConsoleOutputRequest->CharInfo;
- ReadRegion = ReadConsoleOutputRequest->ReadRegion;
- BufferSize = ReadConsoleOutputRequest->BufferSize;
- BufferCoord = ReadConsoleOutputRequest->BufferCoord;
/*
if (!Win32CsrValidateBuffer(ProcessData->Process, CharInfo,
@@ -648,6 +648,10 @@
DPRINT("SrvWriteConsoleOutput\n");
+ BufferSize = WriteConsoleOutputRequest->BufferSize;
+ BufferCoord = WriteConsoleOutputRequest->BufferCoord;
+ CharInfo = WriteConsoleOutputRequest->CharInfo;
+
if (!CsrValidateMessageBuffer(ApiMessage,
(PVOID*)&WriteConsoleOutputRequest->CharInfo,
BufferSize.X * BufferSize.Y,
@@ -663,10 +667,6 @@
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
-
- BufferSize = WriteConsoleOutputRequest->BufferSize;
- BufferCoord = WriteConsoleOutputRequest->BufferCoord;
- CharInfo = WriteConsoleOutputRequest->CharInfo;
/*
if (!Win32CsrValidateBuffer(ProcessData->Process, CharInfo,
@@ -743,8 +743,6 @@
DPRINT("SrvReadConsoleOutputString\n");
- ReadBuffer = ReadConsoleOutputCodeRequest->pCode.pCode;
-
CodeType = ReadConsoleOutputCodeRequest->CodeType;
switch (CodeType)
{
@@ -764,11 +762,20 @@
return STATUS_INVALID_PARAMETER;
}
+ if (!CsrValidateMessageBuffer(ApiMessage,
+
(PVOID*)&ReadConsoleOutputCodeRequest->pCode.pCode,
+ ReadConsoleOutputCodeRequest->NumCodesToRead,
+ CodeSize))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
Status =
ConioLockScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
ReadConsoleOutputCodeRequest->ConsoleHandle, &Buff, GENERIC_READ);
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
+ ReadBuffer = ReadConsoleOutputCodeRequest->pCode.pCode;
Xpos = ReadConsoleOutputCodeRequest->ReadCoord.X;
Ypos = (ReadConsoleOutputCodeRequest->ReadCoord.Y + Buff->VirtualY) %
Buff->MaxY;
@@ -845,169 +852,136 @@
return STATUS_SUCCESS;
}
-CSR_API(CsrWriteConsoleOutputChar)
+CSR_API(SrvWriteConsoleOutputString)
{
NTSTATUS Status;
- PCSRSS_WRITE_CONSOLE_OUTPUT_CHAR WriteConsoleOutputCharRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleOutputCharRequest;
- PCHAR String, tmpString = NULL;
- PBYTE Buffer;
+ PCSRSS_WRITE_CONSOLE_OUTPUT_CODE WriteConsoleOutputCodeRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleOutputCodeRequest;
PCSRSS_CONSOLE Console;
PCSRSS_SCREEN_BUFFER Buff;
- DWORD X, Y, Length, CharSize, Written = 0;
+ USHORT CodeType;
+ PBYTE Buffer; // PUCHAR
+ PCHAR String, tmpString = NULL;
+ DWORD X, Y, Length; // , Written = 0;
+ ULONG CodeSize;
SMALL_RECT UpdateRect;
- DPRINT("CsrWriteConsoleOutputChar\n");
-
- CharSize = (WriteConsoleOutputCharRequest->Unicode ? sizeof(WCHAR) :
sizeof(CHAR));
-
- if (ApiMessage->Header.u1.s1.TotalLength
- < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_CHAR)
- + (WriteConsoleOutputCharRequest->Length * CharSize))
- {
- DPRINT1("Invalid ApiMessage size\n");
+ DPRINT("SrvWriteConsoleOutputString\n");
+
+ CodeType = WriteConsoleOutputCodeRequest->CodeType;
+ switch (CodeType)
+ {
+ case CODE_ASCII:
+ CodeSize = sizeof(CHAR);
+ break;
+
+ case CODE_UNICODE:
+ CodeSize = sizeof(WCHAR);
+ break;
+
+ case CODE_ATTRIBUTE:
+ CodeSize = sizeof(WORD);
+ break;
+
+ default:
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (!CsrValidateMessageBuffer(ApiMessage,
+
(PVOID*)&WriteConsoleOutputCodeRequest->pCode.pCode,
+ WriteConsoleOutputCodeRequest->Length,
+ CodeSize))
+ {
return STATUS_INVALID_PARAMETER;
}
- Status = ConioLockScreenBuffer(CsrGetClientThread()->Process,
- WriteConsoleOutputCharRequest->ConsoleHandle,
+ Status =
ConioLockScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
+ WriteConsoleOutputCodeRequest->ConsoleHandle,
&Buff,
GENERIC_WRITE);
- if (NT_SUCCESS(Status))
- {
- Console = Buff->Header.Console;
- if(WriteConsoleOutputCharRequest->Unicode)
+ if (!NT_SUCCESS(Status)) return Status;
+
+ Console = Buff->Header.Console;
+
+ switch (CodeType)
+ {
+ case CODE_UNICODE:
{
Length = WideCharToMultiByte(Console->OutputCodePage, 0,
-
(PWCHAR)WriteConsoleOutputCharRequest->String,
- WriteConsoleOutputCharRequest->Length,
+
(PWCHAR)WriteConsoleOutputCodeRequest->pCode.UnicodeChar,
+ WriteConsoleOutputCodeRequest->Length,
NULL, 0, NULL, NULL);
tmpString = String = RtlAllocateHeap(GetProcessHeap(), 0, Length);
if (String)
{
WideCharToMultiByte(Console->OutputCodePage, 0,
- (PWCHAR)WriteConsoleOutputCharRequest->String,
- WriteConsoleOutputCharRequest->Length,
+
(PWCHAR)WriteConsoleOutputCodeRequest->pCode.UnicodeChar,
+ WriteConsoleOutputCodeRequest->Length,
String, Length, NULL, NULL);
}
else
{
Status = STATUS_NO_MEMORY;
}
- }
- else
- {
- String = (PCHAR)WriteConsoleOutputCharRequest->String;
- }
-
- if (String)
- {
- if (NT_SUCCESS(Status))
- {
- X = WriteConsoleOutputCharRequest->Coord.X;
- Y = (WriteConsoleOutputCharRequest->Coord.Y + Buff->VirtualY) %
Buff->MaxY;
- Length = WriteConsoleOutputCharRequest->Length;
- Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X)];
- while (Length--)
+
+ break;
+ }
+
+ case CODE_ASCII:
+ String = (PCHAR)WriteConsoleOutputCodeRequest->pCode.AsciiChar;
+ break;
+
+ case CODE_ATTRIBUTE:
+ default:
+ // *(ReadBuffer++) = Code;
+ String = (PCHAR)WriteConsoleOutputCodeRequest->pCode.Attribute;
+ break;
+ }
+
+ if (String && NT_SUCCESS(Status))
+ {
+ X = WriteConsoleOutputCodeRequest->Coord.X;
+ Y = (WriteConsoleOutputCodeRequest->Coord.Y + Buff->VirtualY) %
Buff->MaxY;
+ Length = WriteConsoleOutputCodeRequest->Length;
+ Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + (CodeType ==
CODE_ATTRIBUTE ? 1 : 0)];
+
+ while (Length--)
+ {
+ *Buffer = *String++;
+ // ReadBuffer = (PVOID)((ULONG_PTR)ReadBuffer + CodeSize);
+ String = (PCHAR)((ULONG_PTR)String + CodeSize);
+ // Written++;
+ Buffer += 2;
+ if (++X == Buff->MaxX)
+ {
+ if (++Y == Buff->MaxY)
{
- *Buffer = *String++;
- Written++;
- Buffer += 2;
- if (++X == Buff->MaxX)
- {
- if (++Y == Buff->MaxY)
- {
- Y = 0;
- Buffer = Buff->Buffer;
- }
- X = 0;
- }
+ Y = 0;
+ Buffer = Buff->Buffer + (CodeType == CODE_ATTRIBUTE ? 1 : 0);
}
- if (Buff == Console->ActiveBuffer)
- {
- ConioComputeUpdateRect(Buff, &UpdateRect,
&WriteConsoleOutputCharRequest->Coord,
- WriteConsoleOutputCharRequest->Length);
- ConioDrawRegion(Console, &UpdateRect);
- }
-
- WriteConsoleOutputCharRequest->EndCoord.X = X;
- WriteConsoleOutputCharRequest->EndCoord.Y = (Y + Buff->MaxY -
Buff->VirtualY) % Buff->MaxY;
-
- }
- if (WriteConsoleOutputCharRequest->Unicode)
- {
- RtlFreeHeap(GetProcessHeap(), 0, tmpString);
- }
- }
- ConioUnlockScreenBuffer(Buff);
- }
- WriteConsoleOutputCharRequest->NrCharactersWritten = Written;
+ X = 0;
+ }
+ }
+
+ if (Buff == Console->ActiveBuffer)
+ {
+ ConioComputeUpdateRect(Buff, &UpdateRect,
&WriteConsoleOutputCodeRequest->Coord,
+ WriteConsoleOutputCodeRequest->Length);
+ ConioDrawRegion(Console, &UpdateRect);
+ }
+
+ WriteConsoleOutputCodeRequest->EndCoord.X = X;
+ WriteConsoleOutputCodeRequest->EndCoord.Y = (Y + Buff->MaxY -
Buff->VirtualY) % Buff->MaxY;
+ }
+
+ if (tmpString)
+ {
+ RtlFreeHeap(GetProcessHeap(), 0, tmpString);
+ }
+
+ ConioUnlockScreenBuffer(Buff);
+
+ // WriteConsoleOutputCodeRequest->NrCharactersWritten = Written;
return Status;
-}
-
-CSR_API(CsrWriteConsoleOutputAttrib)
-{
- PCSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB WriteConsoleOutputAttribRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleOutputAttribRequest;
- PCSRSS_CONSOLE Console;
- PCSRSS_SCREEN_BUFFER Buff;
- PUCHAR Buffer;
- PWORD Attribute;
- int X, Y, Length;
- NTSTATUS Status;
- SMALL_RECT UpdateRect;
-
- DPRINT("CsrWriteConsoleOutputAttrib\n");
-
- if (ApiMessage->Header.u1.s1.TotalLength
- < CSR_API_MESSAGE_HEADER_SIZE(CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB)
- + WriteConsoleOutputAttribRequest->Length * sizeof(WORD))
- {
- DPRINT1("Invalid ApiMessage size\n");
- return STATUS_INVALID_PARAMETER;
- }
-
- Status = ConioLockScreenBuffer(CsrGetClientThread()->Process,
- WriteConsoleOutputAttribRequest->ConsoleHandle,
- &Buff,
- GENERIC_WRITE);
- if (! NT_SUCCESS(Status))
- {
- return Status;
- }
- Console = Buff->Header.Console;
-
- X = WriteConsoleOutputAttribRequest->Coord.X;
- Y = (WriteConsoleOutputAttribRequest->Coord.Y + Buff->VirtualY) %
Buff->MaxY;
- Length = WriteConsoleOutputAttribRequest->Length;
- Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + 1];
- Attribute = WriteConsoleOutputAttribRequest->Attribute;
- while (Length--)
- {
- *Buffer = (UCHAR)(*Attribute++);
- Buffer += 2;
- if (++X == Buff->MaxX)
- {
- if (++Y == Buff->MaxY)
- {
- Y = 0;
- Buffer = Buff->Buffer + 1;
- }
- X = 0;
- }
- }
-
- if (Buff == Console->ActiveBuffer)
- {
- ConioComputeUpdateRect(Buff, &UpdateRect,
&WriteConsoleOutputAttribRequest->Coord,
- WriteConsoleOutputAttribRequest->Length);
- ConioDrawRegion(Console, &UpdateRect);
- }
-
- WriteConsoleOutputAttribRequest->EndCoord.X = X;
- WriteConsoleOutputAttribRequest->EndCoord.Y = (Y + Buff->MaxY -
Buff->VirtualY) % Buff->MaxY;
-
- ConioUnlockScreenBuffer(Buff);
-
- return STATUS_SUCCESS;
}
CSR_API(SrvFillConsoleOutput)
@@ -1016,7 +990,7 @@
PCSRSS_FILL_OUTPUT FillOutputRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.FillOutputRequest;
PCSRSS_CONSOLE Console;
PCSRSS_SCREEN_BUFFER Buff;
- DWORD X, Y, Length, Start; // , Written = 0;
+ DWORD X, Y, Length; // , Written = 0;
USHORT CodeType;
BYTE Code;
PBYTE Buffer;
@@ -1034,8 +1008,7 @@
X = FillOutputRequest->Coord.X;
Y = (FillOutputRequest->Coord.Y + Buff->VirtualY) % Buff->MaxY;
Length = FillOutputRequest->Length;
- Start = 2 * (Y * Buff->MaxX + X) + (CodeType == CODE_ATTRIBUTE ? 1 : 0);
- Buffer = &Buff->Buffer[Start];
+ Buffer = &Buff->Buffer[2 * (Y * Buff->MaxX + X) + (CodeType ==
CODE_ATTRIBUTE ? 1 : 0)];
switch (CodeType)
{
@@ -1296,7 +1269,7 @@
PCSRSS_SCREEN_BUFFER_INFO ScreenBufferInfoRequest =
&((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ScreenBufferInfoRequest;
PCSRSS_CONSOLE Console;
PCSRSS_SCREEN_BUFFER Buff;
- PCONSOLE_SCREEN_BUFFER_INFO pInfo;
+ PCONSOLE_SCREEN_BUFFER_INFO pInfo = &ScreenBufferInfoRequest->Info;
DPRINT("SrvGetConsoleScreenBufferInfo\n");
@@ -1304,7 +1277,7 @@
if (!NT_SUCCESS(Status)) return Status;
Console = Buff->Header.Console;
- pInfo = &ScreenBufferInfoRequest->Info;
+
pInfo->dwSize.X = Buff->MaxX;
pInfo->dwSize.Y = Buff->MaxY;
pInfo->dwCursorPosition.X = Buff->CurrentX;
@@ -1316,6 +1289,7 @@
pInfo->srWindow.Bottom = Buff->ShowY + Console->Size.Y - 1;
pInfo->dwMaximumWindowSize.X = Buff->MaxX;
pInfo->dwMaximumWindowSize.Y = Buff->MaxY;
+
ConioUnlockScreenBuffer(Buff);
return STATUS_SUCCESS;