test: client/cmdline.c File Reference

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

# cmdline.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Defines

#define | CONSOLE_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
#define | CONSOLE_NAME_PATH_TERMINATOR ((WCHAR)L'\0')
#define | FNAME_LENGTH 256

## Functions

VOID | InitExeName (VOID)
USHORT | GetCurrentExeName (OUT LPWSTR Buffer, IN ULONG BufferLength)
USHORT | GetExeName (IN OUT LPVOID *ExeName, IN BOOLEAN UnicodeApi, OUT PBOOLEAN UnicodeExe)
| defined(BUILD_WOW64)
BOOL APIENTRY | AddConsoleAliasInternal (IN LPVOID Source, IN UINT SourceLength, IN LPVOID Target, IN UINT TargetLength, IN LPVOID ExeName, IN BOOLEAN Unicode)
BOOL APIENTRY | AddConsoleAliasW (IN LPWSTR Source, IN LPWSTR Target, IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
BOOL APIENTRY | AddConsoleAliasA (IN LPTSTR Source, IN LPTSTR Target, IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleAliasInternal (IN LPVOID Source, IN UINT SourceLength, OUT LPVOID TargetBuffer, IN UINT TargetBufferLength, IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD APIENTRY | GetConsoleAliasW (IN LPWSTR Source, OUT LPWSTR TargetBuffer, IN DWORD TargetBufferLength, IN LPWSTR ExeName)
DWORD APIENTRY | GetConsoleAliasA (IN LPTSTR Source, OUT LPTSTR TargetBuffer, IN DWORD TargetBufferLength, IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleAliasesLengthInternal (IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD APIENTRY | GetConsoleAliasesLengthW (IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
DWORD APIENTRY | GetConsoleAliasesLengthA (IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleAliasExesLengthInternal (IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD APIENTRY | GetConsoleAliasExesLengthW (VOID)
| defined(BUILD_WOW6432)
DWORD APIENTRY | GetConsoleAliasExesLengthA (VOID)
DWORD APIENTRY | GetConsoleAliasesInternal (OUT LPVOID AliasBuffer, IN DWORD AliasBufferLength, IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD | GetConsoleAliasesW (OUT LPWSTR AliasBuffer, IN DWORD AliasBufferLength, IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
DWORD | GetConsoleAliasesA (OUT LPTSTR AliasBuffer, IN DWORD AliasBufferLength, IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleAliasExesInternal (OUT LPVOID ExeNameBuffer, IN DWORD ExeNameBufferLength, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD | GetConsoleAliasExesW (OUT LPWSTR ExeNameBuffer, IN DWORD ExeNameBufferLength)
| defined(BUILD_WOW6432)
DWORD | GetConsoleAliasExesA (OUT LPTSTR ExeNameBuffer, IN DWORD ExeNameBufferLength)
VOID APIENTRY | ExpungeConsoleCommandHistoryInternal (IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
VOID | ExpungeConsoleCommandHistoryW (IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
VOID | ExpungeConsoleCommandHistoryA (IN LPTSTR ExeName)
BOOL APIENTRY | SetConsoleNumberOfCommandsInternal (IN DWORD Number, IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
BOOL | SetConsoleNumberOfCommandsW (IN DWORD Number, IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
BOOL | SetConsoleNumberOfCommandsA (IN DWORD Number, IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleCommandHistoryLengthInternal (IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD | GetConsoleCommandHistoryLengthW (IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
DWORD | GetConsoleCommandHistoryLengthA (IN LPTSTR ExeName)
DWORD APIENTRY | GetConsoleCommandHistoryInternal (OUT LPVOID Commands, IN DWORD CommandBufferLength, IN LPVOID ExeName, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
DWORD | GetConsoleCommandHistoryW (OUT LPWSTR Commands, IN DWORD CommandBufferLength, IN LPWSTR ExeName)
| defined(BUILD_WOW6432)
DWORD | GetConsoleCommandHistoryA (OUT LPTSTR Commands, IN DWORD CommandBufferLength, IN LPTSTR ExeName)
BOOL APIENTRY | SetConsoleCommandHistoryMode (IN DWORD Flags)
| defined(BUILD_WOW64)
DWORD APIENTRY | GetConsoleTitleInternal (OUT PVOID lpConsoleTitle, IN DWORD nSize, IN BOOLEAN Unicode)
DWORD APIENTRY | GetConsoleTitleA (LPSTR lpConsoleTitle, DWORD nSize)
| defined(BUILD_WOW6432)
DWORD APIENTRY | GetConsoleTitleW (LPWSTR lpConsoleTitle, DWORD nSize)
BOOL APIENTRY | SetConsoleTitleInternal (IN CONST VOID *lpConsoleTitle, IN DWORD TitleLength, IN BOOLEAN Unicode)
| defined(BUILD_WOW64)
BOOL APIENTRY | SetConsoleTitleA (LPCSTR lpConsoleTitle)
| defined(BUILD_WOW6432)
BOOL APIENTRY | SetConsoleTitleW (LPCWSTR lpConsoleTitle)
DWORD | GetConsoleInputExeNameA (IN DWORD nBufferLength, OUT LPSTR lpBuffer)
DWORD | GetConsoleInputExeNameW (IN DWORD nBufferLength, OUT LPWSTR lpBuffer)
BOOL | SetConsoleInputExeNameA (IN LPSTR lpExeName)
BOOL | SetConsoleInputExeNameW (IN LPWSTR lpExeName)

## Variables

BOOLEAN | ExeNameInitialized
RTL_CRITICAL_SECTION | ExeNameCriticalSection
WCHAR | ExeNameBuffer [FNAME_LENGTH]
USHORT | ExeNameLength
WCHAR | StartDirBuffer [MAX_PATH+1]
USHORT | StartDirLength

## Define Documentation

#define CONSOLE_NAME_PATH_SEPARATOR ((WCHAR)L'\\')

| Definition at line 25 of file client/cmdline.c.

#define CONSOLE_NAME_PATH_TERMINATOR ((WCHAR)L'\0')

| Definition at line 26 of file client/cmdline.c. Referenced by GetConsoleTitleW(), and InitExeName().

#define FNAME_LENGTH 256

| Definition at line 30 of file client/cmdline.c. Referenced by GetConsoleInputExeNameA(), and SetConsoleInputExeNameW().

## Function Documentation

BOOL APIENTRY AddConsoleAliasA | ( | IN LPTSTR | Source,
|  | IN LPTSTR | Target,
|  | IN LPTSTR | ExeName
| ) |

Definition at line 252 of file client/cmdline.c.

References AddConsoleAliasInternal(), FALSE, NULL, and USHORT.

    00257 {
    00258     USHORT TargetLength;
    00259
    00260     if (Target != NULL) {
    00261         TargetLength = (USHORT) lstrlenA(Target);
    00262     } else {
    00263         TargetLength = 0;
    00264     }
    00265     return AddConsoleAliasInternal(Source,
    00266                                    lstrlenA(Source),
    00267                                    Target,
    00268                                    TargetLength,
    00269                                    ExeName,
    00270                                    FALSE
    00271                                   );
    00272 }

BOOL APIENTRY AddConsoleAliasInternal | ( | IN LPVOID | Source,
|  | IN UINT | SourceLength,
|  | IN LPVOID | Target,
|  | IN UINT | TargetLength,
|  | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

Definition at line 126 of file client/cmdline.c.

References CONSOLE_API_MSG, _CONSOLE_ADDALIAS_MSG::ConsoleHandle, ConsolepAddAlias, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_ADDALIAS_MSG::Exe, _CONSOLE_ADDALIAS_MSG::ExeLength, FALSE, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, PCONSOLE_ADDALIAS_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_ADDALIAS_MSG::Source, _CONSOLE_ADDALIAS_MSG::SourceLength, _CONSOLE_ADDALIAS_MSG::Target, _CONSOLE_ADDALIAS_MSG::TargetLength, TRUE, _CONSOLE_API_MSG::u, _CONSOLE_ADDALIAS_MSG::Unicode, Unicode, _CONSOLE_ADDALIAS_MSG::UnicodeExe, and USHORT.

Referenced by AddConsoleAliasA(), and AddConsoleAliasW().

    00137           :
    00138
    00139     Source - String to substitute alias string for, in input stream.
    00140
    00141     Target - String to substitute for source.  NULL to delete an existing
    00142         alias.
    00143
    00144     ExeName - Exe to set alias in.
    00145
    00146 Return Value:
    00147
    00148     TRUE - The operation was successful.
    00149
    00150     FALSE/NULL - The operation failed. Extended error status is available
    00151         using GetLastError.
    00152
    00153 --*/
    00154
    00155 {
    00156     PCSR_CAPTURE_HEADER CaptureBuffer;
    00157     CONSOLE_API_MSG m;
    00158     ULONG CapturedMsgPointers;
    00159     PCONSOLE_ADDALIAS_MSG a = &m.u.AddConsoleAliasW;
    00160
    00161     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00162     a->SourceLength = (USHORT)SourceLength;
    00163     a->Unicode = Unicode;
    00164     CapturedMsgPointers = 2;
    00165
    00166     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00167
    00168     if (Target != NULL) {
    00169         a->TargetLength = (USHORT)TargetLength;
    00170         CapturedMsgPointers += 1;
    00171     }
    00172     else {
    00173         a->Target = NULL;
    00174         a->TargetLength = 0;
    00175     }
    00176
    00177     CaptureBuffer = CsrAllocateCaptureBuffer( CapturedMsgPointers,
    00178                                               a->SourceLength + a->TargetLength + a->ExeLength
    00179                                             );
    00180     if (CaptureBuffer == NULL) {
    00181         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00182         return FALSE;
    00183     }
    00184     CsrCaptureMessageBuffer( CaptureBuffer,
    00185                              (PCHAR) Source,
    00186                              a->SourceLength,
    00187                              (PVOID *) &a->Source
    00188                            );
    00189
    00190     CsrCaptureMessageBuffer( CaptureBuffer,
    00191                              (PCHAR) ExeName,
    00192                              a->ExeLength,
    00193                              (PVOID *) &a->Exe
    00194                            );
    00195
    00196     if (Target != NULL) {
    00197         CsrCaptureMessageBuffer( CaptureBuffer,
    00198                                  (PCHAR) Target,
    00199                                  a->TargetLength,
    00200                                  (PVOID *) &a->Target
    00201                                );
    00202     }
    00203
    00204     CsrClientCallServer( (PCSR_API_MSG)&m,
    00205                          CaptureBuffer,
    00206                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00207                                               ConsolepAddAlias
    00208                                             ),
    00209                          sizeof( *a )
    00210                        );
    00211
    00212     CsrFreeCaptureBuffer( CaptureBuffer );
    00213
    00214     if (!NT_SUCCESS( m.ReturnValue )) {
    00215         SET_LAST_NT_ERROR(m.ReturnValue);
    00216         return FALSE;
    00217     }
    00218     return TRUE;
    00219
    00220 }

BOOL APIENTRY AddConsoleAliasW | ( | IN LPWSTR | Source,
|  | IN LPWSTR | Target,
|  | IN LPWSTR | ExeName
| ) |

defined(BUILD_WOW6432)

Definition at line 228 of file client/cmdline.c.

References AddConsoleAliasInternal(), NULL, TRUE, and USHORT.

    00233 {
    00234     USHORT TargetLength;
    00235
    00236     if (Target != NULL) {
    00237         TargetLength = (USHORT) (lstrlenW(Target)*sizeof(WCHAR));
    00238     } else {
    00239         TargetLength = 0;
    00240     }
    00241     return AddConsoleAliasInternal(Source,
    00242                                    lstrlenW(Source)*sizeof(WCHAR),
    00243                                    Target,
    00244                                    TargetLength,
    00245                                    ExeName,
    00246                                    TRUE
    00247                                   );
    00248 }

VOID ExpungeConsoleCommandHistoryA | ( | IN LPTSTR | ExeName | ) |

Definition at line 785 of file client/cmdline.c.

References ExpungeConsoleCommandHistoryInternal(), and FALSE.

    00788 {
    00789     ExpungeConsoleCommandHistoryInternal(ExeName,FALSE);
    00790 }

VOID APIENTRY ExpungeConsoleCommandHistoryInternal | ( | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 733 of file client/cmdline.c.

References _CONSOLE_EXPUNGECOMMANDHISTORY_MSG::ConsoleHandle, ConsolepExpungeCommandHistory, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_EXPUNGECOMMANDHISTORY_MSG::Exe, _CONSOLE_EXPUNGECOMMANDHISTORY_MSG::ExeLength, GET_CONSOLE_HANDLE, GetExeName(), NULL, PCONSOLE_EXPUNGECOMMANDHISTORY_MSG, SET_LAST_ERROR, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_EXPUNGECOMMANDHISTORY_MSG::Unicode, and _CONSOLE_EXPUNGECOMMANDHISTORY_MSG::UnicodeExe.

Referenced by ExpungeConsoleCommandHistoryA(), and ExpungeConsoleCommandHistoryW().

    00737 {
    00738     CONSOLE_API_MSG m;
    00739     PCONSOLE_EXPUNGECOMMANDHISTORY_MSG a = &m.u.ExpungeConsoleCommandHistoryW;
    00740     PCSR_CAPTURE_HEADER CaptureBuffer;
    00741
    00742     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00743     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00744     a->Unicode = Unicode;
    00745
    00746     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00747                                               a->ExeLength
    00748                                             );
    00749     if (CaptureBuffer == NULL) {
    00750         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00751         return;
    00752     }
    00753
    00754     CsrCaptureMessageBuffer( CaptureBuffer,
    00755                              (PCHAR) ExeName,
    00756                              a->ExeLength,
    00757                              (PVOID *) &a->Exe
    00758                            );
    00759
    00760     CsrClientCallServer( (PCSR_API_MSG)&m,
    00761                          CaptureBuffer,
    00762                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00763                                               ConsolepExpungeCommandHistory
    00764                                             ),
    00765                          sizeof( *a )
    00766                        );
    00767     CsrFreeCaptureBuffer( CaptureBuffer );
    00768
    00769 }

VOID ExpungeConsoleCommandHistoryW | ( | IN LPWSTR | ExeName | ) |

defined(BUILD_WOW6432)

Definition at line 777 of file client/cmdline.c.

References ExpungeConsoleCommandHistoryInternal(), and TRUE.

    00780 {
    00781     ExpungeConsoleCommandHistoryInternal(ExeName,TRUE);
    00782 }

DWORD APIENTRY GetConsoleAliasA | ( | IN LPTSTR | Source,
|  | OUT LPTSTR | TargetBuffer,
|  | IN DWORD | TargetBufferLength,
|  | IN LPTSTR | ExeName
| ) |

Definition at line 403 of file client/cmdline.c.

References FALSE, and GetConsoleAliasInternal().

    00409 {
    00410     return GetConsoleAliasInternal(Source,
    00411                                    lstrlenA(Source),
    00412                                    TargetBuffer,
    00413                                    TargetBufferLength,
    00414                                    ExeName,
    00415                                    FALSE
    00416                                   );
    00417 }

DWORD GetConsoleAliasesA | ( | OUT LPTSTR | AliasBuffer,
|  | IN DWORD | AliasBufferLength,
|  | IN LPTSTR | ExeName
| ) |

Definition at line 628 of file client/cmdline.c.

References FALSE, and GetConsoleAliasesInternal().

    00633 {
    00634     return GetConsoleAliasesInternal(AliasBuffer,
    00635                                      AliasBufferLength,
    00636                                      ExeName,
    00637                                      FALSE
    00638                                     );
    00639 }

DWORD APIENTRY GetConsoleAliasesInternal | ( | OUT LPVOID | AliasBuffer,
|  | IN DWORD | AliasBufferLength,
|  | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 550 of file client/cmdline.c.

References _CONSOLE_GETALIASES_MSG::AliasesBuffer, _CONSOLE_GETALIASES_MSG::AliasesBufferLength, _CONSOLE_GETALIASES_MSG::ConsoleHandle, ConsolepGetAliases, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), EXCEPTION_EXECUTE_HANDLER, _CONSOLE_GETALIASES_MSG::Exe, _CONSOLE_GETALIASES_MSG::ExeLength, FALSE, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, PCONSOLE_GETALIASES_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_GETALIASES_MSG::Unicode, and _CONSOLE_GETALIASES_MSG::UnicodeExe.

Referenced by GetConsoleAliasesA(), and GetConsoleAliasesW().

    00556 {
    00557     CONSOLE_API_MSG m;
    00558     PCONSOLE_GETALIASES_MSG a = &m.u.GetConsoleAliasesW;
    00559     PCSR_CAPTURE_HEADER CaptureBuffer;
    00560
    00561     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00562     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00563     a->Unicode = Unicode;
    00564     a->AliasesBufferLength = AliasBufferLength;
    00565
    00566     CaptureBuffer = CsrAllocateCaptureBuffer( 2,
    00567                                               a->ExeLength + AliasBufferLength
    00568                                             );
    00569     if (CaptureBuffer == NULL) {
    00570         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00571         return FALSE;
    00572     }
    00573
    00574     CsrCaptureMessageBuffer( CaptureBuffer,
    00575                              (PCHAR) ExeName,
    00576                              a->ExeLength,
    00577                              (PVOID *) &a->Exe
    00578                            );
    00579     CsrCaptureMessageBuffer( CaptureBuffer,
    00580                              (PCHAR) NULL,
    00581                              a->AliasesBufferLength,
    00582                              (PVOID *) &a->AliasesBuffer
    00583                            );
    00584     CsrClientCallServer( (PCSR_API_MSG)&m,
    00585                          CaptureBuffer,
    00586                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00587                                               ConsolepGetAliases
    00588                                             ),
    00589                          sizeof( *a )
    00590                        );
    00591     if (NT_SUCCESS( m.ReturnValue )) {
    00592         try {
    00593             RtlCopyMemory( AliasBuffer, a->AliasesBuffer, a->AliasesBufferLength );
    00594         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00595             CsrFreeCaptureBuffer( CaptureBuffer );
    00596             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00597             return 0;
    00598         }
    00599         CsrFreeCaptureBuffer( CaptureBuffer );
    00600         return a->AliasesBufferLength;
    00601     } else {
    00602         CsrFreeCaptureBuffer( CaptureBuffer );
    00603         SET_LAST_NT_ERROR(m.ReturnValue);
    00604         return 0;
    00605     }
    00606
    00607 }

DWORD APIENTRY GetConsoleAliasesLengthA | ( | IN LPTSTR | ExeName | ) |

Definition at line 485 of file client/cmdline.c.

References FALSE, and GetConsoleAliasesLengthInternal().

    00488 {
    00489     return GetConsoleAliasesLengthInternal(ExeName,
    00490                                            FALSE
    00491                                           );
    00492 }

DWORD APIENTRY GetConsoleAliasesLengthInternal | ( | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 425 of file client/cmdline.c.

References _CONSOLE_GETALIASESLENGTH_MSG::ConsoleHandle, ConsolepGetAliasesLength, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_GETALIASESLENGTH_MSG::Exe, _CONSOLE_GETALIASESLENGTH_MSG::ExeLength, FALSE, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, PCONSOLE_GETALIASESLENGTH_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_GETALIASESLENGTH_MSG::Unicode, and _CONSOLE_GETALIASESLENGTH_MSG::UnicodeExe.

Referenced by GetConsoleAliasesLengthA(), and GetConsoleAliasesLengthW().

    00429 {
    00430     CONSOLE_API_MSG m;
    00431     PCONSOLE_GETALIASESLENGTH_MSG a = &m.u.GetConsoleAliasesLengthW;
    00432     PCSR_CAPTURE_HEADER CaptureBuffer;
    00433
    00434     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00435     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00436     a->Unicode = Unicode;
    00437
    00438     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00439                                               a->ExeLength
    00440                                             );
    00441     if (CaptureBuffer == NULL) {
    00442         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00443         return FALSE;
    00444     }
    00445
    00446     CsrCaptureMessageBuffer( CaptureBuffer,
    00447                              (PCHAR) ExeName,
    00448                              a->ExeLength,
    00449                              (PVOID *) &a->Exe
    00450                            );
    00451     CsrClientCallServer( (PCSR_API_MSG)&m,
    00452                          CaptureBuffer,
    00453                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00454                                               ConsolepGetAliasesLength
    00455                                             ),
    00456                          sizeof( *a )
    00457                        );
    00458     CsrFreeCaptureBuffer( CaptureBuffer );
    00459     if (NT_SUCCESS( m.ReturnValue )) {
    00460         return a->AliasesLength;
    00461     } else {
    00462         SET_LAST_NT_ERROR(m.ReturnValue);
    00463         return 0;
    00464     }
    00465
    00466 }

DWORD APIENTRY GetConsoleAliasesLengthW | ( | IN LPWSTR | ExeName | ) |

defined(BUILD_WOW6432)

Definition at line 474 of file client/cmdline.c.

References GetConsoleAliasesLengthInternal(), and TRUE.

    00477 {
    00478     return GetConsoleAliasesLengthInternal(ExeName,
    00479                                            TRUE
    00480                                           );
    00481 }

DWORD GetConsoleAliasesW | ( | OUT LPWSTR | AliasBuffer,
|  | IN DWORD | AliasBufferLength,
|  | IN LPWSTR | ExeName
| ) |

defined(BUILD_WOW6432)

Definition at line 614 of file client/cmdline.c.

References GetConsoleAliasesInternal(), and TRUE.

    00619 {
    00620     return GetConsoleAliasesInternal(AliasBuffer,
    00621                                      AliasBufferLength,
    00622                                      ExeName,
    00623                                      TRUE
    00624                                     );
    00625 }

DWORD GetConsoleAliasExesA | ( | OUT LPTSTR | ExeNameBuffer,
|  | IN DWORD | ExeNameBufferLength
| ) |

Definition at line 716 of file client/cmdline.c.

References ExeNameBuffer, FALSE, and GetConsoleAliasExesInternal().

    00720 {
    00721     return GetConsoleAliasExesInternal(ExeNameBuffer,
    00722                                        ExeNameBufferLength,
    00723                                        FALSE
    00724                                       );
    00725 }

DWORD APIENTRY GetConsoleAliasExesInternal | ( | OUT LPVOID | ExeNameBuffer,
|  | IN DWORD | ExeNameBufferLength,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 647 of file client/cmdline.c.

References _CONSOLE_GETALIASEXES_MSG::AliasExesBuffer, _CONSOLE_GETALIASEXES_MSG::AliasExesBufferLength, _CONSOLE_GETALIASEXES_MSG::ConsoleHandle, ConsolepGetAliasExes, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), EXCEPTION_EXECUTE_HANDLER, ExeNameBuffer, FALSE, GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, PCONSOLE_GETALIASEXES_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_API_MSG::u, _CONSOLE_GETALIASEXES_MSG::Unicode, and Unicode.

Referenced by GetConsoleAliasExesA(), and GetConsoleAliasExesW().

    00652 {
    00653     CONSOLE_API_MSG m;
    00654     PCONSOLE_GETALIASEXES_MSG a = &m.u.GetConsoleAliasExesW;
    00655     PCSR_CAPTURE_HEADER CaptureBuffer;
    00656
    00657     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00658     a->AliasExesBufferLength = ExeNameBufferLength;
    00659     a->Unicode = Unicode;
    00660     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00661                                               ExeNameBufferLength
    00662                                             );
    00663     if (CaptureBuffer == NULL) {
    00664         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00665         return FALSE;
    00666     }
    00667
    00668     CsrCaptureMessageBuffer( CaptureBuffer,
    00669                              (PCHAR) NULL,
    00670                              a->AliasExesBufferLength,
    00671                              (PVOID *) &a->AliasExesBuffer
    00672                            );
    00673
    00674     CsrClientCallServer( (PCSR_API_MSG)&m,
    00675                          CaptureBuffer,
    00676                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00677                                               ConsolepGetAliasExes
    00678                                             ),
    00679                          sizeof( *a )
    00680                        );
    00681     if (NT_SUCCESS( m.ReturnValue )) {
    00682         try {
    00683             RtlCopyMemory( ExeNameBuffer, a->AliasExesBuffer, a->AliasExesBufferLength );
    00684         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00685             CsrFreeCaptureBuffer( CaptureBuffer );
    00686             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00687             return 0;
    00688         }
    00689         CsrFreeCaptureBuffer( CaptureBuffer );
    00690         return a->AliasExesBufferLength;
    00691     } else {
    00692         CsrFreeCaptureBuffer( CaptureBuffer );
    00693         SET_LAST_NT_ERROR(m.ReturnValue);
    00694         return 0;
    00695     }
    00696
    00697 }

DWORD APIENTRY GetConsoleAliasExesLengthA | ( | VOID |  | ) |

Definition at line 539 of file client/cmdline.c.

References FALSE, and GetConsoleAliasExesLengthInternal().

    00540 {
    00541     return GetConsoleAliasExesLengthInternal( FALSE );
    00542 }

DWORD APIENTRY GetConsoleAliasExesLengthInternal | ( | IN BOOLEAN | Unicode | ) |

defined(BUILD_WOW64)

Definition at line 500 of file client/cmdline.c.

References _CONSOLE_GETALIASEXESLENGTH_MSG::ConsoleHandle, ConsolepGetAliasExesLength, CsrClientCallServer(), GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, PCONSOLE_GETALIASEXESLENGTH_MSG, SET_LAST_NT_ERROR, _CONSOLE_API_MSG::u, _CONSOLE_GETALIASEXESLENGTH_MSG::Unicode, and Unicode.

Referenced by GetConsoleAliasExesLengthA(), and GetConsoleAliasExesLengthW().

    00503 {
    00504     CONSOLE_API_MSG m;
    00505     PCONSOLE_GETALIASEXESLENGTH_MSG a = &m.u.GetConsoleAliasExesLengthW;
    00506
    00507     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00508     a->Unicode = Unicode;
    00509
    00510     CsrClientCallServer( (PCSR_API_MSG)&m,
    00511                          NULL,
    00512                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00513                                               ConsolepGetAliasExesLength
    00514                                             ),
    00515                          sizeof( *a )
    00516                        );
    00517     if (NT_SUCCESS( m.ReturnValue )) {
    00518         return a->AliasExesLength;
    00519     } else {
    00520         SET_LAST_NT_ERROR(m.ReturnValue);
    00521         return 0;
    00522     }
    00523
    00524 }

DWORD APIENTRY GetConsoleAliasExesLengthW | ( | VOID |  | ) |

defined(BUILD_WOW6432)

Definition at line 532 of file client/cmdline.c.

References GetConsoleAliasExesLengthInternal(), and TRUE.

    00533 {
    00534     return GetConsoleAliasExesLengthInternal( TRUE );
    00535 }

DWORD GetConsoleAliasExesW | ( | OUT LPWSTR | ExeNameBuffer,
|  | IN DWORD | ExeNameBufferLength
| ) |

defined(BUILD_WOW6432)

Definition at line 704 of file client/cmdline.c.

References ExeNameBuffer, GetConsoleAliasExesInternal(), and TRUE.

    00708 {
    00709     return GetConsoleAliasExesInternal(ExeNameBuffer,
    00710                                        ExeNameBufferLength,
    00711                                        TRUE
    00712                                       );
    00713 }

DWORD APIENTRY GetConsoleAliasInternal | ( | IN LPVOID | Source,
|  | IN UINT | SourceLength,
|  | OUT LPVOID | TargetBuffer,
|  | IN UINT | TargetBufferLength,
|  | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 280 of file client/cmdline.c.

References _CONSOLE_GETALIAS_MSG::ConsoleHandle, ConsolepGetAlias, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_GETALIAS_MSG::Exe, _CONSOLE_GETALIAS_MSG::ExeLength, FALSE, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, PCONSOLE_GETALIAS_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_GETALIAS_MSG::Source, _CONSOLE_GETALIAS_MSG::SourceLength, _CONSOLE_GETALIAS_MSG::Target, _CONSOLE_GETALIAS_MSG::TargetLength, _CONSOLE_API_MSG::u, _CONSOLE_GETALIAS_MSG::Unicode, Unicode, _CONSOLE_GETALIAS_MSG::UnicodeExe, and USHORT.

Referenced by GetConsoleAliasA(), and GetConsoleAliasW().

    00291           :
    00292
    00293     Source - Name of alias to query.  NULL means query all alias names.
    00294
    00295     Target - Where to store value of alias.  If Source is NULL, then
    00296         value is one or more null terminated strings terminated by an extra
    00297         null byte.  Each null terminated string is the name of an alias.
    00298
    00299 Return Value:
    00300
    00301     Non-zero - The operation was successful, and the return value is the
    00302         number of characters stored in the Target buffer.
    00303
    00304     Zero - The operation failed. Extended error status is available
    00305         using GetLastError.
    00306
    00307 --*/
    00308
    00309 {
    00310     PCSR_CAPTURE_HEADER CaptureBuffer;
    00311     CONSOLE_API_MSG m;
    00312     ULONG CapturedMsgPointers;
    00313     PCONSOLE_GETALIAS_MSG a = &m.u.GetConsoleAliasW;
    00314
    00315     if (Source == NULL) {
    00316         SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    00317         return FALSE;
    00318     }
    00319     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00320     a->Unicode = Unicode;
    00321
    00322     CapturedMsgPointers = 3;
    00323
    00324     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00325
    00326     a->SourceLength = (USHORT) SourceLength;
    00327     a->TargetLength = (USHORT) TargetBufferLength;
    00328
    00329     CaptureBuffer = CsrAllocateCaptureBuffer( CapturedMsgPointers,
    00330                                               a->SourceLength + a->TargetLength + a->ExeLength
    00331                                             );
    00332     if (CaptureBuffer == NULL) {
    00333         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00334         return FALSE;
    00335     }
    00336
    00337     CsrCaptureMessageBuffer( CaptureBuffer,
    00338                              (PCHAR) ExeName,
    00339                              a->ExeLength,
    00340                              (PVOID *) &a->Exe
    00341                            );
    00342
    00343     CsrCaptureMessageBuffer( CaptureBuffer,
    00344                              (PCHAR) Source,
    00345                              a->SourceLength,
    00346                              (PVOID *) &a->Source
    00347                            );
    00348
    00349     CsrCaptureMessageBuffer( CaptureBuffer,
    00350                              (PCHAR) NULL,
    00351                              a->TargetLength,
    00352                              (PVOID *) &a->Target
    00353                            );
    00354
    00355     CsrClientCallServer( (PCSR_API_MSG)&m,
    00356                          CaptureBuffer,
    00357                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00358                                               ConsolepGetAlias
    00359                                             ),
    00360                          sizeof( *a )
    00361                        );
    00362
    00363     if (NT_SUCCESS( m.ReturnValue )) {
    00364         RtlCopyMemory( TargetBuffer, a->Target, a->TargetLength );
    00365     }
    00366     else {
    00367         SET_LAST_NT_ERROR(m.ReturnValue);
    00368         if (m.ReturnValue != STATUS_BUFFER_TOO_SMALL) {
    00369             a->TargetLength = 0;
    00370         }
    00371     }
    00372
    00373     CsrFreeCaptureBuffer( CaptureBuffer );
    00374
    00375     return a->TargetLength;
    00376
    00377 }

DWORD APIENTRY GetConsoleAliasW | ( | IN LPWSTR | Source,
|  | OUT LPWSTR | TargetBuffer,
|  | IN DWORD | TargetBufferLength,
|  | IN LPWSTR | ExeName
| ) |

Definition at line 385 of file client/cmdline.c.

References GetConsoleAliasInternal(), and TRUE.

    00391 {
    00392     return GetConsoleAliasInternal(Source,
    00393                                    lstrlenW(Source)*sizeof(WCHAR),
    00394                                    TargetBuffer,
    00395                                    TargetBufferLength,
    00396                                    ExeName,
    00397                                    TRUE
    00398                                   );
    00399 }

DWORD GetConsoleCommandHistoryA | ( | OUT LPTSTR | Commands,
|  | IN DWORD | CommandBufferLength,
|  | IN LPTSTR | ExeName
| ) |

Definition at line 1024 of file client/cmdline.c.

References Commands, FALSE, and GetConsoleCommandHistoryInternal().

    01029 {
    01030     return GetConsoleCommandHistoryInternal(Commands,
    01031                                             CommandBufferLength,
    01032                                             ExeName,
    01033                                             FALSE
    01034                                            );
    01035 }

DWORD APIENTRY GetConsoleCommandHistoryInternal | ( | OUT LPVOID | Commands,
|  | IN DWORD | CommandBufferLength,
|  | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 945 of file client/cmdline.c.

References _CONSOLE_GETCOMMANDHISTORY_MSG::CommandBuffer, _CONSOLE_GETCOMMANDHISTORY_MSG::CommandBufferLength, Commands, _CONSOLE_GETCOMMANDHISTORY_MSG::ConsoleHandle, ConsolepGetCommandHistory, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), EXCEPTION_EXECUTE_HANDLER, _CONSOLE_GETCOMMANDHISTORY_MSG::Exe, _CONSOLE_GETCOMMANDHISTORY_MSG::ExeLength, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, PCONSOLE_GETCOMMANDHISTORY_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_GETCOMMANDHISTORY_MSG::Unicode, and _CONSOLE_GETCOMMANDHISTORY_MSG::UnicodeExe.

Referenced by GetConsoleCommandHistoryA(), and GetConsoleCommandHistoryW().

    00951 {
    00952     CONSOLE_API_MSG m;
    00953     PCONSOLE_GETCOMMANDHISTORY_MSG a = &m.u.GetConsoleCommandHistoryW;
    00954     PCSR_CAPTURE_HEADER CaptureBuffer;
    00955
    00956     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00957     a->CommandBufferLength = CommandBufferLength;
    00958     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00959     a->Unicode = Unicode;
    00960     CaptureBuffer = CsrAllocateCaptureBuffer( 2,
    00961                                               CommandBufferLength + a->ExeLength
    00962                                             );
    00963     if (CaptureBuffer == NULL) {
    00964         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00965         return 0;
    00966     }
    00967
    00968
    00969     CsrCaptureMessageBuffer( CaptureBuffer,
    00970                              (PCHAR) ExeName,
    00971                              a->ExeLength,
    00972                              (PVOID *) &a->Exe
    00973                            );
    00974
    00975     CsrCaptureMessageBuffer( CaptureBuffer,
    00976                              (PCHAR) NULL,
    00977                              a->CommandBufferLength,
    00978                              (PVOID *) &a->CommandBuffer
    00979                            );
    00980     CsrClientCallServer( (PCSR_API_MSG)&m,
    00981                          CaptureBuffer,
    00982                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00983                                               ConsolepGetCommandHistory
    00984                                             ),
    00985                          sizeof( *a )
    00986                        );
    00987     if (NT_SUCCESS( m.ReturnValue )) {
    00988         try {
    00989             RtlCopyMemory( Commands, a->CommandBuffer, a->CommandBufferLength );
    00990         } except( EXCEPTION_EXECUTE_HANDLER ) {
    00991             CsrFreeCaptureBuffer( CaptureBuffer );
    00992             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    00993             return 0;
    00994         }
    00995         CsrFreeCaptureBuffer( CaptureBuffer );
    00996         return a->CommandBufferLength;
    00997     } else {
    00998         CsrFreeCaptureBuffer( CaptureBuffer );
    00999         SET_LAST_NT_ERROR(m.ReturnValue);
    01000         return 0;
    01001     }
    01002
    01003 }

DWORD GetConsoleCommandHistoryLengthA | ( | IN LPTSTR | ExeName | ) |

Definition at line 930 of file client/cmdline.c.

References FALSE, and GetConsoleCommandHistoryLengthInternal().

    00933 {
    00934     return GetConsoleCommandHistoryLengthInternal(ExeName,
    00935                                                   FALSE
    00936                                                  );
    00937 }

DWORD APIENTRY GetConsoleCommandHistoryLengthInternal | ( | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 877 of file client/cmdline.c.

References _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG::ConsoleHandle, ConsolepGetCommandHistoryLength, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG::Exe, _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG::ExeLength, GET_CONSOLE_HANDLE, GetExeName(), NULL, PCONSOLE_GETCOMMANDHISTORYLENGTH_MSG, SET_LAST_ERROR, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG::Unicode, and _CONSOLE_GETCOMMANDHISTORYLENGTH_MSG::UnicodeExe.

Referenced by GetConsoleCommandHistoryLengthA(), and GetConsoleCommandHistoryLengthW().

    00881 {
    00882     CONSOLE_API_MSG m;
    00883     PCONSOLE_GETCOMMANDHISTORYLENGTH_MSG a = &m.u.GetConsoleCommandHistoryLengthW;
    00884     PCSR_CAPTURE_HEADER CaptureBuffer;
    00885
    00886     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00887     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00888     a->Unicode = Unicode;
    00889     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00890                                               a->ExeLength
    00891                                             );
    00892     if (CaptureBuffer == NULL) {
    00893         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00894         return 0;
    00895     }
    00896
    00897     CsrCaptureMessageBuffer( CaptureBuffer,
    00898                              (PCHAR) ExeName,
    00899                              a->ExeLength,
    00900                              (PVOID *) &a->Exe
    00901                            );
    00902
    00903     CsrClientCallServer( (PCSR_API_MSG)&m,
    00904                          CaptureBuffer,
    00905                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00906                                               ConsolepGetCommandHistoryLength
    00907                                             ),
    00908                          sizeof( *a )
    00909                        );
    00910     CsrFreeCaptureBuffer( CaptureBuffer );
    00911     return a->CommandHistoryLength;
    00912
    00913 }

DWORD GetConsoleCommandHistoryLengthW | ( | IN LPWSTR | ExeName | ) |

defined(BUILD_WOW6432)

Definition at line 920 of file client/cmdline.c.

References GetConsoleCommandHistoryLengthInternal(), and TRUE.

    00923 {
    00924     return GetConsoleCommandHistoryLengthInternal(ExeName,
    00925                                                   TRUE
    00926                                                  );
    00927 }

DWORD GetConsoleCommandHistoryW | ( | OUT LPWSTR | Commands,
|  | IN DWORD | CommandBufferLength,
|  | IN LPWSTR | ExeName
| ) |

defined(BUILD_WOW6432)

Definition at line 1010 of file client/cmdline.c.

References Commands, GetConsoleCommandHistoryInternal(), and TRUE.

    01015 {
    01016     return GetConsoleCommandHistoryInternal(Commands,
    01017                                             CommandBufferLength,
    01018                                             ExeName,
    01019                                             TRUE
    01020                                            );
    01021 }

DWORD GetConsoleInputExeNameA | ( | IN DWORD | nBufferLength,
|  | OUT LPSTR | lpBuffer
| ) |

Definition at line 1256 of file client/cmdline.c.

References DWORD, FALSE, FNAME_LENGTH, GetConsoleInputExeNameW(), n, NT_SUCCESS, NTSTATUS(), RtlInitUnicodeString(), RtlUnicodeStringToAnsiString(), SET_LAST_ERROR, Status, Unicode, and USHORT.

    01260 {
    01261     PUNICODE_STRING Unicode;
    01262     ANSI_STRING AnsiString;
    01263     NTSTATUS Status;
    01264     UNICODE_STRING UnicodeString;
    01265     WCHAR TempExeNameBuffer[FNAME_LENGTH];
    01266     DWORD n;
    01267
    01268     n = GetConsoleInputExeNameW(FNAME_LENGTH, TempExeNameBuffer);
    01269     if (n != 0 && n < FNAME_LENGTH) {
    01270         RtlInitUnicodeString(&UnicodeString, TempExeNameBuffer);
    01271         AnsiString.Buffer = lpBuffer;
    01272         AnsiString.Length = 0;
    01273         AnsiString.MaximumLength = (USHORT)nBufferLength;
    01274         Status = RtlUnicodeStringToAnsiString(&AnsiString, &UnicodeString, FALSE);
    01275         if (!NT_SUCCESS(Status)) {
    01276             if (Status == STATUS_BUFFER_OVERFLOW) {
    01277                 SET_LAST_ERROR(ERROR_BUFFER_OVERFLOW);
    01278                 return n+1;
    01279             } else {
    01280                 SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    01281             }
    01282         }
    01283     }
    01284     return n;
    01285 }

DWORD GetConsoleInputExeNameW | ( | IN DWORD | nBufferLength,
|  | OUT LPWSTR | lpBuffer
| ) |

Definition at line 1288 of file client/cmdline.c.

References DWORD, ExeNameBuffer, ExeNameCriticalSection, ExeNameLength, n, SET_LAST_ERROR, and TRUE.

Referenced by GetConsoleInputExeNameA().

    01292 {
    01293     DWORD n;
    01294
    01295     n = ExeNameLength;
    01296     if (n >= nBufferLength) {
    01297         SET_LAST_ERROR(ERROR_BUFFER_OVERFLOW);
    01298         return n+1;
    01299     }
    01300
    01301     try {
    01302         RtlEnterCriticalSection(&ExeNameCriticalSection);
    01303         RtlCopyMemory(lpBuffer, ExeNameBuffer, n*sizeof(WCHAR));
    01304         lpBuffer[n] = UNICODE_NULL;
    01305     } finally {
    01306         RtlLeaveCriticalSection(&ExeNameCriticalSection);
    01307     }
    01308
    01309     return TRUE;
    01310 }

DWORD APIENTRY GetConsoleTitleA | ( | LPSTR | lpConsoleTitle,
|  | DWORD | nSize
| ) |

defined(BUILD_WOW6432)

Definition at line 1129 of file client/cmdline.c.

References CHAR, DWORD, FALSE, and GetConsoleTitleInternal().

    01133 {
    01134     DWORD NumBytes;
    01135     NumBytes = GetConsoleTitleInternal(lpConsoleTitle,
    01136                                    nSize-sizeof(CHAR), // allow room for null
    01137                                    FALSE
    01138                                   );
    01139     if (NumBytes) {
    01140         lpConsoleTitle[NumBytes] = '\0';   // NULL terminate
    01141     }
    01142     return NumBytes;
    01143 }

DWORD APIENTRY GetConsoleTitleInternal | ( | OUT PVOID | lpConsoleTitle,
|  | IN DWORD | nSize,
|  | IN BOOLEAN | Unicode
| ) |

Definition at line 1070 of file client/cmdline.c.

References _CONSOLE_GETTITLE_MSG::ConsoleHandle, ConsolepGetTitle, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), EXCEPTION_EXECUTE_HANDLER, GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, PCONSOLE_GETTITLE_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, _CONSOLE_GETTITLE_MSG::Title, _CONSOLE_GETTITLE_MSG::TitleLength, _CONSOLE_API_MSG::u, _CONSOLE_GETTITLE_MSG::Unicode, and Unicode.

Referenced by GetConsoleTitleA(), and GetConsoleTitleW().

    01075 {
    01076     CONSOLE_API_MSG m;
    01077     PCONSOLE_GETTITLE_MSG a = &m.u.GetConsoleTitle;
    01078     PCSR_CAPTURE_HEADER CaptureBuffer;
    01079
    01080     if (nSize == 0) {
    01081         return 0;
    01082     }
    01083     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    01084     a->TitleLength = nSize;
    01085     a->Unicode = Unicode;
    01086     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    01087                                               a->TitleLength
    01088                                             );
    01089     if (CaptureBuffer == NULL) {
    01090         return 0;
    01091     }
    01092     CsrCaptureMessageBuffer( CaptureBuffer,
    01093                              NULL,
    01094                              a->TitleLength,
    01095                              (PVOID *) &a->Title
    01096                            );
    01097     CsrClientCallServer( (PCSR_API_MSG)&m,
    01098                          CaptureBuffer,
    01099                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    01100                                               ConsolepGetTitle
    01101                                             ),
    01102                          sizeof( *a )
    01103                        );
    01104     if (NT_SUCCESS( m.ReturnValue )) {
    01105         try {
    01106             RtlCopyMemory( lpConsoleTitle, a->Title, a->TitleLength);
    01107         } except( EXCEPTION_EXECUTE_HANDLER ) {
    01108             CsrFreeCaptureBuffer( CaptureBuffer );
    01109             SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    01110             return 0;
    01111         }
    01112     }
    01113     else {
    01114         CsrFreeCaptureBuffer( CaptureBuffer );
    01115         SET_LAST_NT_ERROR (m.ReturnValue);
    01116         return 0;
    01117     }
    01118     CsrFreeCaptureBuffer( CaptureBuffer );
    01119     return a->TitleLength;
    01120
    01121 }

DWORD APIENTRY GetConsoleTitleW | ( | LPWSTR | lpConsoleTitle,
|  | DWORD | nSize
| ) |

Definition at line 1147 of file client/cmdline.c.

References CONSOLE_NAME_PATH_TERMINATOR, DWORD, GetConsoleTitleInternal(), and TRUE.

    01151 {
    01152     DWORD NumBytes;
    01153     NumBytes = GetConsoleTitleInternal(lpConsoleTitle,
    01154                                    (nSize-1)*sizeof(WCHAR), // allow room for null
    01155                                    TRUE
    01156                                   );
    01157     if (NumBytes) {
    01158         NumBytes /= sizeof(WCHAR);
    01159         lpConsoleTitle[NumBytes] = CONSOLE_NAME_PATH_TERMINATOR;   // NULL terminate
    01160     }
    01161     return NumBytes;
    01162 }

USHORT GetCurrentExeName | ( | OUT LPWSTR | Buffer,
|  | IN ULONG | BufferLength
| ) |

Definition at line 70 of file client/cmdline.c.

References Buffer, ExeNameBuffer, ExeNameCriticalSection, ExeNameInitialized, ExeNameLength, and USHORT.

    00074 {
    00075     if (!ExeNameInitialized) {
    00076         Buffer[0] = UNICODE_NULL;
    00077         return 0;
    00078     }
    00079
    00080     RtlEnterCriticalSection(&ExeNameCriticalSection);
    00081     if (BufferLength > ExeNameLength * sizeof( WCHAR )) {
    00082         BufferLength = ExeNameLength * sizeof( WCHAR );
    00083     }
    00084     RtlCopyMemory(Buffer,ExeNameBuffer,BufferLength);
    00085     RtlLeaveCriticalSection(&ExeNameCriticalSection);
    00086     return (USHORT)BufferLength;
    00087 }

USHORT GetExeName | ( | IN OUT LPVOID * | ExeName,
|  | IN BOOLEAN | UnicodeApi,
|  | OUT PBOOLEAN | UnicodeExe
| ) |

defined(BUILD_WOW64)

Definition at line 94 of file client/cmdline.c.

References EXCEPTION_EXECUTE_HANDLER, FALSE, NULL, strlen(), TRUE, and USHORT.

Referenced by AddConsoleAliasInternal(), ExpungeConsoleCommandHistoryInternal(), GetConsoleAliasesInternal(), GetConsoleAliasesLengthInternal(), GetConsoleAliasInternal(), GetConsoleCommandHistoryInternal(), GetConsoleCommandHistoryLengthInternal(), and SetConsoleNumberOfCommandsInternal().

    00099 {
    00100
    00101     *UnicodeExe = TRUE;
    00102     if (*ExeName == NULL) {
    00103         // Should not get here
    00104         return 0;
    00105     } else if (!UnicodeApi) {
    00106         *UnicodeExe = FALSE;
    00107     }
    00108
    00109     if (ExeName == NULL) {
    00110        return 0;
    00111     }
    00112
    00113     try {
    00114        if (*UnicodeExe)
    00115            return (USHORT)wcslen(*ExeName)*sizeof(WCHAR);  // returns bytes, not chars
    00116        else
    00117            return (USHORT)strlen(*ExeName);  // returns bytes, not chars
    00118     }
    00119     except(EXCEPTION_EXECUTE_HANDLER) {
    00120        return 0;
    00121     }
    00122 }

VOID InitExeName | ( | VOID |  | ) |

Definition at line 39 of file client/cmdline.c.

References CONSOLE_NAME_PATH_TERMINATOR, ExeNameBuffer, ExeNameCriticalSection, ExeNameInitialized, ExeNameLength, RtlInitializeCriticalSection(), StartDirBuffer, StartDirLength, and TRUE.

Referenced by AllocConsole(), and ConDllInitialize().

    00040 {
    00041
    00042     PPEB Peb;
    00043     PLDR_DATA_TABLE_ENTRY ImageEntry;
    00044
    00045     if (ExeNameInitialized) {
    00046         return;
    00047     }
    00048
    00049     RtlInitializeCriticalSection(&ExeNameCriticalSection);
    00050     ExeNameInitialized = TRUE;
    00051     Peb = NtCurrentPeb();
    00052     ImageEntry = (PLDR_DATA_TABLE_ENTRY)Peb->Ldr->InLoadOrderModuleList.Flink;
    00053     ImageEntry = CONTAINING_RECORD(ImageEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
    00054     ExeNameLength = ImageEntry->BaseDllName.Length/sizeof(WCHAR);
    00055     RtlCopyMemory(ExeNameBuffer,
    00056            ImageEntry->BaseDllName.Buffer,
    00057            ImageEntry->BaseDllName.Length
    00058           );
    00059     ExeNameBuffer[ExeNameLength] = CONSOLE_NAME_PATH_TERMINATOR;
    00060     StartDirLength = Peb->ProcessParameters->CurrentDirectory.DosPath.Length/sizeof(WCHAR);
    00061     RtlCopyMemory(StartDirBuffer,
    00062            Peb->ProcessParameters->CurrentDirectory.DosPath.Buffer,
    00063            Peb->ProcessParameters->CurrentDirectory.DosPath.Length
    00064           );
    00065     StartDirBuffer[StartDirLength] = CONSOLE_NAME_PATH_TERMINATOR;
    00066 }

BOOL APIENTRY SetConsoleCommandHistoryMode | ( | IN DWORD | Flags | ) |

defined(BUILD_WOW64)

Definition at line 1043 of file client/cmdline.c.

References _CONSOLE_SETCOMMANDHISTORYMODE_MSG::ConsoleHandle, ConsolepSetCommandHistoryMode, CsrClientCallServer(), FALSE, _CONSOLE_SETCOMMANDHISTORYMODE_MSG::Flags, GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, PCONSOLE_SETCOMMANDHISTORYMODE_MSG, SET_LAST_NT_ERROR, TRUE, and _CONSOLE_API_MSG::u.

    01046 {
    01047     CONSOLE_API_MSG m;
    01048     PCONSOLE_SETCOMMANDHISTORYMODE_MSG a = &m.u.SetConsoleCommandHistoryMode;
    01049
    01050     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    01051     a->Flags = Flags;
    01052
    01053     CsrClientCallServer( (PCSR_API_MSG)&m,
    01054                          NULL,
    01055                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    01056                                               ConsolepSetCommandHistoryMode
    01057                                             ),
    01058                          sizeof( *a )
    01059                        );
    01060     if (NT_SUCCESS( m.ReturnValue )) {
    01061         return TRUE;
    01062     } else {
    01063         SET_LAST_NT_ERROR(m.ReturnValue);
    01064         return FALSE;
    01065     }
    01066 }

BOOL SetConsoleInputExeNameA | ( | IN LPSTR | lpExeName | ) |

Definition at line 1313 of file client/cmdline.c.

References FALSE, NT_SUCCESS, NTSTATUS(), RtlAnsiStringToUnicodeString(), RtlInitAnsiString(), SET_LAST_ERROR, SetConsoleInputExeNameW(), Status, and Unicode.

    01316 {
    01317     PUNICODE_STRING Unicode;
    01318     ANSI_STRING AnsiString;
    01319     NTSTATUS Status;
    01320
    01321     Unicode = &NtCurrentTeb()->StaticUnicodeString;
    01322     RtlInitAnsiString(&AnsiString,lpExeName);
    01323     Status = RtlAnsiStringToUnicodeString(Unicode,&AnsiString,FALSE);
    01324     if (!NT_SUCCESS(Status)) {
    01325         if (Status == STATUS_BUFFER_OVERFLOW) {
    01326             SET_LAST_ERROR(ERROR_FILENAME_EXCED_RANGE);
    01327         } else {
    01328             SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    01329         }
    01330         return FALSE;
    01331     }
    01332
    01333     return SetConsoleInputExeNameW(Unicode->Buffer);
    01334 }

BOOL SetConsoleInputExeNameW | ( | IN LPWSTR | lpExeName | ) |

Definition at line 1337 of file client/cmdline.c.

References DWORD, ExeNameBuffer, ExeNameCriticalSection, ExeNameLength, FALSE, FNAME_LENGTH, n, SET_LAST_ERROR, TRUE, and USHORT.

Referenced by SetConsoleInputExeNameA().

    01340 {
    01341     DWORD n;
    01342
    01343     n = lstrlenW(lpExeName);
    01344     if (n == 0 || n >= FNAME_LENGTH) {
    01345         SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
    01346         return FALSE;
    01347     }
    01348
    01349     RtlEnterCriticalSection(&ExeNameCriticalSection);
    01350     try {
    01351         RtlCopyMemory(ExeNameBuffer,lpExeName,n*sizeof(WCHAR));
    01352         ExeNameLength = (USHORT)n;
    01353     } finally {
    01354         RtlLeaveCriticalSection(&ExeNameCriticalSection);
    01355     }
    01356
    01357     return TRUE;
    01358 }

BOOL SetConsoleNumberOfCommandsA | ( | IN DWORD | Number,
|  | IN LPTSTR | ExeName
| ) |

Definition at line 860 of file client/cmdline.c.

References FALSE, and SetConsoleNumberOfCommandsInternal().

    00864 {
    00865     return SetConsoleNumberOfCommandsInternal(Number,
    00866                                               ExeName,
    00867                                               FALSE
    00868                                              );
    00869 }

BOOL APIENTRY SetConsoleNumberOfCommandsInternal | ( | IN DWORD | Number,
|  | IN LPVOID | ExeName,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 798 of file client/cmdline.c.

References _CONSOLE_SETNUMBEROFCOMMANDS_MSG::ConsoleHandle, ConsolepSetNumberOfCommands, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), _CONSOLE_SETNUMBEROFCOMMANDS_MSG::Exe, _CONSOLE_SETNUMBEROFCOMMANDS_MSG::ExeLength, FALSE, GET_CONSOLE_HANDLE, GetExeName(), NT_SUCCESS, NULL, _CONSOLE_SETNUMBEROFCOMMANDS_MSG::NumCommands, PCONSOLE_SETNUMBEROFCOMMANDS_MSG, SET_LAST_ERROR, SET_LAST_NT_ERROR, TRUE, _CONSOLE_API_MSG::u, Unicode, _CONSOLE_SETNUMBEROFCOMMANDS_MSG::Unicode, and _CONSOLE_SETNUMBEROFCOMMANDS_MSG::UnicodeExe.

Referenced by SetConsoleNumberOfCommandsA(), and SetConsoleNumberOfCommandsW().

    00803 {
    00804     CONSOLE_API_MSG m;
    00805     PCONSOLE_SETNUMBEROFCOMMANDS_MSG a = &m.u.SetConsoleNumberOfCommandsW;
    00806     PCSR_CAPTURE_HEADER CaptureBuffer;
    00807
    00808     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    00809     a->NumCommands = Number;
    00810     a->ExeLength = GetExeName(&ExeName,Unicode,&a->UnicodeExe);
    00811     a->Unicode = Unicode;
    00812     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    00813                                               a->ExeLength
    00814                                             );
    00815     if (CaptureBuffer == NULL) {
    00816         SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
    00817         return FALSE;
    00818     }
    00819
    00820     CsrCaptureMessageBuffer( CaptureBuffer,
    00821                              (PCHAR) ExeName,
    00822                              a->ExeLength,
    00823                              (PVOID *) &a->Exe
    00824                            );
    00825
    00826     CsrClientCallServer( (PCSR_API_MSG)&m,
    00827                          CaptureBuffer,
    00828                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    00829                                               ConsolepSetNumberOfCommands
    00830                                             ),
    00831                          sizeof( *a )
    00832                        );
    00833     CsrFreeCaptureBuffer( CaptureBuffer );
    00834     if (NT_SUCCESS( m.ReturnValue )) {
    00835         return TRUE;
    00836     } else {
    00837         SET_LAST_NT_ERROR(m.ReturnValue);
    00838         return FALSE;
    00839     }
    00840
    00841 }

BOOL SetConsoleNumberOfCommandsW | ( | IN DWORD | Number,
|  | IN LPWSTR | ExeName
| ) |

defined(BUILD_WOW6432)

Definition at line 848 of file client/cmdline.c.

References SetConsoleNumberOfCommandsInternal(), and TRUE.

    00852 {
    00853     return SetConsoleNumberOfCommandsInternal(Number,
    00854                                               ExeName,
    00855                                               TRUE
    00856                                              );
    00857 }

BOOL APIENTRY SetConsoleTitleA | ( | LPCSTR | lpConsoleTitle | ) |

defined(BUILD_WOW6432)

Definition at line 1220 of file client/cmdline.c.

References DWORD, EXCEPTION_EXECUTE_HANDLER, FALSE, SET_LAST_ERROR, SetConsoleTitleInternal(), and strlen().

    01223 {
    01224     DWORD TitleLength;
    01225     try {
    01226         TitleLength = strlen(lpConsoleTitle);
    01227     } except( EXCEPTION_EXECUTE_HANDLER ) {
    01228         SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    01229         return FALSE;
    01230     }
    01231     return SetConsoleTitleInternal(lpConsoleTitle,
    01232                                    TitleLength,
    01233                                    FALSE);
    01234 }

BOOL APIENTRY SetConsoleTitleInternal | ( | IN CONST VOID * | lpConsoleTitle,
|  | IN DWORD | TitleLength,
|  | IN BOOLEAN | Unicode
| ) |

defined(BUILD_WOW64)

Definition at line 1170 of file client/cmdline.c.

References _CONSOLE_SETTITLE_MSG::ConsoleHandle, ConsolepSetTitle, CsrAllocateCaptureBuffer(), CsrCaptureMessageBuffer(), CsrClientCallServer(), CsrFreeCaptureBuffer(), FALSE, GET_CONSOLE_HANDLE, NT_SUCCESS, NULL, PCONSOLE_SETTITLE_MSG, SET_LAST_NT_ERROR, _CONSOLE_SETTITLE_MSG::Title, _CONSOLE_SETTITLE_MSG::TitleLength, TRUE, _CONSOLE_API_MSG::u, _CONSOLE_SETTITLE_MSG::Unicode, and Unicode.

Referenced by SetConsoleTitleA(), and SetConsoleTitleW().

    01175 {
    01176     CONSOLE_API_MSG m;
    01177     PCONSOLE_SETTITLE_MSG a = &m.u.SetConsoleTitle;
    01178     PCSR_CAPTURE_HEADER CaptureBuffer;
    01179
    01180     a->ConsoleHandle = GET_CONSOLE_HANDLE;
    01181     a->TitleLength = TitleLength;
    01182     a->Unicode = Unicode;
    01183     CaptureBuffer = CsrAllocateCaptureBuffer( 1,
    01184                                               a->TitleLength
    01185                                             );
    01186     if (CaptureBuffer == NULL) {
    01187         return FALSE;
    01188     }
    01189     CsrCaptureMessageBuffer( CaptureBuffer,
    01190                              (PCHAR) lpConsoleTitle,
    01191                              a->TitleLength,
    01192                              (PVOID *) &a->Title
    01193                            );
    01194     CsrClientCallServer( (PCSR_API_MSG)&m,
    01195                          CaptureBuffer,
    01196                          CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
    01197                                               ConsolepSetTitle
    01198                                             ),
    01199                          sizeof( *a )
    01200                        );
    01201
    01202     CsrFreeCaptureBuffer( CaptureBuffer );
    01203
    01204     if (NT_SUCCESS( m.ReturnValue )) {
    01205         return TRUE;
    01206     }
    01207     else {
    01208         SET_LAST_NT_ERROR (m.ReturnValue);
    01209         return FALSE;
    01210     }
    01211
    01212 }

BOOL APIENTRY SetConsoleTitleW | ( | LPCWSTR | lpConsoleTitle | ) |

Definition at line 1238 of file client/cmdline.c.

References DWORD, EXCEPTION_EXECUTE_HANDLER, FALSE, SET_LAST_ERROR, SetConsoleTitleInternal(), and TRUE.

    01241 {
    01242     DWORD TitleLength;
    01243     try {
    01244         TitleLength = wcslen(lpConsoleTitle)*sizeof(WCHAR);
    01245     } except( EXCEPTION_EXECUTE_HANDLER ) {
    01246         SET_LAST_ERROR(ERROR_INVALID_ACCESS);
    01247         return FALSE;
    01248     }
    01249     return SetConsoleTitleInternal(lpConsoleTitle,
    01250                                    TitleLength,
    01251                                    TRUE);
    01252 }

## Variable Documentation

WCHAR ExeNameBuffer[FNAME_LENGTH]

| Definition at line 33 of file client/cmdline.c. Referenced by GetConsoleAliasExesA(), GetConsoleAliasExesInternal(), GetConsoleAliasExesW(), GetConsoleInputExeNameW(), GetCurrentExeName(), InitExeName(), SetConsoleInputExeNameW(), and SetUpAppName().

RTL_CRITICAL_SECTION ExeNameCriticalSection

| Definition at line 32 of file client/cmdline.c. Referenced by GetConsoleInputExeNameW(), GetCurrentExeName(), InitExeName(), and SetConsoleInputExeNameW().

BOOLEAN ExeNameInitialized

| Definition at line 31 of file client/cmdline.c. Referenced by GetCurrentExeName(), and InitExeName().

USHORT ExeNameLength

| Definition at line 34 of file client/cmdline.c. Referenced by GetConsoleInputExeNameW(), GetCurrentExeName(), InitExeName(), ReadChars(), ReadConsoleA(), ReadConsoleInternal(), ReadConsoleW(), SetConsoleInputExeNameW(), and SetUpAppName().

WCHAR StartDirBuffer[MAX_PATH+1]

| Definition at line 35 of file client/cmdline.c. Referenced by InitExeName(), and SetUpAppName().

USHORT StartDirLength

| Definition at line 36 of file client/cmdline.c. Referenced by InitExeName(), and SetUpAppName().