#define NDEBUG
#include <debug.h>
-typedef struct tagHISTORY_BUFFER
+typedef struct _HISTORY_BUFFER
{
LIST_ENTRY ListEntry;
- WORD Position;
- WORD MaxEntries;
- WORD NumEntries;
+ UINT Position;
+ UINT MaxEntries;
+ UINT NumEntries;
PUNICODE_STRING Entries;
UNICODE_STRING ExeName;
} HISTORY_BUFFER, *PHISTORY_BUFFER;
/* FUNCTIONS *****************************************************************/
static PHISTORY_BUFFER
-HistoryCurrentBuffer(PCSRSS_CONSOLE Console)
+HistoryCurrentBuffer(PCONSOLE Console)
{
/* TODO: use actual EXE name sent from process that called ReadConsole */
UNICODE_STRING ExeName = { 14, 14, L"cmd.exe" };
}
static VOID
-HistoryAddEntry(PCSRSS_CONSOLE Console)
+HistoryAddEntry(PCONSOLE Console)
{
UNICODE_STRING NewEntry;
PHISTORY_BUFFER Hist;
}
static VOID
-HistoryGetCurrentEntry(PCSRSS_CONSOLE Console, PUNICODE_STRING Entry)
+HistoryGetCurrentEntry(PCONSOLE Console, PUNICODE_STRING Entry)
{
PHISTORY_BUFFER Hist;
if (!(Hist = HistoryCurrentBuffer(Console)) || Hist->NumEntries == 0)
}
static PHISTORY_BUFFER
-HistoryFindBuffer(PCSRSS_CONSOLE Console, PUNICODE_STRING ExeName)
+HistoryFindBuffer(PCONSOLE Console, PUNICODE_STRING ExeName)
{
PLIST_ENTRY Entry = Console->HistoryBuffers.Flink;
while (Entry != &Console->HistoryBuffers)
CSR_API(SrvGetConsoleCommandHistoryLength)
{
- PCSRSS_GET_COMMAND_HISTORY_LENGTH GetCommandHistoryLength = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLength;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
+ PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryLengthRequest;
+ PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+ PCONSOLE Console;
NTSTATUS Status;
PHISTORY_BUFFER Hist;
ULONG Length = 0;
INT i;
- if (!Win32CsrValidateBuffer(ProcessData,
- GetCommandHistoryLength->ExeName.Buffer,
- GetCommandHistoryLength->ExeName.Length, 1))
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&GetCommandHistoryLengthRequest->ExeName.Buffer,
+ GetCommandHistoryLengthRequest->ExeName.Length,
+ sizeof(BYTE)))
{
- return STATUS_ACCESS_VIOLATION;
+ return STATUS_INVALID_PARAMETER;
}
Status = ConioConsoleFromProcessData(ProcessData, &Console);
if (NT_SUCCESS(Status))
{
- Hist = HistoryFindBuffer(Console, &GetCommandHistoryLength->ExeName);
+ Hist = HistoryFindBuffer(Console, &GetCommandHistoryLengthRequest->ExeName);
if (Hist)
{
for (i = 0; i < Hist->NumEntries; i++)
Length += Hist->Entries[i].Length + sizeof(WCHAR);
}
- GetCommandHistoryLength->Length = Length;
+ GetCommandHistoryLengthRequest->Length = Length;
ConioUnlockConsole(Console);
}
return Status;
CSR_API(SrvGetConsoleCommandHistory)
{
- PCSRSS_GET_COMMAND_HISTORY GetCommandHistory = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistory;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
+ PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetCommandHistoryRequest;
+ PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+ PCONSOLE Console;
NTSTATUS Status;
PHISTORY_BUFFER Hist;
- PBYTE Buffer = (PBYTE)GetCommandHistory->History;
- ULONG BufferSize = GetCommandHistory->Length;
+ PBYTE Buffer = (PBYTE)GetCommandHistoryRequest->History;
+ ULONG BufferSize = GetCommandHistoryRequest->Length;
INT i;
- if (!Win32CsrValidateBuffer(ProcessData, Buffer, BufferSize, 1) ||
- !Win32CsrValidateBuffer(ProcessData,
- GetCommandHistory->ExeName.Buffer,
- GetCommandHistory->ExeName.Length, 1))
+ if ( !CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&GetCommandHistoryRequest->History,
+ GetCommandHistoryRequest->Length,
+ sizeof(BYTE)) ||
+ !CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&GetCommandHistoryRequest->ExeName.Buffer,
+ GetCommandHistoryRequest->ExeName.Length,
+ sizeof(BYTE)) )
{
- return STATUS_ACCESS_VIOLATION;
+ return STATUS_INVALID_PARAMETER;
}
Status = ConioConsoleFromProcessData(ProcessData, &Console);
if (NT_SUCCESS(Status))
{
- Hist = HistoryFindBuffer(Console, &GetCommandHistory->ExeName);
+ Hist = HistoryFindBuffer(Console, &GetCommandHistoryRequest->ExeName);
if (Hist)
{
for (i = 0; i < Hist->NumEntries; i++)
Buffer += sizeof(WCHAR);
}
}
- GetCommandHistory->Length = Buffer - (PBYTE)GetCommandHistory->History;
+ GetCommandHistoryRequest->Length = Buffer - (PBYTE)GetCommandHistoryRequest->History;
ConioUnlockConsole(Console);
}
return Status;
CSR_API(SrvExpungeConsoleCommandHistory)
{
- PCSRSS_EXPUNGE_COMMAND_HISTORY ExpungeCommandHistory = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistory;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
+ PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ExpungeCommandHistoryRequest;
+ PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+ PCONSOLE Console;
PHISTORY_BUFFER Hist;
NTSTATUS Status;
- if (!Win32CsrValidateBuffer(ProcessData,
- ExpungeCommandHistory->ExeName.Buffer,
- ExpungeCommandHistory->ExeName.Length, 1))
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&ExpungeCommandHistoryRequest->ExeName.Buffer,
+ ExpungeCommandHistoryRequest->ExeName.Length,
+ sizeof(BYTE)))
{
- return STATUS_ACCESS_VIOLATION;
+ return STATUS_INVALID_PARAMETER;
}
Status = ConioConsoleFromProcessData(ProcessData, &Console);
if (NT_SUCCESS(Status))
{
- Hist = HistoryFindBuffer(Console, &ExpungeCommandHistory->ExeName);
+ Hist = HistoryFindBuffer(Console, &ExpungeCommandHistoryRequest->ExeName);
HistoryDeleteBuffer(Hist);
ConioUnlockConsole(Console);
}
CSR_API(SrvSetConsoleNumberOfCommands)
{
- PCSRSS_SET_HISTORY_NUMBER_COMMANDS SetHistoryNumberCommands = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommands;
- PCSR_PROCESS ProcessData = CsrGetClientThread()->Process;
- PCSRSS_CONSOLE Console;
+ PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryNumberCommandsRequest;
+ PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
+ PCONSOLE Console;
PHISTORY_BUFFER Hist;
NTSTATUS Status;
- WORD MaxEntries = SetHistoryNumberCommands->NumCommands;
+ UINT MaxEntries = SetHistoryNumberCommandsRequest->NumCommands;
PUNICODE_STRING OldEntryList, NewEntryList;
- if (!Win32CsrValidateBuffer(ProcessData,
- SetHistoryNumberCommands->ExeName.Buffer,
- SetHistoryNumberCommands->ExeName.Length, 1))
+ if (!CsrValidateMessageBuffer(ApiMessage,
+ (PVOID*)&SetHistoryNumberCommandsRequest->ExeName.Buffer,
+ SetHistoryNumberCommandsRequest->ExeName.Length,
+ sizeof(BYTE)))
{
- return STATUS_ACCESS_VIOLATION;
+ return STATUS_INVALID_PARAMETER;
}
Status = ConioConsoleFromProcessData(ProcessData, &Console);
if (NT_SUCCESS(Status))
{
- Hist = HistoryFindBuffer(Console, &SetHistoryNumberCommands->ExeName);
+ Hist = HistoryFindBuffer(Console, &SetHistoryNumberCommandsRequest->ExeName);
if (Hist)
{
OldEntryList = Hist->Entries;
CSR_API(SrvGetConsoleHistory)
{
- PCSRSS_GET_HISTORY_INFO GetHistoryInfo = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetHistoryInfo;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+ PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
+ PCONSOLE Console;
+ NTSTATUS Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
if (NT_SUCCESS(Status))
{
- GetHistoryInfo->HistoryBufferSize = Console->HistoryBufferSize;
- GetHistoryInfo->NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
- GetHistoryInfo->dwFlags = Console->HistoryNoDup;
+ HistoryInfoRequest->HistoryBufferSize = Console->HistoryBufferSize;
+ HistoryInfoRequest->NumberOfHistoryBuffers = Console->NumberOfHistoryBuffers;
+ HistoryInfoRequest->dwFlags = Console->HistoryNoDup;
ConioUnlockConsole(Console);
}
return Status;
CSR_API(SrvSetConsoleHistory)
{
- PCSRSS_SET_HISTORY_INFO SetHistoryInfo = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetHistoryInfo;
- PCSRSS_CONSOLE Console;
- NTSTATUS Status = ConioConsoleFromProcessData(CsrGetClientThread()->Process, &Console);
+ PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.HistoryInfoRequest;
+ PCONSOLE Console;
+ NTSTATUS Status = ConioConsoleFromProcessData(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console);
if (NT_SUCCESS(Status))
{
- Console->HistoryBufferSize = (WORD)SetHistoryInfo->HistoryBufferSize;
- Console->NumberOfHistoryBuffers = (WORD)SetHistoryInfo->NumberOfHistoryBuffers;
- Console->HistoryNoDup = SetHistoryInfo->dwFlags & HISTORY_NO_DUP_FLAG;
+ Console->HistoryBufferSize = HistoryInfoRequest->HistoryBufferSize;
+ Console->NumberOfHistoryBuffers = HistoryInfoRequest->NumberOfHistoryBuffers;
+ Console->HistoryNoDup = HistoryInfoRequest->dwFlags & HISTORY_NO_DUP_FLAG;
ConioUnlockConsole(Console);
}
return Status;
}
static VOID
-LineInputSetPos(PCSRSS_CONSOLE Console, UINT Pos)
+LineInputSetPos(PCONSOLE Console, UINT Pos)
{
if (Pos != Console->LinePos && Console->Mode & ENABLE_ECHO_INPUT)
{
- PCSRSS_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
+ PCONSOLE_SCREEN_BUFFER Buffer = Console->ActiveBuffer;
UINT OldCursorX = Buffer->CurrentX;
UINT OldCursorY = Buffer->CurrentY;
INT XY = OldCursorY * Buffer->MaxX + OldCursorX;
}
static VOID
-LineInputEdit(PCSRSS_CONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
+LineInputEdit(PCONSOLE Console, UINT NumToDelete, UINT NumToInsert, WCHAR *Insertion)
{
UINT Pos = Console->LinePos;
UINT NewSize = Console->LineSize - NumToDelete + NumToInsert;
}
static VOID
-LineInputRecallHistory(PCSRSS_CONSOLE Console, INT Offset)
+LineInputRecallHistory(PCONSOLE Console, INT Offset)
{
PHISTORY_BUFFER Hist;
}
VOID FASTCALL
-LineInputKeyDown(PCSRSS_CONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
+LineInputKeyDown(PCONSOLE Console, KEY_EVENT_RECORD *KeyEvent)
{
UINT Pos = Console->LinePos;
PHISTORY_BUFFER Hist;