test: client/stream.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# stream.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Functions

HANDLE APIENTRY | GetConsoleInputWaitHandle (VOID)
HANDLE APIENTRY | OpenConsoleWInternal (IN ULONG HandleType, IN ULONG DesiredAccess, IN BOOL InheritHandle, IN ULONG ShareMode)
| defined(BUILD_WOW64)
HANDLE APIENTRY | OpenConsoleW (IN LPWSTR lpConsoleDevice, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwShareMode)
BOOL APIENTRY | ReadConsoleInternal (IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN OUT LPVOID lpReserved, IN BOOLEAN Unicode, IN USHORT ExeNameLength, IN LPWSTR ExeName)
BOOL APIENTRY | ReadConsoleA (IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN OUT LPVOID lpReserved)
| defined(BUILD_WOW6432)
BOOL APIENTRY | ReadConsoleW (IN HANDLE hConsoleInput, OUT LPVOID lpBuffer, IN DWORD nNumberOfCharsToRead, OUT LPDWORD lpNumberOfCharsRead, IN OUT LPVOID lpReserved)
BOOL APIENTRY | WriteConsoleInternal (IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
BOOL APIENTRY | WriteConsoleA (IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, IN OUT LPVOID lpReserved)
| defined(BUILD_WOW6432)
BOOL APIENTRY | WriteConsoleW (IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, IN OUT LPVOID lpReserved)
BOOL APIENTRY | CloseConsoleHandle (IN HANDLE hConsole)
| defined(BUILD_WOW64)
HANDLE APIENTRY | DuplicateConsoleHandle (IN HANDLE hSourceHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
BOOL APIENTRY | GetConsoleHandleInformation (IN HANDLE hObject, OUT LPDWORD lpdwFlags)
BOOL APIENTRY | SetConsoleHandleInformation (IN HANDLE hObject, IN DWORD dwMask, IN DWORD dwFlags)
BOOL APIENTRY | VerifyConsoleIoHandle (IN HANDLE hIoHandle)

## Variables

HANDLE | InputWaitHandle = (HANDLE)-1

## Function Documentation

BOOL APIENTRY CloseConsoleHandle | ( | IN HANDLE | hConsole | ) |

defined(BUILD_WOW64)

Definition at line 553 of file client/stream.c.

References _CONSOLE_CLOSEHANDLE_MSG::ConsoleHandle, ConsolepCloseHandle, CsrClientCallServer(), FALSE, GET_CONSOLE_HANDLE, _CONSOLE_CLOSEHANDLE_MSG::Handle, NT_SUCCESS, NULL, PCONSOLE_CLOSEHANDLE_MSG, SET_LAST_NT_ERROR, TRUE, and _CONSOLE_API_MSG::u.

    00559           :
    00560
    00561     hConsole - An open handle to console input or output.
    00562
    00563 Return Value:
    00564
    00565     TRUE - The operation was successful.
    00566
    00567     FALSE/NULL - The operation failed. Extended error status is available
    00568         using GetLastError.
    00569
    00570 --*/
    00571
    00572 {
    00573
    00574     CONSOLE_API_MSG m;
    00575     PCONSOLE_CLOSEHANDLE_MSG a = &m.u.CloseHandle;
    00576
    00577     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00578     a->Handle = hConsole;
    00579     CsrClientCallServer( (PCSR_API_MSG)&m,
    00580                          NULL,
    00581                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00582                                               ConsolepCloseHandle
    00583                                             ),
    00584                          sizeof( *a )
    00585                        );
    00586     if (NT_SUCCESS( m.ReturnValue )) {
    00587         return TRUE;
    00588     } else {
    00589         SET_LAST_NT_ERROR (m.ReturnValue);
    00590         return FALSE;
    00591     }
    00592
    00593 }

HANDLE APIENTRY DuplicateConsoleHandle | ( | IN HANDLE | hSourceHandle,
|  | IN DWORD | dwDesiredAccess,
|  | IN BOOL | bInheritHandle,
|  | IN DWORD | dwOptions
| ) |

Definition at line 597 of file client/stream.c.

References _CONSOLE_DUPHANDLE_MSG::ConsoleHandle, ConsolepDupHandle, CsrClientCallServer(), _CONSOLE_DUPHANDLE_MSG::DesiredAccess, GET_CONSOLE_HANDLE, _CONSOLE_DUPHANDLE_MSG::InheritHandle, INVALID_HANDLE_VALUE, NT_SUCCESS, NULL, _CONSOLE_DUPHANDLE_MSG::Options, PCONSOLE_DUPHANDLE_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_DUPHANDLE_MSG::SourceHandle, _CONSOLE_API_MSG::u, VALID_ACCESSES, and VALID_DUP_OPTIONS.

    00604           :
    00605
    00606     hSourceHandle - An open handle to the console device.
    00607
    00608     dwDesiredAccess - The access requested to for the new handle.  This
    00609         access must be equal to or a proper subset of the granted access
    00610         associated with the SourceHandle.  This parameter is ignored if
    00611         the DUPLICATE_SAME_ACCESS option is specified.
    00612
    00613     bInheritHandle - Supplies a flag that if TRUE, marks the target
    00614         handle as inheritable.  If this is the case, then the target
    00615         handle will be inherited to new processes each time the target
    00616         process creates a new process using CreateProcess.
    00617
    00618     dwOptions - Specifies optional behaviors for the caller.
    00619
    00620         Options Flags:
    00621
    00622         DUPLICATE_CLOSE_SOURCE - The SourceHandle will be closed by
    00623             this service prior to returning to the caller.  This occurs
    00624             regardless of any error status returned.
    00625
    00626         DUPLICATE_SAME_ACCESS - The DesiredAccess parameter is ignored
    00627             and instead the GrantedAccess associated with SourceHandle
    00628             is used as the DesiredAccess when creating the TargetHandle.
    00629
    00630
    00631 Return Value:
    00632
    00633     Not -1 - Returns an open handle to the specified console device.
    00634         Subsequent access to the file is controlled by the DesiredAccess
    00635         parameter.
    00636
    00637     0xffffffff - The operation failed. Extended error status is available
    00638         using GetLastError.
    00639 --*/
    00640
    00641 {
    00642
    00643     CONSOLE_API_MSG m;
    00644     PCONSOLE_DUPHANDLE_MSG a = &m.u.DuplicateHandle;
    00645
    00646     if (dwOptions & ~VALID_DUP_OPTIONS) {
    00647         SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    00648         return (HANDLE) INVALID_HANDLE_VALUE;
    00649     }
    00650     if (((dwOptions & DUPLICATE_SAME_ACCESS) == 0) &&
    00651          (dwDesiredAccess & ~VALID_ACCESSES)) {
    00652         SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    00653         return (HANDLE) INVALID_HANDLE_VALUE;
    00654     }
    00655
    00656     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00657     a->SourceHandle = hSourceHandle;
    00658     a->DesiredAccess = dwDesiredAccess;
    00659     a->InheritHandle = (BOOLEAN) bInheritHandle;
    00660     a->Options = dwOptions;
    00661     CsrClientCallServer( (PCSR_API_MSG)&m,
    00662                          NULL,
    00663                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00664                                               ConsolepDupHandle
    00665                                             ),
    00666                          sizeof( *a )
    00667                        );
    00668     if (NT_SUCCESS( m.ReturnValue )) {
    00669         return a->TargetHandle;
    00670     } else {
    00671         SET_LAST_NT_ERROR (m.ReturnValue);
    00672         return (HANDLE) INVALID_HANDLE_VALUE;
    00673     }
    00674
    00675 }

BOOL APIENTRY GetConsoleHandleInformation | ( | IN HANDLE | hObject,
|  | OUT LPDWORD | lpdwFlags
| ) |

Definition at line 680 of file client/stream.c.

References _CONSOLE_GETHANDLEINFORMATION_MSG::ConsoleHandle, ConsolepGetHandleInformation, CsrClientCallServer(), EXCEPTION_EXECUTE_HANDLER, FALSE, GET_CONSOLE_HANDLE, _CONSOLE_GETHANDLEINFORMATION_MSG::Handle, NT_SUCCESS, NULL, PCONSOLE_GETHANDLEINFORMATION_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, TRUE, and _CONSOLE_API_MSG::u.

    00686           :
    00687
    00688     hObject - An open handle to console input or output.
    00689
    00690     lpdwFlags - Receives flags for console object.
    00691
    00692 Return Value:
    00693
    00694     TRUE - The operation was successful.
    00695
    00696     FALSE/NULL - The operation failed. Extended error status is available
    00697         using GetLastError.
    00698
    00699 --*/
    00700
    00701 {
    00702
    00703     CONSOLE_API_MSG m;
    00704     PCONSOLE_GETHANDLEINFORMATION_MSG a = &m.u.GetHandleInformation;
    00705
    00706     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00707     a->Handle = hObject;
    00708
    00709     CsrClientCallServer( (PCSR_API_MSG)&m,
    00710                          NULL,
    00711                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00712                                               ConsolepGetHandleInformation
    00713                                             ),
    00714                          sizeof( *a )
    00715                        );
    00716     if (NT_SUCCESS( m.ReturnValue )) {
    00717         try {
    00718            *lpdwFlags = a->Flags;
    00719         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00720             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00721             return FALSE;
    00722         }
    00723         return TRUE;
    00724     } else {
    00725         SET_LAST_NT_ERROR (m.ReturnValue);
    00726         return FALSE;
    00727     }
    00728
    00729 }

HANDLE APIENTRY GetConsoleInputWaitHandle | ( | VOID |  | ) |

Definition at line 33 of file client/stream.c.

References InputWaitHandle.

    00034 {
    00035     return InputWaitHandle;
    00036 }

HANDLE APIENTRY OpenConsoleW | ( | IN LPWSTR | lpConsoleDevice,
|  | IN DWORD | dwDesiredAccess,
|  | IN BOOL | bInheritHandle,
|  | IN DWORD | dwShareMode
| ) |

Definition at line 98 of file client/stream.c.

References CONSOLE_INPUT_HANDLE, CONSOLE_OUTPUT_HANDLE, EXCEPTION_EXECUTE_HANDLER, INVALID_HANDLE_VALUE, OpenConsoleWInternal(), SET_LAST_ERROR, VALID_ACCESSES, and VALID_SHARE_ACCESSES.

    00107           :
    00108
    00109     lpConsoleDevice - Supplies the console device name to open.  "CONIN$"
    00110         indicates console input.  "CONOUT$" indicates console output.  The
    00111         caller must have appropriate access to the console for this call to
    00112         succeed.
    00113
    00114     dwDesiredAccess - Supplies the caller's desired access to the console
    00115         device.
    00116
    00117         DesiredAccess Flags:
    00118
    00119         GENERIC_READ - Read access to the console device is requested.  This
    00120             allows data to be read from the console device.
    00121
    00122         GENERIC_WRITE - Write access to the console device is requested.  This
    00123             allows data to be written to the console device.
    00124
    00125     bInheritHandle - Supplies a flag that indicates whether or not the
    00126         returned handle is to be inherited by a new process
    00127         during a CreateProcess.  A value of TRUE indicates that the
    00128         new process will inherit the handle.
    00129
    00130     dwShareMode - Supplies a set of flags that indicates how this console
    00131         device is to be shared with other openers of the console device.  A
    00132         value of zero for this parameter indicates no sharing of the console,
    00133         or exclusive access to the console is to occur.
    00134
    00135         ShareMode Flags:
    00136
    00137         FILE_SHARE_READ - Other open operations may be performed on the
    00138             console device for read access.
    00139
    00140         FILE_SHARE_WRITE - Other open operations may be performed on the
    00141             console device for write access.
    00142
    00143 Return Value:
    00144
    00145     Not -1 - Returns an open handle to the specified console device.
    00146         Subsequent access to the file is controlled by the DesiredAccess
    00147         parameter.
    00148
    00149     0xffffffff - The operation failed. Extended error status is available
    00150         using GetLastError.
    00151 --*/
    00152
    00153 {
    00154     ULONG HandleType;
    00155
    00156     try {
    00157         if (!lstrcmpiW(CONSOLE_INPUT_STRING,lpConsoleDevice)) {
    00158             HandleType = CONSOLE_INPUT_HANDLE;
    00159         }
    00160         else if (!lstrcmpiW(CONSOLE_OUTPUT_STRING,lpConsoleDevice)) {
    00161             HandleType = CONSOLE_OUTPUT_HANDLE;
    00162         }
    00163         else {
    00164             SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    00165             return (HANDLE) INVALID_HANDLE_VALUE;
    00166         }
    00167     } except( EXCEPTION_EXECUTE_HANDLER ) {
    00168         SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00169         return (HANDLE) INVALID_HANDLE_VALUE;
    00170     }
    00171     if (dwDesiredAccess & ~VALID_ACCESSES ||
    00172         dwShareMode & ~VALID_SHARE_ACCESSES) {
    00173         SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    00174         return (HANDLE) INVALID_HANDLE_VALUE;
    00175     }
    00176
    00177     return OpenConsoleWInternal(HandleType,
    00178                                 dwDesiredAccess,
    00179                                 bInheritHandle,
    00180                                 dwShareMode
    00181                                 );
    00182
    00183 }

HANDLE APIENTRY OpenConsoleWInternal | ( | IN ULONG | HandleType,
|  | IN ULONG | DesiredAccess,
|  | IN BOOL | InheritHandle,
|  | IN ULONG | ShareMode
| ) |

defined(BUILD_WOW64)

Definition at line 44 of file client/stream.c.

References _CONSOLE_OPENCONSOLE_MSG::ConsoleHandle, ConsolepOpenConsole, CsrClientCallServer(), _CONSOLE_OPENCONSOLE_MSG::DesiredAccess, GET_CONSOLE_HANDLE, _CONSOLE_OPENCONSOLE_MSG::HandleType, _CONSOLE_OPENCONSOLE_MSG::InheritHandle, INVALID_HANDLE_VALUE, NT_SUCCESS, NULL, PCONSOLE_OPENCONSOLE_MSG, SET_LAST_NT_ERROR, _CONSOLE_OPENCONSOLE_MSG::ShareMode, and _CONSOLE_API_MSG::u.

Referenced by OpenConsoleW().

    00052                    :
    00053
    00054    Marshels parameters for the ConsolepOpenConsole command.
    00055
    00056 Arguments:
    00057
    00058    See the CONSOLE_OPENCONSOLE_MSG structure and OpenConsoleW.
    00059
    00060 Return Value:
    00061
    00062     INVALID_HANDLE_VALUE - An error occured.
    00063
    00064 --*/
    00065 {
    00066
    00067     CONSOLE_API_MSG m;
    00068     PCONSOLE_OPENCONSOLE_MSG a = &m.u.OpenConsole;
    00069
    00070     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00071     a->HandleType    = HandleType;
    00072     a->DesiredAccess = DesiredAccess;
    00073     a->InheritHandle = InheritHandle;
    00074     a->ShareMode= ShareMode;
    00075     CsrClientCallServer( (PCSR_API_MSG)&m,
    00076                          NULL,
    00077                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00078                                               ConsolepOpenConsole
    00079                                             ),
    00080                          sizeof( *a )
    00081                        );
    00082     if (!NT_SUCCESS( m.ReturnValue)) {
    00083         SET_LAST_NT_ERROR(m.ReturnValue);
    00084         return (HANDLE) INVALID_HANDLE_VALUE;
    00085     }
    00086     else {
    00087         return a->Handle;
    00088     }
    00089
    00090 }

BOOL APIENTRY ReadConsoleA | ( | IN HANDLE | hConsoleInput,
|  | OUT LPVOID | lpBuffer,
|  | IN DWORD | nNumberOfCharsToRead,
|  | OUT LPDWORD | lpNumberOfCharsRead,
|  | IN OUT LPVOID | lpReserved
| ) |

defined(BUILD_WOW6432)

Definition at line 349 of file client/stream.c.

References BUFFER_SIZE, ExeNameLength, FALSE, GetCurrentExeName(), NULL, ReadConsoleInternal(), and USHORT.

    00356 {
    00357
    00358     WCHAR ExeName[BUFFER_SIZE/2];
    00359     USHORT ExeNameLength;
    00360
    00361     ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName));
    00362
    00363     return ReadConsoleInternal(hConsoleInput,
    00364                                lpBuffer,
    00365                                nNumberOfCharsToRead,
    00366                                lpNumberOfCharsRead,
    00367                                NULL,
    00368                                FALSE,
    00369                                ExeNameLength,
    00370                                ExeName
    00371                               );
    00372     UNREFERENCED_PARAMETER(lpReserved);
    00373 }

BOOL APIENTRY ReadConsoleInternal | ( | IN HANDLE | hConsoleInput,
|  | OUT LPVOID | lpBuffer,
|  | IN DWORD | nNumberOfCharsToRead,
|  | OUT LPDWORD | lpNumberOfCharsRead,
|  | IN OUT LPVOID | lpReserved,
|  | IN BOOLEAN | Unicode,
|  | IN USHORT | ExeNameLength,
|  | IN LPWSTR | ExeName
| ) |

Definition at line 191 of file client/stream.c.

References _CONSOLE_READCONSOLE_MSG::Buffer, BUFFER_SIZE, _CONSOLE_READCONSOLE_MSG::BufPtr, _CONSOLE_READCONSOLE_MSG::CaptureBufferSize, _CONSOLE_READCONSOLE_MSG::ConsoleHandle, ConsolepReadConsole, _CONSOLE_READCONSOLE_MSG::ControlKeyState, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_READCONSOLE_MSG::CtrlWakeupMask, EXCEPTION_EXECUTE_HANDLER, ExeNameLength, _CONSOLE_READCONSOLE_MSG::ExeNameLength, FALSE, GET_CONSOLE_HANDLE, _CONSOLE_READCONSOLE_MSG::InitialNumBytes, _CONSOLE_READCONSOLE_MSG::InputHandle, NT_SUCCESS, NTSTATUS(), NtYieldExecution(), NULL, _CONSOLE_READCONSOLE_MSG::NumBytes, PCONSOLE_READCONSOLE_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, Status, TRUE, _CONSOLE_API_MSG::u, Unicode, and _CONSOLE_READCONSOLE_MSG::Unicode.

Referenced by ReadConsoleA(), and ReadConsoleW().

    00202           :
    00203
    00204     hConsoleInput - Supplies an open handle to "CONIN$" open for GENERIC_READ
    00205         or the StdIn handle.
    00206
    00207     lpBuffer - Supplies the address of a buffer to receive the data read
    00208         from the console input.
    00209
    00210     nNumberOfBytesToRead - Supplies the number of bytes to read from the
    00211         input buffer.
    00212
    00213     lpReserved - Ignore unless 4.0 application, in which case it points
    00214         to a CONSOLE_READCONSOLE_CONTROL data structure.  UNICODE only.
    00215         If !Unicode, then call fails if this parameter is non-NULL
    00216
    00217     Unicode - TRUE if call from ReadConsoleW, FALSE if ReadConsoleA
    00218
    00219
    00220 Return Value:
    00221
    00222     NON-NULL - Returns the number of bytes actually read from the input buffer.
    00223
    00224     FALSE/NULL - The operation failed.
    00225         Extended error status is available using GetLastError.
    00226 --*/
    00227
    00228 {
    00229     PCSR_CAPTURE_HEADER CaptureBuffer;
    00230     CONSOLE_API_MSG m;
    00231     PCONSOLE_READCONSOLE_MSG a = &m.u.ReadConsole;
    00232     BOOLEAN Dummy;
    00233     PCONSOLE_READCONSOLE_CONTROL pInputControl;
    00234     NTSTATUS Status;
    00235
    00236     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00237     a->InputHandle = hConsoleInput;
    00238     a->ExeNameLength = ExeNameLength;
    00239     RtlCopyMemory(a->Buffer, ExeName, ExeNameLength);
    00240     a->Unicode = Unicode;
    00241
    00242     //
    00243     // if ansi, make capture buffer large enough to hold translated
    00244     // string.  this will make server side code much simpler.
    00245     //
    00246
    00247     a->CaptureBufferSize = a->NumBytes = nNumberOfCharsToRead * sizeof(WCHAR);
    00248     if (a->CaptureBufferSize > BUFFER_SIZE) {
    00249         CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00250                                                   a->CaptureBufferSize
    00251                                                 );
    00252         if (CaptureBuffer == NULL) {
    00253             SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00254             return FALSE;
    00255         }
    00256         CsrCaptureMessageBuffer( CaptureBuffer,
    00257                                  NULL,
    00258                                  a->CaptureBufferSize,
    00259                                  (PVOID *) &a->BufPtr
    00260                                );
    00261
    00262     }
    00263     else {
    00264         a->BufPtr = a->Buffer;
    00265         CaptureBuffer = NULL;
    00266     }
    00267
    00268
    00269     pInputControl = (PCONSOLE_READCONSOLE_CONTROL)lpReserved;
    00270     a->InitialNumBytes = 0;
    00271     a->CtrlWakeupMask = 0;
    00272     a->ControlKeyState = 0;
    00273     Status = STATUS_SUCCESS;
    00274     try {
    00275         if (Unicode &&
    00276             ARGUMENT_PRESENT(lpReserved) &&
    00277             NtCurrentPeb()->ImageSubsystemMajorVersion >= 4 &&
    00278             pInputControl->nLength == sizeof(*pInputControl)
    00279            ) {
    00280             if ((pInputControl->nInitialChars > nNumberOfCharsToRead)) {
    00281                 Status = STATUS_INVALID_PARAMETER;
    00282             } else {
    00283                 a->InitialNumBytes = pInputControl->nInitialChars * sizeof(WCHAR);
    00284                 if (pInputControl->nInitialChars != 0) {
    00285                     RtlCopyMemory( a->BufPtr, lpBuffer, a->InitialNumBytes );
    00286                 }
    00287                 a->CtrlWakeupMask = pInputControl->dwCtrlWakeupMask;
    00288             }
    00289         } else {
    00290             pInputControl = NULL;
    00291         }
    00292     } except( EXCEPTION_EXECUTE_HANDLER ) {
    00293         Status = GetExceptionCode();
    00294     }
    00295
    00296     if (!NT_SUCCESS(Status) && pInputControl != NULL) {
    00297         if (CaptureBuffer != NULL) {
    00298             CsrFreeCaptureBuffer( CaptureBuffer );
    00299         }
    00300         SET_LAST_NT_ERROR(Status);
    00301         return FALSE;
    00302     }
    00303
    00304     CsrClientCallServer( (PCSR_API_MSG)&m,
    00305                          CaptureBuffer,
    00306                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00307                                               ConsolepReadConsole
    00308                                             ),
    00309                          sizeof( *a )
    00310                        );
    00311     if (NT_SUCCESS( m.ReturnValue )) {
    00312         try {
    00313             *lpNumberOfCharsRead = a->NumBytes;
    00314             if (Unicode) {
    00315                 *lpNumberOfCharsRead /= sizeof(WCHAR);
    00316                 if (pInputControl != NULL) {
    00317                     pInputControl->dwControlKeyState = a->ControlKeyState;
    00318                 }
    00319             }
    00320             RtlCopyMemory( lpBuffer, a->BufPtr, a->NumBytes );
    00321         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00322             if (CaptureBuffer != NULL) {
    00323                 CsrFreeCaptureBuffer( CaptureBuffer );
    00324             }
    00325             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00326             return FALSE;
    00327         }
    00328     }
    00329     if (CaptureBuffer != NULL) {
    00330         CsrFreeCaptureBuffer( CaptureBuffer );
    00331     }
    00332     if (!NT_SUCCESS( m.ReturnValue )) {
    00333         SET_LAST_NT_ERROR(m.ReturnValue);
    00334         return FALSE;
    00335     } else if (m.ReturnValue == STATUS_ALERTED) {
    00336         // ctrl-c or ctrl-break
    00337         NtYieldExecution();
    00338         SET_LAST_ERROR(ERROR_OPERATION_ABORTED);
    00339     }
    00340     return TRUE;
    00341 }

BOOL APIENTRY ReadConsoleW | ( | IN HANDLE | hConsoleInput,
|  | OUT LPVOID | lpBuffer,
|  | IN DWORD | nNumberOfCharsToRead,
|  | OUT LPDWORD | lpNumberOfCharsRead,
|  | IN OUT LPVOID | lpReserved
| ) |

Definition at line 377 of file client/stream.c.

References BUFFER_SIZE, ExeNameLength, GetCurrentExeName(), ReadConsoleInternal(), TRUE, and USHORT.

    00384 {
    00385     WCHAR ExeName[BUFFER_SIZE/2];
    00386     USHORT ExeNameLength;
    00387
    00388     ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName));
    00389
    00390     return ReadConsoleInternal(hConsoleInput,
    00391                                lpBuffer,
    00392                                nNumberOfCharsToRead,
    00393                                lpNumberOfCharsRead,
    00394                                lpReserved,
    00395                                TRUE,
    00396                                ExeNameLength,
    00397                                ExeName
    00398                               );
    00399     UNREFERENCED_PARAMETER(lpReserved);
    00400 }

BOOL APIENTRY SetConsoleHandleInformation | ( | IN HANDLE | hObject,
|  | IN DWORD | dwMask,
|  | IN DWORD | dwFlags
| ) |

Definition at line 734 of file client/stream.c.

References _CONSOLE_SETHANDLEINFORMATION_MSG::ConsoleHandle, ConsolepSetHandleInformation, CsrClientCallServer(), dwFlags, FALSE, _CONSOLE_SETHANDLEINFORMATION_MSG::Flags, GET_CONSOLE_HANDLE, _CONSOLE_SETHANDLEINFORMATION_MSG::Handle, _CONSOLE_SETHANDLEINFORMATION_MSG::Mask, NT_SUCCESS, NULL, PCONSOLE_SETHANDLEINFORMATION_MSG, SET_LAST_NT_ERROR, TRUE, and _CONSOLE_API_MSG::u.

    00741           :
    00742
    00743     hObject - An open handle to console input or output.
    00744
    00745     dwMask - Flags to change.
    00746
    00747     dwFlags - New values for flags.
    00748
    00749 Return Value:
    00750
    00751     TRUE - The operation was successful.
    00752
    00753     FALSE/NULL - The operation failed. Extended error status is available
    00754         using GetLastError.
    00755
    00756 --*/
    00757
    00758 {
    00759
    00760     CONSOLE_API_MSG m;
    00761     PCONSOLE_SETHANDLEINFORMATION_MSG a = &m.u.SetHandleInformation;
    00762
    00763     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00764     a->Handle = hObject;
    00765     a->Mask = dwMask;
    00766     a->Flags = dwFlags;
    00767
    00768     CsrClientCallServer( (PCSR_API_MSG)&m,
    00769                          NULL,
    00770                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00771                                               ConsolepSetHandleInformation
    00772                                             ),
    00773                          sizeof( *a )
    00774                        );
    00775     if (NT_SUCCESS( m.ReturnValue )) {
    00776         return TRUE;
    00777     } else {
    00778         SET_LAST_NT_ERROR (m.ReturnValue);
    00779         return FALSE;
    00780     }
    00781
    00782 }

BOOL APIENTRY VerifyConsoleIoHandle | ( | IN HANDLE | hIoHandle | ) |

Definition at line 787 of file client/stream.c.

References _CONSOLE_VERIFYIOHANDLE_MSG::ConsoleHandle, ConsolepVerifyIoHandle, CsrClientCallServer(), FALSE, GET_CONSOLE_HANDLE, _CONSOLE_VERIFYIOHANDLE_MSG::Handle, NT_SUCCESS, NULL, PCONSOLE_VERIFYIOHANDLE_MSG, SET_LAST_NT_ERROR, and _CONSOLE_API_MSG::u.

    00792           :
    00793
    00794     hIoHandle - Handle to verify
    00795
    00796 Return Value:
    00797
    00798     TRUE - handle is a valid console handle.
    00799
    00800     FALSE - handle is not a valid console handle.
    00801
    00802 --*/
    00803
    00804 {
    00805
    00806     CONSOLE_API_MSG m;
    00807     PCONSOLE_VERIFYIOHANDLE_MSG a = &m.u.VerifyConsoleIoHandle;
    00808
    00809     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00810     a->Handle = hIoHandle;
    00811
    00812     //
    00813     // If this process doesn't have a console handle, bail immediately.
    00814     //
    00815
    00816     if (a->ConsoleHandle == NULL) {
    00817         return FALSE;
    00818     }
    00819
    00820     CsrClientCallServer( (PCSR_API_MSG)&m,
    00821                          NULL,
    00822                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00823                                               ConsolepVerifyIoHandle
    00824                                             ),
    00825                          sizeof( *a )
    00826                        );
    00827     if (NT_SUCCESS( m.ReturnValue )) {
    00828         return a->Valid;
    00829     } else {
    00830         SET_LAST_NT_ERROR (m.ReturnValue);
    00831         return FALSE;
    00832     }
    00833
    00834
    00835 }

BOOL APIENTRY WriteConsoleA | ( | IN HANDLE | hConsoleOutput,
|  | IN CONST VOID * | lpBuffer,
|  | IN DWORD | nNumberOfCharsToWrite,
|  | OUT LPDWORD | lpNumberOfCharsWritten,
|  | IN OUT LPVOID | lpReserved
| ) |

defined(BUILD_WOW6432)

Definition at line 511 of file client/stream.c.

References FALSE, and WriteConsoleInternal().

Referenced by PrintPair().

    00518 {
    00519     return WriteConsoleInternal(hConsoleOutput,
    00520                                 lpBuffer,
    00521                                 nNumberOfCharsToWrite,
    00522                                 lpNumberOfCharsWritten,
    00523                                 FALSE
    00524                                );
    00525     UNREFERENCED_PARAMETER(lpReserved);
    00526 }

BOOL APIENTRY WriteConsoleInternal | ( | IN HANDLE | hConsoleOutput,
|  | IN CONST VOID * | lpBuffer,
|  | IN DWORD | nNumberOfCharsToWrite,
|  | OUT LPDWORD | lpNumberOfCharsWritten,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 408 of file client/stream.c.

References _CONSOLE_WRITECONSOLE_MSG::Buffer, BUFFER_SIZE, _CONSOLE_WRITECONSOLE_MSG::BufferInMessage, _CONSOLE_WRITECONSOLE_MSG::BufPtr, _CONSOLE_WRITECONSOLE_MSG::ConsoleHandle, ConsolepWriteConsole, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), EXCEPTION_EXECUTE_HANDLER, FALSE, GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, _CONSOLE_WRITECONSOLE_MSG::NumBytes, _CONSOLE_WRITECONSOLE_MSG::OutputHandle, PCONSOLE_WRITECONSOLE_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, TRUE, _CONSOLE_API_MSG::u, _CONSOLE_WRITECONSOLE_MSG::Unicode, and Unicode.

Referenced by WriteConsoleA(), and WriteConsoleW().

    00417           :
    00418
    00419     hFile - Supplies an open handle to to "CONOUT$" open for GENERIC_WRITE
    00420         or the StdOut or StdErr handle.
    00421
    00422     lpBuffer - Supplies the address of the data that is to be written to
    00423         the console output.
    00424
    00425     nNumberOfBytesToWrite - Supplies the number of bytes to write to the
    00426         console output.
    00427
    00428 Return Value:
    00429
    00430     NON-NULL - Returns the number of bytes actually written to the device.
    00431
    00432     FALSE/NULL - The operation failed.
    00433         Extended error status is available using GetLastError.
    00434 --*/
    00435
    00436 {
    00437
    00438     PCSR_CAPTURE_HEADER CaptureBuffer;
    00439     CONSOLE_API_MSG m;
    00440     PCONSOLE_WRITECONSOLE_MSG a = &m.u.WriteConsole;
    00441
    00442     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00443     a->OutputHandle = hConsoleOutput;
    00444
    00445     if (Unicode) {
    00446         a->NumBytes = nNumberOfCharsToWrite * sizeof(WCHAR);
    00447     } else {
    00448         a->NumBytes = nNumberOfCharsToWrite;
    00449     }
    00450
    00451     a->Unicode = Unicode;
    00452     if (a->NumBytes > BUFFER_SIZE) {
    00453         CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00454                                                   a->NumBytes
    00455                                                 );
    00456         if (CaptureBuffer == NULL) {
    00457             SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00458             return FALSE;
    00459         }
    00460         CsrCaptureMessageBuffer( CaptureBuffer,
    00461                                  (PCHAR) lpBuffer,
    00462                                  a->NumBytes,
    00463                                  (PVOID *) &a->BufPtr
    00464                                );
    00465         a->BufferInMessage = FALSE;
    00466     }
    00467     else {
    00468         a->BufPtr = a->Buffer;
    00469         try {
    00470             RtlCopyMemory( a->BufPtr, lpBuffer, a->NumBytes);
    00471         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00472             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00473             return FALSE;
    00474         }
    00475         CaptureBuffer = NULL;
    00476         a->BufferInMessage = TRUE;
    00477     }
    00478     CsrClientCallServer( (PCSR_API_MSG)&m,
    00479                          CaptureBuffer,
    00480                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00481                                               ConsolepWriteConsole
    00482                                             ),
    00483                          sizeof( *a )
    00484                        );
    00485     if (CaptureBuffer != NULL) {
    00486         CsrFreeCaptureBuffer( CaptureBuffer );
    00487     }
    00488     if (!NT_SUCCESS( m.ReturnValue )) {
    00489         SET_LAST_NT_ERROR(m.ReturnValue);
    00490         return FALSE;
    00491     }
    00492     try {
    00493        *lpNumberOfCharsWritten = a->NumBytes;
    00494        if (Unicode) {
    00495            *lpNumberOfCharsWritten /= sizeof(WCHAR);
    00496        }
    00497     } except( EXCEPTION_EXECUTE_HANDLER ) {
    00498         SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00499         return FALSE;
    00500     }
    00501     return TRUE;
    00502
    00503 }

BOOL APIENTRY WriteConsoleW | ( | IN HANDLE | hConsoleOutput,
|  | IN CONST VOID * | lpBuffer,
|  | IN DWORD | nNumberOfCharsToWrite,
|  | OUT LPDWORD | lpNumberOfCharsWritten,
|  | IN OUT LPVOID | lpReserved
| ) |

Definition at line 530 of file client/stream.c.

References TRUE, and WriteConsoleInternal().

Referenced by main(), and PrintPair().

    00537 {
    00538     return WriteConsoleInternal(hConsoleOutput,
    00539                                 lpBuffer,
    00540                                 nNumberOfCharsToWrite,
    00541                                 lpNumberOfCharsWritten,
    00542                                 TRUE
    00543                                );
    00544     UNREFERENCED_PARAMETER(lpReserved);
    00545 }

## Variable Documentation

HANDLE InputWaitHandle = (HANDLE)-1

| Definition at line 29 of file client/stream.c. Referenced by AllocConsole(), ConDllInitialize(), FreeConsole(), and GetConsoleInputWaitHandle().