/* PRIVATE FUNCTIONS **********************************************************/
+#if 0
/* Get the size needed to copy a string to a capture buffer, including alignment */
static ULONG
IntStringSize(LPCVOID String,
BOOL Unicode)
{
ULONG Size = (Unicode ? wcslen(String) : strlen(String)) * sizeof(WCHAR);
- return (Size + 3) & -4;
+ return (Size + 3) & ~3;
}
+#endif
-
-/* Copy a string to a capture buffer */
static VOID
-IntCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer,
- LPCVOID String,
- BOOL Unicode,
- PUNICODE_STRING RequestString)
-{
- ULONG Size;
- if (Unicode)
- {
- Size = wcslen(String) * sizeof(WCHAR);
- CsrCaptureMessageBuffer(CaptureBuffer, (PVOID)String, Size, (PVOID *)&RequestString->Buffer);
- }
- else
- {
- Size = strlen(String);
- CsrAllocateMessagePointer(CaptureBuffer, Size * sizeof(WCHAR), (PVOID *)&RequestString->Buffer);
- Size = MultiByteToWideChar(CP_ACP, 0, String, Size, RequestString->Buffer, Size * sizeof(WCHAR))
- * sizeof(WCHAR);
- }
- RequestString->Length = RequestString->MaximumLength = (USHORT)Size;
-}
-
-
-static BOOL
-IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode)
+IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &ApiMessage.Data.ExpungeCommandHistoryRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+
+ if (lpExeName == NULL || NumChars == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
+ return;
}
- CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ ExpungeCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ ExpungeCommandHistoryRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ ExpungeCommandHistoryRequest->Unicode =
+ ExpungeCommandHistoryRequest->Unicode2 = bUnicode;
+
+ // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, ExpungeCommandHistoryRequest->ExeLength);
if (!CaptureBuffer)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return FALSE;
+ return;
}
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
- &ExpungeCommandHistoryRequest->ExeName);
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ ExpungeCommandHistoryRequest->ExeLength,
+ (PVOID)&ExpungeCommandHistoryRequest->ExeName);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory),
- sizeof(CONSOLE_EXPUNGECOMMANDHISTORY));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory),
+ sizeof(*ExpungeCommandHistoryRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status))
- {
- BaseSetLastNTError(Status);
- return FALSE;
- }
-
- return TRUE;
+ if (!NT_SUCCESS(ApiMessage.Status))
+ BaseSetLastNTError(ApiMessage.Status);
}
static DWORD
-IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode)
+IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &ApiMessage.Data.GetCommandHistoryRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- DWORD HistoryLength = cbHistory * (bUnicode ? 1 : sizeof(WCHAR));
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+
+ if (lpExeName == NULL || NumChars == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
- CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) +
- HistoryLength);
+ GetCommandHistoryRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ GetCommandHistoryRequest->HistoryLength = cbHistory;
+ GetCommandHistoryRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ GetCommandHistoryRequest->Unicode =
+ GetCommandHistoryRequest->Unicode2 = bUnicode;
+
+ // CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) +
+ // HistoryLength);
+ CaptureBuffer = CsrAllocateCaptureBuffer(2, GetCommandHistoryRequest->ExeLength +
+ GetCommandHistoryRequest->HistoryLength);
if (!CaptureBuffer)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
return 0;
}
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
- &GetCommandHistoryRequest->ExeName);
- GetCommandHistoryRequest->Length = HistoryLength;
- CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ GetCommandHistoryRequest->ExeLength,
+ (PVOID)&GetCommandHistoryRequest->ExeName);
+
+ CsrAllocateMessagePointer(CaptureBuffer, GetCommandHistoryRequest->HistoryLength,
(PVOID*)&GetCommandHistoryRequest->History);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory),
- sizeof(CONSOLE_GETCOMMANDHISTORY));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory),
+ sizeof(*GetCommandHistoryRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
CsrFreeCaptureBuffer(CaptureBuffer);
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return 0;
}
- if (bUnicode)
- {
- memcpy(lpHistory,
- GetCommandHistoryRequest->History,
- GetCommandHistoryRequest->Length);
- }
- else
- {
- WideCharToMultiByte(CP_ACP, 0,
- GetCommandHistoryRequest->History,
- GetCommandHistoryRequest->Length / sizeof(WCHAR),
- lpHistory,
- cbHistory,
- NULL, NULL);
- }
+ RtlCopyMemory(lpHistory,
+ GetCommandHistoryRequest->History,
+ GetCommandHistoryRequest->HistoryLength);
CsrFreeCaptureBuffer(CaptureBuffer);
- return GetCommandHistoryRequest->Length;
+ return GetCommandHistoryRequest->HistoryLength;
}
static DWORD
IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &ApiMessage.Data.GetCommandHistoryLengthRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+
+ if (lpExeName == NULL || NumChars == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
- CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ GetCommandHistoryLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ GetCommandHistoryLengthRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ GetCommandHistoryLengthRequest->Unicode =
+ GetCommandHistoryLengthRequest->Unicode2 = bUnicode;
+
+ // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, GetCommandHistoryLengthRequest->ExeLength);
if (!CaptureBuffer)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
return 0;
}
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
- &GetCommandHistoryLengthRequest->ExeName);
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ GetCommandHistoryLengthRequest->ExeLength,
+ (PVOID)&GetCommandHistoryLengthRequest->ExeName);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength),
- sizeof(CONSOLE_GETCOMMANDHISTORYLENGTH));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength),
+ sizeof(*GetCommandHistoryLengthRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return 0;
}
- return GetCommandHistoryLengthRequest->Length;
+ return GetCommandHistoryLengthRequest->HistoryLength;
}
static BOOL
IntSetConsoleNumberOfCommands(DWORD dwNumCommands,
LPCVOID lpExeName,
- BOOL bUnicode)
+ BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &ApiMessage.Data.SetHistoryNumberCommandsRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName))
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+
+ if (lpExeName == NULL || NumChars == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
- CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ SetHistoryNumberCommandsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands;
+ SetHistoryNumberCommandsRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ SetHistoryNumberCommandsRequest->Unicode =
+ SetHistoryNumberCommandsRequest->Unicode2 = bUnicode;
+
+ // CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode));
+ CaptureBuffer = CsrAllocateCaptureBuffer(1, SetHistoryNumberCommandsRequest->ExeLength);
if (!CaptureBuffer)
{
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
return FALSE;
}
- IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
- &SetHistoryNumberCommandsRequest->ExeName);
- SetHistoryNumberCommandsRequest->NumCommands = dwNumCommands;
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ SetHistoryNumberCommandsRequest->ExeLength,
+ (PVOID)&SetHistoryNumberCommandsRequest->ExeName);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands),
- sizeof(CONSOLE_SETHISTORYNUMBERCOMMANDS));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands),
+ sizeof(*SetHistoryNumberCommandsRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return FALSE;
}
/*
* @implemented (Undocumented)
*/
-BOOL
+VOID
WINAPI
-ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName)
+DECLSPEC_HOTPATCH
+ExpungeConsoleCommandHistoryW(IN LPCWSTR lpExeName)
{
- return IntExpungeConsoleCommandHistory(lpExeName, TRUE);
+ IntExpungeConsoleCommandHistory(lpExeName, TRUE);
}
/*
* @implemented (Undocumented)
*/
-BOOL
+VOID
WINAPI
-ExpungeConsoleCommandHistoryA(LPCSTR lpExeName)
+DECLSPEC_HOTPATCH
+ExpungeConsoleCommandHistoryA(IN LPCSTR lpExeName)
{
- return IntExpungeConsoleCommandHistory(lpExeName, FALSE);
+ IntExpungeConsoleCommandHistory(lpExeName, FALSE);
}
*/
DWORD
WINAPI
-GetConsoleCommandHistoryW(LPWSTR lpHistory,
- DWORD cbHistory,
- LPCWSTR lpExeName)
+DECLSPEC_HOTPATCH
+GetConsoleCommandHistoryW(OUT LPWSTR lpHistory,
+ IN DWORD cbHistory,
+ IN LPCWSTR lpExeName)
{
return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE);
}
*/
DWORD
WINAPI
-GetConsoleCommandHistoryA(LPSTR lpHistory,
- DWORD cbHistory,
- LPCSTR lpExeName)
+DECLSPEC_HOTPATCH
+GetConsoleCommandHistoryA(OUT LPSTR lpHistory,
+ IN DWORD cbHistory,
+ IN LPCSTR lpExeName)
{
return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE);
}
*/
DWORD
WINAPI
-GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName)
+DECLSPEC_HOTPATCH
+GetConsoleCommandHistoryLengthW(IN LPCWSTR lpExeName)
{
return IntGetConsoleCommandHistoryLength(lpExeName, TRUE);
}
*/
DWORD
WINAPI
-GetConsoleCommandHistoryLengthA(LPCSTR lpExeName)
+DECLSPEC_HOTPATCH
+GetConsoleCommandHistoryLengthA(IN LPCSTR lpExeName)
{
- return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR);
+ return IntGetConsoleCommandHistoryLength(lpExeName, FALSE);
}
*/
BOOL
WINAPI
-SetConsoleNumberOfCommandsW(DWORD dwNumCommands,
- LPCSTR lpExeName)
+DECLSPEC_HOTPATCH
+SetConsoleNumberOfCommandsW(IN DWORD dwNumCommands,
+ IN LPCWSTR lpExeName)
{
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE);
}
*/
BOOL
WINAPI
-SetConsoleNumberOfCommandsA(DWORD dwNumCommands,
- LPCWSTR lpExeName)
+DECLSPEC_HOTPATCH
+SetConsoleNumberOfCommandsA(IN DWORD dwNumCommands,
+ IN LPCSTR lpExeName)
{
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE);
}
/*
- * @unimplemented
+ * @implemented
*/
BOOL
WINAPI
+DECLSPEC_HOTPATCH
SetConsoleCommandHistoryMode(IN DWORD dwMode)
{
- STUB;
- return FALSE;
+ CONSOLE_API_MESSAGE ApiMessage;
+ PCONSOLE_SETHISTORYMODE SetHistoryModeRequest = &ApiMessage.Data.SetHistoryModeRequest;
+
+ SetHistoryModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+ SetHistoryModeRequest->Mode = dwMode;
+
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCommandHistoryMode),
+ sizeof(*SetHistoryModeRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
+ {
+ BaseSetLastNTError(ApiMessage.Status);
+ return FALSE;
+ }
+
+ return TRUE;
}
/* EOF */