/* 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;
}
Size = MultiByteToWideChar(CP_ACP, 0, String, Size, RequestString->Buffer, Size * sizeof(WCHAR))
* sizeof(WCHAR);
}
- RequestString->Length = RequestString->MaximumLength = Size;
+ RequestString->Length = RequestString->MaximumLength = (USHORT)Size;
}
+#endif
-
-static BOOL
-IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode)
+static VOID
+IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
- PCSRSS_EXPUNGE_COMMAND_HISTORY ExpungeCommandHistory = &ApiMessage.Data.ExpungeCommandHistory;
+ 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,
- &ExpungeCommandHistory->ExeName);
+ // 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(CSRSS_EXPUNGE_COMMAND_HISTORY));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepExpungeCommandHistory),
+ sizeof(*ExpungeCommandHistoryRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.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;
- PCSRSS_GET_COMMAND_HISTORY GetCommandHistory = &ApiMessage.Data.GetCommandHistory;
+ 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,
- &GetCommandHistory->ExeName);
- GetCommandHistory->Length = HistoryLength;
- CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
- (PVOID*)&GetCommandHistory->History);
-
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistory),
- sizeof(CSRSS_GET_COMMAND_HISTORY));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
+ // &GetCommandHistoryRequest->ExeName);
+ CsrCaptureMessageBuffer(CaptureBuffer,
+ (PVOID)lpExeName,
+ GetCommandHistoryRequest->ExeLength,
+ (PVOID)&GetCommandHistoryRequest->ExeName);
+
+ // CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
+ CsrAllocateMessagePointer(CaptureBuffer, GetCommandHistoryRequest->HistoryLength,
+ (PVOID*)&GetCommandHistoryRequest->History);
+
+ 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,
- GetCommandHistory->History,
- GetCommandHistory->Length);
- }
- else
- {
- WideCharToMultiByte(CP_ACP, 0,
- GetCommandHistory->History,
- GetCommandHistory->Length / sizeof(WCHAR),
- lpHistory,
- cbHistory,
- NULL, NULL);
- }
+ RtlCopyMemory(lpHistory,
+ GetCommandHistoryRequest->History,
+ GetCommandHistoryRequest->HistoryLength);
CsrFreeCaptureBuffer(CaptureBuffer);
- return GetCommandHistory->Length;
+ return GetCommandHistoryRequest->HistoryLength;
}
static DWORD
IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
- PCSRSS_GET_COMMAND_HISTORY_LENGTH GetCommandHistoryLength = &ApiMessage.Data.GetCommandHistoryLength;
+ 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,
- &GetCommandHistoryLength->ExeName);
+ // 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(CSRSS_GET_COMMAND_HISTORY_LENGTH));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCommandHistoryLength),
+ sizeof(*GetCommandHistoryLengthRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return 0;
}
- return GetCommandHistoryLength->Length;
+ return GetCommandHistoryLengthRequest->HistoryLength;
}
static BOOL
IntSetConsoleNumberOfCommands(DWORD dwNumCommands,
LPCVOID lpExeName,
- BOOL bUnicode)
+ BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
- PCSRSS_SET_HISTORY_NUMBER_COMMANDS SetHistoryNumberCommands = &ApiMessage.Data.SetHistoryNumberCommands;
+ 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,
- &SetHistoryNumberCommands->ExeName);
- SetHistoryNumberCommands->NumCommands = dwNumCommands;
+ // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
+ // &SetHistoryNumberCommandsRequest->ExeName);
+ 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(CSRSS_SET_HISTORY_NUMBER_COMMANDS));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetNumberOfCommands),
+ sizeof(*SetHistoryNumberCommandsRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return FALSE;
}
/*
* @implemented (Undocumented)
*/
-BOOL
+VOID
WINAPI
ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName)
{
- return IntExpungeConsoleCommandHistory(lpExeName, TRUE);
+ IntExpungeConsoleCommandHistory(lpExeName, TRUE);
}
/*
* @implemented (Undocumented)
*/
-BOOL
+VOID
WINAPI
ExpungeConsoleCommandHistoryA(LPCSTR lpExeName)
{
- return IntExpungeConsoleCommandHistory(lpExeName, FALSE);
+ IntExpungeConsoleCommandHistory(lpExeName, FALSE);
}
WINAPI
GetConsoleCommandHistoryLengthA(LPCSTR lpExeName)
{
- return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR);
+ return IntGetConsoleCommandHistoryLength(lpExeName, FALSE);
}
BOOL
WINAPI
SetConsoleNumberOfCommandsW(DWORD dwNumCommands,
- LPCSTR lpExeName)
+ LPCWSTR lpExeName)
{
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE);
}
BOOL
WINAPI
SetConsoleNumberOfCommandsA(DWORD dwNumCommands,
- LPCWSTR lpExeName)
+ LPCSTR lpExeName)
{
return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE);
}
/*
- * @unimplemented
+ * @implemented
*/
BOOL
WINAPI
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 */