22#define ConioRectHeight(Rect) \
23 (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
24#define ConioRectWidth(Rect) \
25 (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
47 ULONG CharSize, SizeBytes;
49 DPRINT(
"IntReadConsole\n");
54 ReadConsoleRequest->
Unicode = bUnicode;
69 DPRINT(
"IntReadConsole(ExeName = %wZ)\n", &ExeName);
74 CharSize = (bUnicode ?
sizeof(
WCHAR) :
sizeof(
CHAR));
78 ReadConsoleRequest->
NumBytes = SizeBytes;
86 if (SizeBytes <=
sizeof(ReadConsoleRequest->
StaticBuffer))
95 if (CaptureBuffer ==
NULL)
97 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
180 sizeof(*ReadConsoleRequest));
190 *lpNumberOfCharsRead = ReadConsoleRequest->
NumBytes / CharSize;
196 ReadConsoleRequest->
Buffer,
266 GetInputRequest->
Unicode = bUnicode;
285 if (CaptureBuffer ==
NULL)
287 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
302 sizeof(*GetInputRequest));
359 ReadOutputRequest->
Unicode = bUnicode;
366 if (SizeX <= 0 || SizeY <= 0)
371 lpReadRegion->Right = lpReadRegion->Left + SizeX - 1;
372 lpReadRegion->Bottom = lpReadRegion->Top + SizeY - 1;
374 ReadOutputRequest->
ReadRegion = *lpReadRegion;
383 NumCells = SizeX * SizeY;
384 DPRINT(
"IntReadConsoleOutput: (%d x %d)\n", SizeX, SizeY);
403 if (CaptureBuffer ==
NULL)
405 DPRINT1(
"CsrAllocateCaptureBuffer failed with size %ld!\n",
Size);
420 sizeof(*ReadOutputRequest));
428 *lpReadRegion = ReadOutputRequest->
ReadRegion;
441 for (
y = 0,
Y = ReadOutputRequest->
ReadRegion.
Top; Y <= ReadOutputRequest->ReadRegion.Bottom; ++
y, ++
Y)
447 for (
x = 0,
X = ReadOutputRequest->
ReadRegion.
Left; X <= ReadOutputRequest->ReadRegion.Right; ++
x, ++
X)
449 *(
lpBuffer + (
y + dwBufferCoord.Y) * dwBufferSize.X + (
x + dwBufferCoord.X)) =
450 *(ReadOutputRequest->
CharInfo +
y * SizeX +
x);
488 ULONG CodeSize, SizeBytes;
490 DPRINT(
"IntReadConsoleOutputCode\n");
503 ReadOutputCodeRequest->
Coord = dwReadCoord;
507 ReadOutputCodeRequest->
CodeType = CodeType;
522 SizeBytes =
nLength * CodeSize;
539 if (CaptureBuffer ==
NULL)
541 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
556 sizeof(*ReadOutputCodeRequest));
564 *lpNumberOfCodesRead = ReadOutputCodeRequest->
NumCodes;
569 ReadOutputCodeRequest->
pCode,
570 ReadOutputCodeRequest->
NumCodes * CodeSize);
600 IN DWORD nNumberOfCharsToWrite,
609 ULONG CharSize, SizeBytes;
611 DPRINT(
"IntWriteConsole\n");
616 WriteConsoleRequest->
Unicode = bUnicode;
623 CharSize = (bUnicode ?
sizeof(
WCHAR) :
sizeof(
CHAR));
624 SizeBytes = nNumberOfCharsToWrite * CharSize;
626 WriteConsoleRequest->
NumBytes = SizeBytes;
634 if (SizeBytes <=
sizeof(WriteConsoleRequest->
StaticBuffer))
657 if (CaptureBuffer ==
NULL)
659 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
676 sizeof(*WriteConsoleRequest));
685 if (
Success && lpNumberOfCharsWritten)
689 *lpNumberOfCharsWritten = WriteConsoleRequest->
NumBytes / CharSize;
722 DPRINT(
"IntWriteConsoleInput: %lx %p\n",
nLength, lpNumberOfEventsWritten);
728 WriteInputRequest->
Unicode = bUnicode;
761 if (CaptureBuffer ==
NULL)
763 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
779 sizeof(*WriteInputRequest));
791 *lpNumberOfEventsWritten = WriteInputRequest->
NumRecords;
828 WriteOutputRequest->
Unicode = bUnicode;
835 if (SizeX <= 0 || SizeY <= 0)
840 lpWriteRegion->Right = lpWriteRegion->Left + SizeX - 1;
841 lpWriteRegion->Bottom = lpWriteRegion->Top + SizeY - 1;
852 NumCells = SizeX * SizeY;
853 DPRINT(
"IntWriteConsoleOutput: (%d x %d)\n", SizeX, SizeY);
890 DPRINT1(
"CsrAllocateCaptureBuffer failed with size %ld, let's use local heap buffer...\n",
Size);
898 DPRINT1(
"Failed to allocate heap buffer with size %ld!\n",
Size);
917 for (
y = 0,
Y = WriteOutputRequest->
WriteRegion.
Top; Y <= WriteOutputRequest->WriteRegion.Bottom; ++
y, ++
Y)
920 lpBuffer + (
y + dwBufferCoord.Y) * dwBufferSize.X + dwBufferCoord.X,
923 for (
x = 0,
X = WriteOutputRequest->
WriteRegion.
Left; X <= WriteOutputRequest->WriteRegion.Right; ++
x, ++
X)
925 *(WriteOutputRequest->
CharInfo +
y * SizeX +
x) =
926 *(
lpBuffer + (
y + dwBufferCoord.Y) * dwBufferSize.X + (
x + dwBufferCoord.X));
942 sizeof(*WriteOutputRequest));
992 ULONG CodeSize, SizeBytes;
1002 DPRINT(
"IntWriteConsoleOutputCode\n");
1007 WriteOutputCodeRequest->
Coord = dwWriteCoord;
1011 WriteOutputCodeRequest->
CodeType = CodeType;
1026 SizeBytes =
nLength * CodeSize;
1056 if (CaptureBuffer ==
NULL)
1058 DPRINT1(
"CsrAllocateCaptureBuffer failed!\n");
1074 sizeof(*WriteOutputCodeRequest));
1085 *lpNumberOfCodesWritten = WriteOutputCodeRequest->
NumCodes;
1115 DPRINT(
"IntFillConsoleOutputCode\n");
1128 FillOutputRequest->
WriteCoord = dwWriteCoord;
1129 FillOutputRequest->
CodeType = CodeType;
1137 sizeof(*FillOutputRequest));
1145 *lpNumberOfCodesWritten = FillOutputRequest->
NumCodes;
1183 lpNumberOfCharsRead,
1204 lpNumberOfCharsRead,
1391 lpNumberOfCharsRead);
1412 lpNumberOfCharsRead);
1433 lpNumberOfAttrsRead);
1449 IN DWORD nNumberOfCharsToWrite,
1455 nNumberOfCharsToWrite,
1456 lpNumberOfCharsWritten,
1470 IN DWORD nNumberOfCharsToWrite,
1476 nNumberOfCharsToWrite,
1477 lpNumberOfCharsWritten,
1497 lpNumberOfEventsWritten,
1517 lpNumberOfEventsWritten,
1537 lpNumberOfEventsWritten,
1557 lpNumberOfEventsWritten,
1622 lpNumberOfCharsWritten);
1643 lpNumberOfCharsWritten);
1664 lpNumberOfAttrsWritten);
1681 Code.UnicodeChar = cCharacter;
1687 lpNumberOfCharsWritten);
1701 LPDWORD lpNumberOfCharsWritten)
1704 Code.AsciiChar = cCharacter;
1710 lpNumberOfCharsWritten);
1727 Code.Attribute = wAttribute;
1733 lpNumberOfAttrsWritten);
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
enum _CODE_TYPE CODE_TYPE
@ ConsolepReadConsoleOutputString
@ ConsolepGetConsoleInput
@ ConsolepWriteConsoleInput
@ ConsolepWriteConsoleOutput
@ ConsolepReadConsoleOutput
@ ConsolepWriteConsoleOutputString
@ ConsolepFillConsoleOutput
#define CONSRV_SERVERDLL_INDEX
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
#define ERROR_NOT_ENOUGH_MEMORY
#define NT_SUCCESS(StatCode)
#define ERROR_INVALID_PARAMETER
#define ERROR_INVALID_HANDLE
USHORT GetCurrentExeName(OUT PWCHAR ExeName, IN USHORT BufferSize)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleInputExW(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead, IN WORD wFlags)
static BOOL IntWriteConsole(IN HANDLE hConsoleOutput, IN PVOID lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved, IN BOOLEAN bUnicode)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputAttribute(IN HANDLE hConsoleOutput, OUT LPWORD lpAttribute, IN DWORD nLength, IN COORD dwReadCoord, OUT LPDWORD lpNumberOfAttrsRead)
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterA(IN HANDLE hConsoleOutput, IN CHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten)
#define ConioRectWidth(Rect)
static BOOL IntWriteConsoleOutput(IN HANDLE hConsoleOutput, IN CONST CHAR_INFO *lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpWriteRegion, IN BOOLEAN bUnicode)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputCharacterW(IN HANDLE hConsoleOutput, OUT LPWSTR lpCharacter, IN DWORD nLength, IN COORD dwReadCoord, OUT LPDWORD lpNumberOfCharsRead)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleInputW(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleW(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleInputExA(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead, IN WORD wFlags)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleInputA(IN HANDLE hConsoleInput, IN CONST INPUT_RECORD *lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
static BOOL IntGetConsoleInput(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead, IN WORD wFlags, IN BOOLEAN bUnicode)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleInputW(IN HANDLE hConsoleInput, IN CONST INPUT_RECORD *lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsWritten)
static BOOL IntReadConsoleOutputCode(IN HANDLE hConsoleOutput, IN CODE_TYPE CodeType, OUT PVOID pCode, IN DWORD nLength, IN COORD dwReadCoord, OUT LPDWORD lpNumberOfCodesRead)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputA(IN HANDLE hConsoleOutput, OUT PCHAR_INFO lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpReadRegion)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleInputVDMW(IN HANDLE hConsoleInput, IN CONST INPUT_RECORD *lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsWritten)
static BOOL IntReadConsole(IN HANDLE hConsoleInput, OUT PVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL, IN BOOLEAN bUnicode)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN LPCWSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputCharacterA(IN HANDLE hConsoleOutput, IN LPCSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleInputVDMA(IN HANDLE hConsoleInput, IN CONST INPUT_RECORD *lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleW(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
static BOOL IntFillConsoleOutputCode(IN HANDLE hConsoleOutput, IN CODE_TYPE CodeType, IN CODE_ELEMENT Code, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCodesWritten)
#define ConioRectHeight(Rect)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleInputA(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
static BOOL IntWriteConsoleOutputCode(IN HANDLE hConsoleOutput, IN CODE_TYPE CodeType, IN CONST VOID *pCode, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCodesWritten)
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputW(IN HANDLE hConsoleOutput, IN CONST CHAR_INFO *lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpWriteRegion)
BOOL WINAPI DECLSPEC_HOTPATCH PeekConsoleInputA(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputW(IN HANDLE hConsoleOutput, OUT PCHAR_INFO lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpReadRegion)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN CONST WORD *lpAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputA(IN HANDLE hConsoleOutput, IN CONST CHAR_INFO *lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpWriteRegion)
BOOL WINAPI DECLSPEC_HOTPATCH PeekConsoleInputW(IN HANDLE hConsoleInput, OUT PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsRead)
static BOOL IntWriteConsoleInput(IN HANDLE hConsoleInput, IN PINPUT_RECORD lpBuffer, IN DWORD nLength, OUT LPDWORD lpNumberOfEventsWritten, IN BOOLEAN bUnicode, IN BOOLEAN bAppendToEnd)
static BOOL IntReadConsoleOutput(IN HANDLE hConsoleOutput, OUT PCHAR_INFO lpBuffer, IN COORD dwBufferSize, IN COORD dwBufferCoord, IN OUT PSMALL_RECT lpReadRegion, IN BOOLEAN bUnicode)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleA(IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN PCONSOLE_READCONSOLE_CONTROL pInputControl OPTIONAL)
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputCharacterA(IN HANDLE hConsoleOutput, OUT LPSTR lpCharacter, IN DWORD nLength, IN COORD dwReadCoord, OUT LPDWORD lpNumberOfCharsRead)
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
NTSYSAPI NTSTATUS WINAPI NtYieldExecution(void)
#define EXCEPTION_EXECUTE_HANDLER
#define RTL_FIELD_SIZE(type, field)
#define _SEH2_EXCEPT(...)
#define _SEH2_YIELD(__stmt)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(_In_ ULONG ArgumentCount, _In_ ULONG BufferSize)
ULONG NTAPI CsrAllocateMessagePointer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
VOID NTAPI CsrFreeCaptureBuffer(_In_ _Frees_ptr_ PCSR_CAPTURE_BUFFER CaptureBuffer)
VOID NTAPI CsrCaptureMessageBuffer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PVOID MessageBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
#define IsConsoleHandle(h)
#define DECLSPEC_HOTPATCH
PULONG MinorVersion OPTIONAL
CONSOLE_READOUTPUT ReadOutputRequest
CONSOLE_FILLOUTPUTCODE FillOutputRequest
union _CONSOLE_API_MESSAGE::@3541 Data
CONSOLE_WRITEOUTPUTCODE WriteOutputCodeRequest
CONSOLE_WRITECONSOLE WriteConsoleRequest
CONSOLE_WRITEOUTPUT WriteOutputRequest
CONSOLE_READOUTPUTCODE ReadOutputCodeRequest
CONSOLE_READCONSOLE ReadConsoleRequest
CONSOLE_GETINPUT GetInputRequest
CONSOLE_WRITEINPUT WriteInputRequest
CHAR CodeStaticBuffer[80]
BOOLEAN UsingStaticBuffer
#define RtlCopyMemory(Destination, Source, Length)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
struct _CHAR_INFO CHAR_INFO
_In_ DWORD _Out_ LPDWORD lpNumberOfEventsRead
_In_ DWORD nNumberOfCharsToRead
struct _INPUT_RECORD INPUT_RECORD
_In_ DWORD _Out_ _In_ WORD wFlags
#define CONSOLE_READ_NOREMOVE
#define CONSOLE_READ_NOWAIT
_In_ DWORD _Out_ _In_opt_ PCONSOLE_READCONSOLE_CONTROL pInputControl
#define ERROR_INVALID_ACCESS
#define ERROR_OPERATION_ABORTED