mirror of
https://github.com/reactos/reactos.git
synced 2025-06-12 11:48:31 +00:00
[KERNEL32]
Use new structures and api indices namings. [CONSRV] Use CsrValidateMessageBuffer instead of Win32CsrValidateBuffer. svn path=/branches/ros-csrss/; revision=57729
This commit is contained in:
parent
feb045c64b
commit
4b04f7d488
3 changed files with 87 additions and 57 deletions
|
@ -503,7 +503,8 @@ IntWriteConsoleInput(HANDLE hConsoleInput,
|
||||||
LPDWORD lpNumberOfEventsWritten,
|
LPDWORD lpNumberOfEventsWritten,
|
||||||
BOOL bUnicode)
|
BOOL bUnicode)
|
||||||
{
|
{
|
||||||
CSR_API_MESSAGE Request;
|
CONSOLE_API_MESSAGE ApiMessage;
|
||||||
|
PCSRSS_WRITE_CONSOLE_INPUT WriteConsoleInputRequest = &ApiMessage.Data.WriteConsoleInputRequest;
|
||||||
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
||||||
DWORD Size;
|
DWORD Size;
|
||||||
|
|
||||||
|
@ -515,8 +516,9 @@ IntWriteConsoleInput(HANDLE hConsoleInput,
|
||||||
|
|
||||||
Size = nLength * sizeof(INPUT_RECORD);
|
Size = nLength * sizeof(INPUT_RECORD);
|
||||||
|
|
||||||
/* Allocate a Capture Buffer */
|
|
||||||
DPRINT("IntWriteConsoleInput: %lx %p\n", Size, lpNumberOfEventsWritten);
|
DPRINT("IntWriteConsoleInput: %lx %p\n", Size, lpNumberOfEventsWritten);
|
||||||
|
|
||||||
|
/* Allocate a Capture Buffer */
|
||||||
CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
|
||||||
if (CaptureBuffer == NULL)
|
if (CaptureBuffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -525,43 +527,47 @@ IntWriteConsoleInput(HANDLE hConsoleInput,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate space in the Buffer */
|
/* Capture the user buffer */
|
||||||
CsrCaptureMessageBuffer(CaptureBuffer,
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
||||||
lpBuffer,
|
lpBuffer,
|
||||||
Size,
|
Size,
|
||||||
(PVOID*)&Request.Data.WriteConsoleInputRequest.InputRecord);
|
(PVOID*)&WriteConsoleInputRequest->InputRecord);
|
||||||
|
|
||||||
/* Set up the data to send to the Console Server */
|
/* Set up the data to send to the Console Server */
|
||||||
Request.Data.WriteConsoleInputRequest.ConsoleHandle = hConsoleInput;
|
WriteConsoleInputRequest->ConsoleHandle = hConsoleInput;
|
||||||
Request.Data.WriteConsoleInputRequest.Unicode = bUnicode;
|
WriteConsoleInputRequest->Unicode = bUnicode;
|
||||||
Request.Data.WriteConsoleInputRequest.Length = nLength;
|
WriteConsoleInputRequest->Length = nLength;
|
||||||
|
|
||||||
/* Call the server */
|
/* Call the server */
|
||||||
CsrClientCallServer(&Request,
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||||
CaptureBuffer,
|
CaptureBuffer,
|
||||||
CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_INPUT),
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleInput),
|
||||||
sizeof(CSR_API_MESSAGE));
|
sizeof(CSRSS_WRITE_CONSOLE_INPUT));
|
||||||
DPRINT("Server returned: %x\n", Request.Status);
|
DPRINT("Server returned: %x\n", ApiMessage.Status);
|
||||||
|
|
||||||
/* Check for success*/
|
/* Check for success*/
|
||||||
if (NT_SUCCESS(Request.Status))
|
if (NT_SUCCESS(ApiMessage.Status))
|
||||||
{
|
{
|
||||||
/* Return the number of events read */
|
/* Return the number of events read */
|
||||||
DPRINT("Events read: %lx\n", Request.Data.WriteConsoleInputRequest.Length);
|
DPRINT("Events read: %lx\n", WriteConsoleInputRequest->Length);
|
||||||
*lpNumberOfEventsWritten = Request.Data.WriteConsoleInputRequest.Length;
|
|
||||||
|
if (lpNumberOfEventsWritten != NULL)
|
||||||
|
*lpNumberOfEventsWritten = WriteConsoleInputRequest->Length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Error out */
|
if (lpNumberOfEventsWritten != NULL)
|
||||||
*lpNumberOfEventsWritten = 0;
|
*lpNumberOfEventsWritten = 0;
|
||||||
BaseSetLastNTError(Request.Status);
|
|
||||||
|
/* Error out */
|
||||||
|
BaseSetLastNTError(ApiMessage.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Release the capture buffer */
|
/* Release the capture buffer */
|
||||||
CsrFreeCaptureBuffer(CaptureBuffer);
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
||||||
|
|
||||||
/* Return TRUE or FALSE */
|
/* Return TRUE or FALSE */
|
||||||
return NT_SUCCESS(Request.Status);
|
return NT_SUCCESS(ApiMessage.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -574,14 +580,22 @@ IntWriteConsoleOutput(HANDLE hConsoleOutput,
|
||||||
PSMALL_RECT lpWriteRegion,
|
PSMALL_RECT lpWriteRegion,
|
||||||
BOOL bUnicode)
|
BOOL bUnicode)
|
||||||
{
|
{
|
||||||
CSR_API_MESSAGE Request;
|
CONSOLE_API_MESSAGE ApiMessage;
|
||||||
|
PCSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest = &ApiMessage.Data.WriteConsoleOutputRequest;
|
||||||
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
||||||
ULONG Size;
|
ULONG Size;
|
||||||
|
|
||||||
|
if ((lpBuffer == NULL) || (lpWriteRegion == NULL))
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
|
Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
|
||||||
|
|
||||||
/* Allocate a Capture Buffer */
|
|
||||||
DPRINT("IntWriteConsoleOutput: %lx %p\n", Size, lpWriteRegion);
|
DPRINT("IntWriteConsoleOutput: %lx %p\n", Size, lpWriteRegion);
|
||||||
|
|
||||||
|
/* Allocate a Capture Buffer */
|
||||||
CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, Size);
|
||||||
if (CaptureBuffer == NULL)
|
if (CaptureBuffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -590,45 +604,42 @@ IntWriteConsoleOutput(HANDLE hConsoleOutput,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate space in the Buffer */
|
/* Capture the user buffer */
|
||||||
CsrCaptureMessageBuffer(CaptureBuffer,
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
||||||
NULL,
|
(PVOID)lpBuffer,
|
||||||
Size,
|
Size,
|
||||||
(PVOID*)&Request.Data.WriteConsoleOutputRequest.CharInfo);
|
(PVOID*)&WriteConsoleOutputRequest->CharInfo);
|
||||||
|
|
||||||
/* Copy from the buffer */
|
|
||||||
RtlCopyMemory(Request.Data.WriteConsoleOutputRequest.CharInfo, lpBuffer, Size);
|
|
||||||
|
|
||||||
/* Set up the data to send to the Console Server */
|
/* Set up the data to send to the Console Server */
|
||||||
Request.Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
|
WriteConsoleOutputRequest->ConsoleHandle = hConsoleOutput;
|
||||||
Request.Data.WriteConsoleOutputRequest.Unicode = bUnicode;
|
WriteConsoleOutputRequest->Unicode = bUnicode;
|
||||||
Request.Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
|
WriteConsoleOutputRequest->BufferSize = dwBufferSize;
|
||||||
Request.Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
|
WriteConsoleOutputRequest->BufferCoord = dwBufferCoord;
|
||||||
Request.Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
|
WriteConsoleOutputRequest->WriteRegion = *lpWriteRegion;
|
||||||
|
|
||||||
/* Call the server */
|
/* Call the server */
|
||||||
CsrClientCallServer(&Request,
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||||
CaptureBuffer,
|
CaptureBuffer,
|
||||||
CSR_CREATE_API_NUMBER(CSR_CONSOLE, WRITE_CONSOLE_OUTPUT),
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepWriteConsoleOutput),
|
||||||
sizeof(CSR_API_MESSAGE));
|
sizeof(CSRSS_WRITE_CONSOLE_OUTPUT));
|
||||||
DPRINT("Server returned: %x\n", Request.Status);
|
DPRINT("Server returned: %x\n", ApiMessage.Status);
|
||||||
|
|
||||||
/* Check for success*/
|
/* Check for success*/
|
||||||
if (!NT_SUCCESS(Request.Status))
|
if (!NT_SUCCESS(ApiMessage.Status))
|
||||||
{
|
{
|
||||||
/* Error out */
|
/* Error out */
|
||||||
BaseSetLastNTError(Request.Status);
|
BaseSetLastNTError(ApiMessage.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the read region */
|
/* Return the read region */
|
||||||
DPRINT("read region: %lx\n", Request.Data.WriteConsoleOutputRequest.WriteRegion);
|
DPRINT("read region: %lx\n", WriteConsoleOutputRequest->WriteRegion);
|
||||||
*lpWriteRegion = Request.Data.WriteConsoleOutputRequest.WriteRegion;
|
*lpWriteRegion = WriteConsoleOutputRequest->WriteRegion;
|
||||||
|
|
||||||
/* Release the capture buffer */
|
/* Release the capture buffer */
|
||||||
CsrFreeCaptureBuffer(CaptureBuffer);
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
||||||
|
|
||||||
/* Return TRUE or FALSE */
|
/* Return TRUE or FALSE */
|
||||||
return NT_SUCCESS(Request.Status);
|
return NT_SUCCESS(ApiMessage.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -457,20 +457,27 @@ CSR_API(SrvWriteConsoleInput)
|
||||||
|
|
||||||
DPRINT("SrvWriteConsoleInput\n");
|
DPRINT("SrvWriteConsoleInput\n");
|
||||||
|
|
||||||
Status = ConioLockConsole(ProcessData, WriteConsoleInputRequest->ConsoleHandle, &Console, GENERIC_WRITE);
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
||||||
if (! NT_SUCCESS(Status))
|
(PVOID*)&WriteConsoleInputRequest->InputRecord,
|
||||||
|
WriteConsoleInputRequest->Length,
|
||||||
|
sizeof(INPUT_RECORD)))
|
||||||
{
|
{
|
||||||
return Status;
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status = ConioLockConsole(ProcessData, WriteConsoleInputRequest->ConsoleHandle, &Console, GENERIC_WRITE);
|
||||||
|
if (!NT_SUCCESS(Status)) return Status;
|
||||||
|
|
||||||
InputRecord = WriteConsoleInputRequest->InputRecord;
|
InputRecord = WriteConsoleInputRequest->InputRecord;
|
||||||
Length = WriteConsoleInputRequest->Length;
|
Length = WriteConsoleInputRequest->Length;
|
||||||
|
|
||||||
|
/*
|
||||||
if (!Win32CsrValidateBuffer(ProcessData->Process, InputRecord, Length, sizeof(INPUT_RECORD)))
|
if (!Win32CsrValidateBuffer(ProcessData->Process, InputRecord, Length, sizeof(INPUT_RECORD)))
|
||||||
{
|
{
|
||||||
ConioUnlockConsole(Console);
|
ConioUnlockConsole(Console);
|
||||||
return STATUS_ACCESS_VIOLATION;
|
return STATUS_ACCESS_VIOLATION;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for (i = 0; i < Length && NT_SUCCESS(Status); i++)
|
for (i = 0; i < Length && NT_SUCCESS(Status); i++)
|
||||||
{
|
{
|
||||||
|
@ -482,6 +489,7 @@ CSR_API(SrvWriteConsoleInput)
|
||||||
&InputRecord->Event.KeyEvent.uChar.UnicodeChar,
|
&InputRecord->Event.KeyEvent.uChar.UnicodeChar,
|
||||||
&AsciiChar);
|
&AsciiChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ConioProcessChar(Console, InputRecord++);
|
Status = ConioProcessChar(Console, InputRecord++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -453,11 +453,6 @@ CSR_API(SrvReadConsoleOutput)
|
||||||
|
|
||||||
DPRINT("SrvReadConsoleOutput\n");
|
DPRINT("SrvReadConsoleOutput\n");
|
||||||
|
|
||||||
CharInfo = ReadConsoleOutputRequest->CharInfo;
|
|
||||||
ReadRegion = ReadConsoleOutputRequest->ReadRegion;
|
|
||||||
BufferSize = ReadConsoleOutputRequest->BufferSize;
|
|
||||||
BufferCoord = ReadConsoleOutputRequest->BufferCoord;
|
|
||||||
|
|
||||||
if (!CsrValidateMessageBuffer(ApiMessage,
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
||||||
(PVOID*)&ReadConsoleOutputRequest->CharInfo,
|
(PVOID*)&ReadConsoleOutputRequest->CharInfo,
|
||||||
BufferSize.X * BufferSize.Y,
|
BufferSize.X * BufferSize.Y,
|
||||||
|
@ -465,6 +460,15 @@ CSR_API(SrvReadConsoleOutput)
|
||||||
{
|
{
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
if (!Win32CsrValidateBuffer(ProcessData->Process, CharInfo,
|
||||||
BufferSize.X * BufferSize.Y, sizeof(CHAR_INFO)))
|
BufferSize.X * BufferSize.Y, sizeof(CHAR_INFO)))
|
||||||
|
@ -474,9 +478,6 @@ CSR_API(SrvReadConsoleOutput)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Status = ConioLockScreenBuffer(ProcessData, ReadConsoleOutputRequest->ConsoleHandle, &Buff, GENERIC_READ);
|
|
||||||
if (!NT_SUCCESS(Status)) return Status;
|
|
||||||
|
|
||||||
/* FIXME: Is this correct? */
|
/* FIXME: Is this correct? */
|
||||||
CodePage = ProcessData->Console->OutputCodePage;
|
CodePage = ProcessData->Console->OutputCodePage;
|
||||||
|
|
||||||
|
@ -613,8 +614,8 @@ CSR_API(SrvWriteConsole)
|
||||||
CSR_API(SrvWriteConsoleOutput)
|
CSR_API(SrvWriteConsoleOutput)
|
||||||
{
|
{
|
||||||
PCSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleOutputRequest;
|
PCSRSS_WRITE_CONSOLE_OUTPUT WriteConsoleOutputRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.WriteConsoleOutputRequest;
|
||||||
|
PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
|
||||||
SHORT i, X, Y, SizeX, SizeY;
|
SHORT i, X, Y, SizeX, SizeY;
|
||||||
PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
|
|
||||||
PCSRSS_CONSOLE Console;
|
PCSRSS_CONSOLE Console;
|
||||||
PCSRSS_SCREEN_BUFFER Buff;
|
PCSRSS_SCREEN_BUFFER Buff;
|
||||||
SMALL_RECT ScreenBuffer;
|
SMALL_RECT ScreenBuffer;
|
||||||
|
@ -628,25 +629,35 @@ CSR_API(SrvWriteConsoleOutput)
|
||||||
|
|
||||||
DPRINT("SrvWriteConsoleOutput\n");
|
DPRINT("SrvWriteConsoleOutput\n");
|
||||||
|
|
||||||
|
if (!CsrValidateMessageBuffer(ApiMessage,
|
||||||
|
(PVOID*)&WriteConsoleOutputRequest->CharInfo,
|
||||||
|
BufferSize.X * BufferSize.Y,
|
||||||
|
sizeof(CHAR_INFO)))
|
||||||
|
{
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
Status = ConioLockScreenBuffer(ProcessData,
|
Status = ConioLockScreenBuffer(ProcessData,
|
||||||
WriteConsoleOutputRequest->ConsoleHandle,
|
WriteConsoleOutputRequest->ConsoleHandle,
|
||||||
&Buff,
|
&Buff,
|
||||||
GENERIC_WRITE);
|
GENERIC_WRITE);
|
||||||
if (! NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status)) return Status;
|
||||||
{
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
Console = Buff->Header.Console;
|
Console = Buff->Header.Console;
|
||||||
|
|
||||||
BufferSize = WriteConsoleOutputRequest->BufferSize;
|
BufferSize = WriteConsoleOutputRequest->BufferSize;
|
||||||
BufferCoord = WriteConsoleOutputRequest->BufferCoord;
|
BufferCoord = WriteConsoleOutputRequest->BufferCoord;
|
||||||
CharInfo = WriteConsoleOutputRequest->CharInfo;
|
CharInfo = WriteConsoleOutputRequest->CharInfo;
|
||||||
if (!Win32CsrValidateBuffer(ProcessData, CharInfo,
|
|
||||||
|
/*
|
||||||
|
if (!Win32CsrValidateBuffer(ProcessData->Process, CharInfo,
|
||||||
BufferSize.X * BufferSize.Y, sizeof(CHAR_INFO)))
|
BufferSize.X * BufferSize.Y, sizeof(CHAR_INFO)))
|
||||||
{
|
{
|
||||||
ConioUnlockScreenBuffer(Buff);
|
ConioUnlockScreenBuffer(Buff);
|
||||||
return STATUS_ACCESS_VIOLATION;
|
return STATUS_ACCESS_VIOLATION;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
WriteRegion = WriteConsoleOutputRequest->WriteRegion;
|
WriteRegion = WriteConsoleOutputRequest->WriteRegion;
|
||||||
|
|
||||||
SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&WriteRegion));
|
SizeY = min(BufferSize.Y - BufferCoord.Y, ConioRectHeight(&WriteRegion));
|
||||||
|
@ -656,7 +667,7 @@ CSR_API(SrvWriteConsoleOutput)
|
||||||
|
|
||||||
/* Make sure WriteRegion is inside the screen buffer */
|
/* Make sure WriteRegion is inside the screen buffer */
|
||||||
ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1);
|
ConioInitRect(&ScreenBuffer, 0, 0, Buff->MaxY - 1, Buff->MaxX - 1);
|
||||||
if (! ConioGetIntersection(&WriteRegion, &ScreenBuffer, &WriteRegion))
|
if (!ConioGetIntersection(&WriteRegion, &ScreenBuffer, &WriteRegion))
|
||||||
{
|
{
|
||||||
ConioUnlockScreenBuffer(Buff);
|
ConioUnlockScreenBuffer(Buff);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue