2012-11-15 16:29:21 +00:00
|
|
|
/*
|
1999-03-06 10:57:02 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2012-11-15 16:29:21 +00:00
|
|
|
* FILE: dll/win32/kernel32/client/console/console.c
|
1999-03-06 10:57:02 +00:00
|
|
|
* PURPOSE: Win32 server console functions
|
2013-04-10 20:33:30 +00:00
|
|
|
* PROGRAMMERS: James Tabor
|
2012-11-15 16:29:21 +00:00
|
|
|
* <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2012-11-15 16:29:21 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
1999-12-26 15:50:53 +00:00
|
|
|
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
2000-03-22 18:36:00 +00:00
|
|
|
|
2012-11-15 23:06:49 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
1999-03-30 21:58:05 +00:00
|
|
|
|
2013-02-10 13:59:09 +00:00
|
|
|
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
2005-01-03 23:02:15 +00:00
|
|
|
extern RTL_CRITICAL_SECTION ConsoleLock;
|
2008-07-30 15:00:57 +00:00
|
|
|
extern BOOL ConsoleInitialized;
|
2003-08-16 17:37:51 +00:00
|
|
|
extern BOOL WINAPI IsDebuggerPresent(VOID);
|
2003-08-13 06:53:54 +00:00
|
|
|
|
2013-01-16 00:16:06 +00:00
|
|
|
/* Console reserved "file" names */
|
|
|
|
static LPCWSTR BaseConFileName = CONSOLE_FILE_NAME;
|
|
|
|
static LPCWSTR BaseConInputFileName = CONSOLE_INPUT_FILE_NAME;
|
|
|
|
static LPCWSTR BaseConOutputFileName = CONSOLE_OUTPUT_FILE_NAME;
|
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
PHANDLER_ROUTINE InitialHandler[1];
|
|
|
|
PHANDLER_ROUTINE* CtrlHandlers;
|
|
|
|
ULONG NrCtrlHandlers;
|
|
|
|
ULONG NrAllocatedHandlers;
|
|
|
|
|
2013-01-01 23:36:19 +00:00
|
|
|
HANDLE InputWaitHandle = INVALID_HANDLE_VALUE;
|
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
#define INPUTEXENAME_BUFLEN 256
|
2011-11-11 12:22:05 +00:00
|
|
|
static WCHAR InputExeName[INPUTEXENAME_BUFLEN];
|
2001-04-04 22:21:32 +00:00
|
|
|
|
2013-02-10 13:59:09 +00:00
|
|
|
|
2012-11-15 16:29:21 +00:00
|
|
|
/* Default Console Control Handler ********************************************/
|
2003-08-09 04:13:24 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
DefaultConsoleCtrlHandler(DWORD Event)
|
|
|
|
{
|
2010-03-10 06:50:15 +00:00
|
|
|
DPRINT("Default handler called: %lx\n", Event);
|
2009-01-30 14:25:00 +00:00
|
|
|
switch(Event)
|
|
|
|
{
|
|
|
|
case CTRL_C_EVENT:
|
|
|
|
DPRINT("Ctrl-C Event\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CTRL_BREAK_EVENT:
|
|
|
|
DPRINT("Ctrl-Break Event\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CTRL_CLOSE_EVENT:
|
|
|
|
DPRINT("Ctrl Close Event\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CTRL_LOGOFF_EVENT:
|
2010-03-10 06:50:15 +00:00
|
|
|
DPRINT("Ctrl Logoff Event\n");
|
2009-01-30 14:25:00 +00:00
|
|
|
break;
|
2013-01-03 17:42:27 +00:00
|
|
|
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
|
|
|
DPRINT("Ctrl Shutdown Event\n");
|
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
ExitProcess(CONTROL_C_EXIT);
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 23:06:49 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
DWORD nExitCode = 0;
|
2012-11-15 23:06:49 +00:00
|
|
|
DWORD CodeAndFlag = PtrToUlong(lpThreadParameter);
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD nCode = CodeAndFlag & MAXLONG;
|
|
|
|
UINT i;
|
2010-03-09 20:13:19 +00:00
|
|
|
EXCEPTION_RECORD erException;
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2013-01-01 23:36:19 +00:00
|
|
|
DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag, nCode);
|
2009-01-30 14:25:00 +00:00
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
|
|
|
|
|
|
|
|
switch(nCode)
|
|
|
|
{
|
|
|
|
case CTRL_C_EVENT:
|
|
|
|
case CTRL_BREAK_EVENT:
|
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
if (IsDebuggerPresent())
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
erException.ExceptionCode = (nCode == CTRL_C_EVENT ?
|
|
|
|
DBG_CONTROL_C : DBG_CONTROL_BREAK);
|
2009-01-30 14:25:00 +00:00
|
|
|
erException.ExceptionFlags = 0;
|
|
|
|
erException.ExceptionRecord = NULL;
|
2010-03-09 20:13:19 +00:00
|
|
|
erException.ExceptionAddress = DefaultConsoleCtrlHandler;
|
2009-01-30 14:25:00 +00:00
|
|
|
erException.NumberParameters = 0;
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
RtlRaiseException(&erException);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
if ((nCode != CTRL_C_EVENT) ||
|
|
|
|
(NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
|
|
|
|
{
|
|
|
|
for (i = NrCtrlHandlers; i > 0; i--)
|
|
|
|
{
|
|
|
|
if (CtrlHandlers[i - 1](nCode)) break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
ExitThread(0);
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2010-03-09 20:13:19 +00:00
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case CTRL_CLOSE_EVENT:
|
|
|
|
case CTRL_LOGOFF_EVENT:
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
|
|
|
break;
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
case 3:
|
|
|
|
ExitThread(0);
|
|
|
|
break;
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
case 4:
|
|
|
|
ExitProcess(CONTROL_C_EXIT);
|
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
ASSERT(ConsoleInitialized);
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
2013-03-10 15:37:22 +00:00
|
|
|
|
2010-03-09 20:13:19 +00:00
|
|
|
nExitCode = 0;
|
|
|
|
if ((nCode != CTRL_C_EVENT) || (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
for (i = NrCtrlHandlers; i > 0; i--)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
if ((i == 1) &&
|
|
|
|
(CodeAndFlag & MINLONG) &&
|
|
|
|
((nCode == CTRL_LOGOFF_EVENT) || (nCode == CTRL_SHUTDOWN_EVENT)))
|
|
|
|
{
|
2010-03-10 06:50:15 +00:00
|
|
|
DPRINT("Skipping system/service apps\n");
|
2009-01-30 14:25:00 +00:00
|
|
|
break;
|
2010-03-09 20:13:19 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
if (CtrlHandlers[i - 1](nCode))
|
|
|
|
{
|
|
|
|
switch(nCode)
|
|
|
|
{
|
|
|
|
case CTRL_CLOSE_EVENT:
|
|
|
|
case CTRL_LOGOFF_EVENT:
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
2010-03-09 20:13:19 +00:00
|
|
|
case 3:
|
2009-01-30 14:25:00 +00:00
|
|
|
nExitCode = CodeAndFlag;
|
2010-03-09 20:13:19 +00:00
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 23:06:49 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
2013-03-10 15:37:22 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
ExitThread(nExitCode);
|
2012-11-15 23:06:49 +00:00
|
|
|
return STATUS_SUCCESS;
|
2003-08-16 17:37:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 23:36:19 +00:00
|
|
|
VOID
|
|
|
|
WINAPI
|
|
|
|
InitConsoleCtrlHandling(VOID)
|
|
|
|
{
|
|
|
|
/* Initialize Console Ctrl Handler */
|
|
|
|
NrAllocatedHandlers = NrCtrlHandlers = 1;
|
|
|
|
CtrlHandlers = InitialHandler;
|
|
|
|
CtrlHandlers[0] = DefaultConsoleCtrlHandler;
|
|
|
|
}
|
|
|
|
|
2003-08-16 17:37:51 +00:00
|
|
|
|
2012-11-15 16:51:29 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2003-07-10 18:50:51 +00:00
|
|
|
|
2013-01-16 00:16:06 +00:00
|
|
|
LPCWSTR
|
|
|
|
IntCheckForConsoleFileName(IN LPCWSTR pszName,
|
|
|
|
IN DWORD dwDesiredAccess)
|
|
|
|
{
|
|
|
|
LPCWSTR ConsoleName = pszName;
|
|
|
|
ULONG DeviceNameInfo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether we deal with a DOS device, and if so,
|
|
|
|
* strip the path till the file name.
|
|
|
|
* Therefore, things like \\.\CON or C:\some_path\CONIN$
|
|
|
|
* are transformed into CON or CONIN$, for example.
|
|
|
|
*/
|
|
|
|
DeviceNameInfo = RtlIsDosDeviceName_U(pszName);
|
|
|
|
if (DeviceNameInfo != 0)
|
|
|
|
{
|
2013-01-16 22:25:12 +00:00
|
|
|
ConsoleName = (LPCWSTR)((ULONG_PTR)ConsoleName + ((DeviceNameInfo >> 16) & 0xFFFF));
|
2013-01-16 00:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a standard console "file" name according to what we passed in parameters */
|
|
|
|
if (_wcsicmp(ConsoleName, BaseConInputFileName) == 0)
|
|
|
|
{
|
|
|
|
return BaseConInputFileName;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(ConsoleName, BaseConOutputFileName) == 0)
|
|
|
|
{
|
|
|
|
return BaseConOutputFileName;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(ConsoleName, BaseConFileName) == 0)
|
|
|
|
{
|
|
|
|
if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) == GENERIC_READ)
|
|
|
|
{
|
|
|
|
return BaseConInputFileName;
|
|
|
|
}
|
|
|
|
else if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) == GENERIC_WRITE)
|
|
|
|
{
|
|
|
|
return BaseConOutputFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are there, that means that either the file name or the desired access are wrong */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
2013-05-30 00:50:03 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://undoc.airesoft.co.uk/kernel32.dll/ConsoleMenuControl.php
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-05-30 00:50:03 +00:00
|
|
|
HMENU
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2013-05-30 00:50:03 +00:00
|
|
|
ConsoleMenuControl(HANDLE hConsoleOutput,
|
|
|
|
DWORD dwCmdIdLow,
|
|
|
|
DWORD dwCmdIdHigh)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-05-30 00:50:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_MENUCONTROL MenuControlRequest = &ApiMessage.Data.MenuControlRequest;
|
|
|
|
|
|
|
|
MenuControlRequest->OutputHandle = hConsoleOutput;
|
|
|
|
MenuControlRequest->dwCmdIdLow = dwCmdIdLow;
|
|
|
|
MenuControlRequest->dwCmdIdHigh = dwCmdIdHigh;
|
|
|
|
MenuControlRequest->hMenu = NULL;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepMenuControl),
|
|
|
|
sizeof(CONSOLE_MENUCONTROL));
|
|
|
|
|
|
|
|
return MenuControlRequest->hMenu;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
DuplicateConsoleHandle(HANDLE hConsole,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
DWORD dwOptions)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest = &ApiMessage.Data.DuplicateHandleRequest;
|
2003-03-09 21:37:18 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
if ( (dwOptions & ~(DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) ||
|
|
|
|
(!(dwOptions & DUPLICATE_SAME_ACCESS) &&
|
|
|
|
(dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))) )
|
2003-03-09 21:37:18 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError (ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
2003-03-09 21:37:18 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
DuplicateHandleRequest->ConsoleHandle = hConsole;
|
2012-11-17 23:07:59 +00:00
|
|
|
DuplicateHandleRequest->Access = dwDesiredAccess;
|
|
|
|
DuplicateHandleRequest->Inheritable = bInheritHandle;
|
|
|
|
DuplicateHandleRequest->Options = dwOptions;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-30 14:25:00 +00:00
|
|
|
NULL,
|
2012-11-17 23:07:59 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepDuplicateHandle),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_DUPLICATEHANDLE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-03-09 21:37:18 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2003-03-09 21:37:18 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return DuplicateHandleRequest->ConsoleHandle;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-04-01 00:23:34 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-04-01 00:23:34 +00:00
|
|
|
BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2013-04-01 00:23:34 +00:00
|
|
|
GetConsoleDisplayMode(LPDWORD lpModeFlags)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-04-01 00:23:34 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETDISPLAYMODE GetDisplayModeRequest = &ApiMessage.Data.GetDisplayModeRequest;
|
|
|
|
|
2013-04-09 15:21:14 +00:00
|
|
|
if (lpModeFlags == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-01 00:23:34 +00:00
|
|
|
// GetDisplayModeRequest->OutputHandle = hConsoleOutput;
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetDisplayMode),
|
|
|
|
sizeof(CONSOLE_GETDISPLAYMODE));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpModeFlags = GetDisplayModeRequest->DisplayMode;
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @unimplemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2013-06-16 21:35:18 +00:00
|
|
|
GetConsoleFontInfo(HANDLE hConsoleOutput,
|
|
|
|
BOOL bMaximumWindow,
|
|
|
|
DWORD nFontCount,
|
|
|
|
PCONSOLE_FONT_INFO lpConsoleFontInfo)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-16 21:35:18 +00:00
|
|
|
DPRINT1("GetConsoleFontInfo(0x%x, %d, %d, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, nFontCount, lpConsoleFontInfo);
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
COORD
|
|
|
|
WINAPI
|
2002-08-22 15:21:57 +00:00
|
|
|
GetConsoleFontSize(HANDLE hConsoleOutput,
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD nFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
COORD Empty = {0, 0};
|
|
|
|
DPRINT1("GetConsoleFontSize(0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return Empty;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @implemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-04-09 15:21:14 +00:00
|
|
|
BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2013-01-05 23:10:12 +00:00
|
|
|
GetConsoleHardwareState(HANDLE hConsoleOutput,
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD Flags,
|
|
|
|
PDWORD State)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &ApiMessage.Data.HardwareStateRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-04-01 00:23:34 +00:00
|
|
|
DPRINT1("GetConsoleHardwareState(%d, 0x%p) UNIMPLEMENTED!\n", Flags, State);
|
|
|
|
|
2013-04-09 15:21:14 +00:00
|
|
|
if (State == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
HardwareStateRequest->OutputHandle = hConsoleOutput;
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-30 14:25:00 +00:00
|
|
|
NULL,
|
2012-11-17 23:07:59 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHardwareState),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETHWSTATE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
*State = HardwareStateRequest->State;
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @implemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
GetConsoleInputWaitHandle(VOID)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-01-01 23:36:19 +00:00
|
|
|
return InputWaitHandle;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2013-06-16 21:35:18 +00:00
|
|
|
BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2002-08-22 15:21:57 +00:00
|
|
|
GetCurrentConsoleFont(HANDLE hConsoleOutput,
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL bMaximumWindow,
|
|
|
|
PCONSOLE_FONT_INFO lpConsoleCurrentFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
DPRINT1("GetCurrentConsoleFont(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", hConsoleOutput, bMaximumWindow, lpConsoleCurrentFont);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @unimplemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
ULONG
|
|
|
|
WINAPI
|
|
|
|
GetNumberOfConsoleFonts(VOID)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
DPRINT1("GetNumberOfConsoleFonts() UNIMPLEMENTED!\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
2012-11-17 23:29:53 +00:00
|
|
|
return 1;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-05-29 00:29:07 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-05-29 00:29:07 +00:00
|
|
|
BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2013-05-29 00:29:07 +00:00
|
|
|
InvalidateConsoleDIBits(IN HANDLE hConsoleOutput,
|
|
|
|
IN PSMALL_RECT lpRect)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-05-29 00:29:07 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest = &ApiMessage.Data.InvalidateDIBitsRequest;
|
|
|
|
|
|
|
|
if (lpRect == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateDIBitsRequest->OutputHandle = hConsoleOutput;
|
|
|
|
InvalidateDIBitsRequest->Region = *lpRect;
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepInvalidateBitMapRect),
|
|
|
|
sizeof(CONSOLE_INVALIDATEDIBITS));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented (Undocumented)
|
|
|
|
*/
|
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
OpenConsoleW(LPCWSTR wsName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
DWORD dwShareMode)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2012-11-17 22:42:04 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_OPENCONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
|
2012-12-30 13:25:50 +00:00
|
|
|
CONSOLE_HANDLE_TYPE HandleType;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2013-01-16 00:16:06 +00:00
|
|
|
if (wsName && 0 == _wcsicmp(wsName, BaseConInputFileName))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-17 22:42:04 +00:00
|
|
|
HandleType = HANDLE_INPUT;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2013-01-16 00:16:06 +00:00
|
|
|
else if (wsName && 0 == _wcsicmp(wsName, BaseConOutputFileName))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-17 22:42:04 +00:00
|
|
|
HandleType = HANDLE_OUTPUT;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2012-11-17 22:42:04 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 00:16:06 +00:00
|
|
|
if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)) ||
|
|
|
|
(dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) )
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2012-11-17 22:42:04 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 22:42:04 +00:00
|
|
|
OpenConsoleRequest->HandleType = HandleType;
|
|
|
|
OpenConsoleRequest->Access = dwDesiredAccess;
|
|
|
|
OpenConsoleRequest->Inheritable = bInheritHandle;
|
|
|
|
OpenConsoleRequest->ShareMode = dwShareMode;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 22:42:04 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-30 14:25:00 +00:00
|
|
|
NULL,
|
2012-11-17 22:42:04 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepOpenConsole),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_OPENCONSOLE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return OpenConsoleRequest->ConsoleHandle;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-06-01 22:49:50 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleCursor.php
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-06-01 22:49:50 +00:00
|
|
|
SetConsoleCursor(HANDLE hConsoleOutput,
|
|
|
|
HCURSOR hCursor)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-01 22:49:50 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETCURSOR SetCursorRequest = &ApiMessage.Data.SetCursorRequest;
|
|
|
|
|
|
|
|
SetCursorRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetCursorRequest->hCursor = hCursor;
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursor),
|
|
|
|
sizeof(CONSOLE_SETCURSOR));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-04-01 00:23:34 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-04-01 00:23:34 +00:00
|
|
|
SetConsoleDisplayMode(HANDLE hConsoleOutput,
|
|
|
|
DWORD dwFlags,
|
|
|
|
PCOORD lpNewScreenBufferDimensions)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-04-01 00:23:34 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest = &ApiMessage.Data.SetDisplayModeRequest;
|
|
|
|
|
|
|
|
SetDisplayModeRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetDisplayModeRequest->DisplayMode = dwFlags;
|
2013-04-14 14:49:30 +00:00
|
|
|
SetDisplayModeRequest->NewSBDim.X = 0;
|
|
|
|
SetDisplayModeRequest->NewSBDim.Y = 0;
|
2013-04-01 00:23:34 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetDisplayMode),
|
|
|
|
sizeof(CONSOLE_SETDISPLAYMODE));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-09 15:21:14 +00:00
|
|
|
if (lpNewScreenBufferDimensions)
|
|
|
|
*lpNewScreenBufferDimensions = SetDisplayModeRequest->NewSBDim;
|
|
|
|
|
2013-04-01 00:23:34 +00:00
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @unimplemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-06-16 21:35:18 +00:00
|
|
|
SetConsoleFont(HANDLE hConsoleOutput,
|
|
|
|
DWORD nFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-16 21:35:18 +00:00
|
|
|
DPRINT1("SetConsoleFont(0x%x, %d) UNIMPLEMENTED!\n", hConsoleOutput, nFont);
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @implemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-01-05 23:10:12 +00:00
|
|
|
SetConsoleHardwareState(HANDLE hConsoleOutput,
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD Flags,
|
|
|
|
DWORD State)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETHWSTATE HardwareStateRequest = &ApiMessage.Data.HardwareStateRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-04-01 00:23:34 +00:00
|
|
|
DPRINT1("SetConsoleHardwareState(%d, %d) UNIMPLEMENTED!\n", Flags, State);
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
HardwareStateRequest->OutputHandle = hConsoleOutput;
|
|
|
|
HardwareStateRequest->State = State;
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-30 14:25:00 +00:00
|
|
|
NULL,
|
2012-11-17 23:07:59 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHardwareState),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETHWSTATE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-01-30 14:25:00 +00:00
|
|
|
* @unimplemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleKeyShortcuts(DWORD Unknown0,
|
|
|
|
DWORD Unknown1,
|
|
|
|
DWORD Unknown2,
|
|
|
|
DWORD Unknown3)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
DPRINT1("SetConsoleKeyShortcuts(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-06-01 22:49:50 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://undoc.airesoft.co.uk/kernel32.dll/SetConsoleMaximumWindowSize.php
|
|
|
|
* Does nothing, returns TRUE only. Checked on Windows Server 2003.
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-06-01 22:49:50 +00:00
|
|
|
SetConsoleMaximumWindowSize(HANDLE hConsoleOutput,
|
|
|
|
COORD dwMaximumSize)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-01 22:49:50 +00:00
|
|
|
DPRINT1("SetConsoleMaximumWindowSize(0x%x, {%d, %d}) does nothing\n",
|
|
|
|
hConsoleOutput, dwMaximumSize.X, dwMaximumSize.Y);
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-05-30 00:50:03 +00:00
|
|
|
* @implemented (Undocumented)
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-05-30 00:50:03 +00:00
|
|
|
SetConsoleMenuClose(BOOL bEnable)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-05-30 00:50:03 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &ApiMessage.Data.SetMenuCloseRequest;
|
|
|
|
|
|
|
|
SetMenuCloseRequest->Enable = bEnable;
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMenuClose),
|
|
|
|
sizeof(CONSOLE_SETMENUCLOSE));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-08-12 19:31:54 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
|
|
|
|
* Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2013-08-12 19:31:54 +00:00
|
|
|
SetConsolePalette(HANDLE hConsoleOutput,
|
|
|
|
HPALETTE hPalette,
|
|
|
|
UINT dwUsage)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-08-12 19:31:54 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETPALETTE SetPaletteRequest = &ApiMessage.Data.SetPaletteRequest;
|
|
|
|
|
|
|
|
SetPaletteRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetPaletteRequest->PaletteHandle = hPalette;
|
|
|
|
SetPaletteRequest->Usage = dwUsage;
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetPalette),
|
|
|
|
sizeof(CONSOLE_SETPALETTE));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
2013-06-01 22:49:50 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-06-01 22:49:50 +00:00
|
|
|
INT
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2013-06-01 22:49:50 +00:00
|
|
|
ShowConsoleCursor(HANDLE hConsoleOutput,
|
|
|
|
BOOL bShow)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-01 22:49:50 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SHOWCURSOR ShowCursorRequest = &ApiMessage.Data.ShowCursorRequest;
|
|
|
|
|
|
|
|
ShowCursorRequest->OutputHandle = hConsoleOutput;
|
|
|
|
ShowCursorRequest->Show = bShow;
|
|
|
|
ShowCursorRequest->RefCount = 0;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepShowCursor),
|
|
|
|
sizeof(CONSOLE_SHOWCURSOR));
|
|
|
|
|
|
|
|
return ShowCursorRequest->RefCount;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-03-05 22:51:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: Checks whether the given handle is a valid console handle.
|
2012-11-17 23:29:53 +00:00
|
|
|
*
|
2003-03-05 22:51:48 +00:00
|
|
|
* ARGUMENTS:
|
|
|
|
* Handle - Handle to be checked
|
2012-11-17 23:29:53 +00:00
|
|
|
*
|
2003-03-05 22:51:48 +00:00
|
|
|
* RETURNS:
|
|
|
|
* TRUE: Handle is a valid console handle
|
|
|
|
* FALSE: Handle is not a valid console handle.
|
2012-11-17 23:29:53 +00:00
|
|
|
*
|
2003-03-05 22:51:48 +00:00
|
|
|
* STATUS: Officially undocumented
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2003-03-05 22:51:48 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2003-03-05 22:51:48 +00:00
|
|
|
VerifyConsoleIoHandle(HANDLE Handle)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.VerifyHandleRequest.ConsoleHandle = Handle;
|
2002-08-22 15:21:57 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 18:06:17 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepVerifyIoHandle),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_VERIFYHANDLE));
|
2012-11-15 18:06:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2002-08-22 15:21:57 +00:00
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
return TRUE;
|
2004-11-02 20:42:06 +00:00
|
|
|
}
|
2002-08-22 15:21:57 +00:00
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
2004-11-02 20:42:06 +00:00
|
|
|
*/
|
2012-11-15 18:06:17 +00:00
|
|
|
DWORD
|
2004-11-02 20:42:06 +00:00
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
WriteConsoleInputVDMA(DWORD Unknown0,
|
|
|
|
DWORD Unknown1,
|
|
|
|
DWORD Unknown2,
|
|
|
|
DWORD Unknown3)
|
2004-11-02 20:42:06 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
DPRINT1("WriteConsoleInputVDMA(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
2012-11-15 18:06:17 +00:00
|
|
|
DWORD
|
1999-03-06 10:57:02 +00:00
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
WriteConsoleInputVDMW(DWORD Unknown0,
|
|
|
|
DWORD Unknown1,
|
|
|
|
DWORD Unknown2,
|
|
|
|
DWORD Unknown3)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
DPRINT1("WriteConsoleInputVDMW(0x%x, 0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2, Unknown3);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
CloseConsoleHandle(HANDLE Handle)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.CloseHandleRequest.ConsoleHandle = Handle;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 18:06:17 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCloseHandle),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_CLOSEHANDLE));
|
2012-11-15 18:06:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2002-10-20 00:34:40 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
GetStdHandle(DWORD nStdHandle)
|
2012-11-17 23:29:53 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Get a handle for the standard input, standard output
|
|
|
|
* and a standard error device.
|
|
|
|
*
|
|
|
|
* ARGUMENTS:
|
|
|
|
* nStdHandle - Specifies the device for which to return the handle.
|
|
|
|
*
|
|
|
|
* RETURNS: If the function succeeds, the return value is the handle
|
|
|
|
* of the specified device. Otherwise the value is INVALID_HANDLE_VALUE.
|
|
|
|
*/
|
2012-11-15 18:06:17 +00:00
|
|
|
{
|
2013-02-10 12:36:57 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
switch (nStdHandle)
|
|
|
|
{
|
|
|
|
case STD_INPUT_HANDLE:
|
|
|
|
return Ppb->StandardInput;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_OUTPUT_HANDLE:
|
|
|
|
return Ppb->StandardOutput;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_ERROR_HANDLE:
|
|
|
|
return Ppb->StandardError;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 01:39:49 +00:00
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
2012-11-15 18:06:17 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
2012-11-15 18:06:17 +00:00
|
|
|
WINAPI
|
|
|
|
SetStdHandle(DWORD nStdHandle,
|
|
|
|
HANDLE hHandle)
|
2012-11-17 23:29:53 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Set the handle for the standard input, standard output or
|
|
|
|
* the standard error device.
|
|
|
|
*
|
|
|
|
* ARGUMENTS:
|
|
|
|
* nStdHandle - Specifies the handle to be set.
|
|
|
|
* hHandle - The handle to set.
|
|
|
|
*
|
|
|
|
* RETURNS: TRUE if the function succeeds, FALSE otherwise.
|
|
|
|
*/
|
2012-11-15 18:06:17 +00:00
|
|
|
{
|
2013-02-10 12:36:57 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/* no need to check if hHandle == INVALID_HANDLE_VALUE */
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
switch (nStdHandle)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_INPUT_HANDLE:
|
|
|
|
Ppb->StandardInput = hHandle;
|
|
|
|
return TRUE;
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_OUTPUT_HANDLE:
|
|
|
|
Ppb->StandardOutput = hHandle;
|
|
|
|
return TRUE;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_ERROR_HANDLE:
|
|
|
|
Ppb->StandardError = hHandle;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
/* Windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
|
2012-11-15 18:06:17 +00:00
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-11-02 20:42:06 +00:00
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*--------------------------------------------------------------
|
|
|
|
* AllocConsole
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
AllocConsole(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2013-02-10 12:36:57 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_ALLOCCONSOLE AllocConsoleRequest = &ApiMessage.Data.AllocConsoleRequest;
|
2013-02-10 12:36:57 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
if (Parameters->ConsoleHandle)
|
2012-11-15 18:06:17 +00:00
|
|
|
{
|
2013-02-10 12:36:57 +00:00
|
|
|
DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
|
2013-01-13 17:07:25 +00:00
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
2012-11-15 18:06:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2013-03-24 17:08:10 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO));
|
2013-02-10 12:36:57 +00:00
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
sizeof(CONSOLE_START_INFO),
|
|
|
|
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2013-06-16 17:16:33 +00:00
|
|
|
InitConsoleInfo(AllocConsoleRequest->ConsoleStartInfo,
|
|
|
|
&Parameters->ImagePathName);
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2013-07-06 19:57:38 +00:00
|
|
|
AllocConsoleRequest->ConsoleHandle = NULL;
|
2013-01-01 23:36:19 +00:00
|
|
|
AllocConsoleRequest->CtrlDispatcher = ConsoleControlDispatcher;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
AllocConsoleRequest->PropDispatcher = PropDialogHandler;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2013-02-10 12:36:57 +00:00
|
|
|
CaptureBuffer,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAlloc),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_ALLOCCONSOLE));
|
2013-02-10 12:36:57 +00:00
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2013-07-06 19:57:38 +00:00
|
|
|
Parameters->ConsoleHandle = AllocConsoleRequest->ConsoleHandle;
|
2013-01-01 23:36:19 +00:00
|
|
|
SetStdHandle(STD_INPUT_HANDLE , AllocConsoleRequest->InputHandle );
|
2012-11-17 23:29:53 +00:00
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, AllocConsoleRequest->OutputHandle);
|
2013-01-01 23:36:19 +00:00
|
|
|
SetStdHandle(STD_ERROR_HANDLE , AllocConsoleRequest->ErrorHandle );
|
2012-11-15 18:06:17 +00:00
|
|
|
|
2013-01-01 23:36:19 +00:00
|
|
|
/* Initialize Console Ctrl Handler */
|
|
|
|
InitConsoleCtrlHandling();
|
|
|
|
|
|
|
|
InputWaitHandle = AllocConsoleRequest->InputWaitHandle;
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-02 20:42:06 +00:00
|
|
|
/*--------------------------------------------------------------
|
2012-11-15 18:06:17 +00:00
|
|
|
* FreeConsole
|
2004-11-02 20:42:06 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
FreeConsole(VOID)
|
2004-11-02 20:42:06 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
// AG: I'm not sure if this is correct (what happens to std handles?)
|
|
|
|
// but I just tried to reverse what AllocConsole() does...
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 18:06:17 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFree),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_FREECONSOLE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2012-11-15 18:06:17 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
|
2013-01-01 23:36:19 +00:00
|
|
|
|
|
|
|
CloseHandle(InputWaitHandle);
|
|
|
|
InputWaitHandle = INVALID_HANDLE_VALUE;
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
return TRUE;
|
2003-07-09 10:43:08 +00:00
|
|
|
}
|
1999-03-06 10:57:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2012-11-15 18:06:17 +00:00
|
|
|
* GetConsoleScreenBufferInfo
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
GetConsoleScreenBufferInfo(HANDLE hConsoleOutput,
|
|
|
|
PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
if (lpConsoleScreenBufferInfo == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.ScreenBufferInfoRequest.OutputHandle = hConsoleOutput;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 18:06:17 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetScreenBufferInfo),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSCREENBUFFERINFO));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2012-11-17 23:29:53 +00:00
|
|
|
|
|
|
|
*lpConsoleScreenBufferInfo = ApiMessage.Data.ScreenBufferInfoRequest.Info;
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2012-11-15 18:06:17 +00:00
|
|
|
* SetConsoleCursorPosition
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-15 18:06:17 +00:00
|
|
|
SetConsoleCursorPosition(HANDLE hConsoleOutput,
|
|
|
|
COORD dwCursorPosition)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.SetCursorPositionRequest.OutputHandle = hConsoleOutput;
|
2012-11-17 23:29:53 +00:00
|
|
|
ApiMessage.Data.SetCursorPositionRequest.Position = dwCursorPosition;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorPosition),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETCURSORPOSITION));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-11-15 18:06:17 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleMode
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleMode(HANDLE hConsoleHandle,
|
|
|
|
LPDWORD lpMode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-04-09 15:21:14 +00:00
|
|
|
if (lpMode == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:07:59 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMode),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCONSOLEMODE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-10-17 23:10:40 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
*lpMode = ConsoleModeRequest->ConsoleMode;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetNumberOfConsoleInputEvents
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
|
|
|
|
LPDWORD lpNumberOfEvents)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-03-09 01:39:49 +00:00
|
|
|
PCONSOLE_GETNUMINPUTEVENTS GetNumInputEventsRequest = &ApiMessage.Data.GetNumInputEventsRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-03-09 01:39:49 +00:00
|
|
|
GetNumInputEventsRequest->InputHandle = hConsoleInput;
|
|
|
|
GetNumInputEventsRequest->NumInputEvents = 0;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfInputEvents),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETNUMINPUTEVENTS));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-03-09 01:39:49 +00:00
|
|
|
if (lpNumberOfEvents == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_ACCESS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpNumberOfEvents = GetNumInputEventsRequest->NumInputEvents;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetLargestConsoleWindowSize
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2013-04-09 15:21:14 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
COORD
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetLargestConsoleWindowSize(HANDLE hConsoleOutput)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2013-04-09 15:21:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &ApiMessage.Data.GetLargestWindowSizeRequest;
|
|
|
|
|
|
|
|
GetLargestWindowSizeRequest->OutputHandle = hConsoleOutput;
|
2013-04-14 14:49:30 +00:00
|
|
|
GetLargestWindowSizeRequest->Size.X = 0;
|
|
|
|
GetLargestWindowSizeRequest->Size.Y = 0;
|
2013-04-09 15:21:14 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetLargestWindowSize),
|
|
|
|
sizeof(CONSOLE_GETLARGESTWINDOWSIZE));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT1("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest->Size.X, GetLargestWindowSizeRequest->Size.Y);
|
|
|
|
return GetLargestWindowSizeRequest->Size;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleCursorInfo
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleCursorInfo(HANDLE hConsoleOutput,
|
|
|
|
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
if (!lpConsoleCursorInfo)
|
|
|
|
{
|
2009-01-30 14:36:57 +00:00
|
|
|
if (!hConsoleOutput)
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
else
|
|
|
|
SetLastError(ERROR_INVALID_ACCESS);
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.CursorInfoRequest.OutputHandle = hConsoleOutput;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCursorInfo),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCURSORINFO));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
*lpConsoleCursorInfo = ApiMessage.Data.CursorInfoRequest.Info;
|
2001-09-01 15:36:45 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetNumberOfConsoleMouseButtons
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @unimplemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
DPRINT1("GetNumberOfConsoleMouseButtons(0x%x) UNIMPLEMENTED!\n", lpNumberOfMouseButtons);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleMode
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleMode(HANDLE hConsoleHandle,
|
|
|
|
DWORD dwMode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
ConsoleModeRequest->ConsoleHandle = hConsoleHandle;
|
2013-04-01 00:23:34 +00:00
|
|
|
ConsoleModeRequest->ConsoleMode = dwMode;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:07:59 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:07:59 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMode),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCONSOLEMODE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2012-10-17 23:10:40 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleActiveScreenBuffer
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
ApiMessage.Data.SetScreenBufferRequest.OutputHandle = hConsoleOutput;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetActiveScreenBuffer),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETACTIVESCREENBUFFER));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-01-21 00:07:03 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* FlushConsoleInputBuffer
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
FlushConsoleInputBuffer(HANDLE hConsoleInput)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.FlushInputBufferRequest.InputHandle = hConsoleInput;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFlushInputBuffer),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_FLUSHINPUTBUFFER));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-09-01 15:36:45 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleScreenBufferSize
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2010-05-12 03:34:02 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
|
|
|
|
COORD dwSize)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2010-05-12 03:34:02 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2010-05-12 03:34:02 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.SetScreenBufferSizeRequest.OutputHandle = hConsoleOutput;
|
|
|
|
ApiMessage.Data.SetScreenBufferSizeRequest.Size = dwSize;
|
2010-05-12 03:34:02 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetScreenBufferSize),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETSCREENBUFFERSIZE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-12 03:34:02 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2010-05-12 03:34:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleCursorInfo
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleCursorInfo(HANDLE hConsoleOutput,
|
|
|
|
CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.CursorInfoRequest.OutputHandle = hConsoleOutput;
|
2012-11-17 23:29:53 +00:00
|
|
|
ApiMessage.Data.CursorInfoRequest.Info = *lpConsoleCursorInfo;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2012-11-17 23:29:53 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:29:53 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorInfo),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCURSORINFO));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-09-01 15:36:45 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2004-11-02 20:42:06 +00:00
|
|
|
IntScrollConsoleScreenBuffer(HANDLE hConsoleOutput,
|
2007-01-21 23:29:10 +00:00
|
|
|
const SMALL_RECT *lpScrollRectangle,
|
|
|
|
const SMALL_RECT *lpClipRectangle,
|
2004-11-02 20:42:06 +00:00
|
|
|
COORD dwDestinationOrigin,
|
2007-01-21 23:29:10 +00:00
|
|
|
const CHAR_INFO *lpFill,
|
2004-11-02 20:42:06 +00:00
|
|
|
BOOL bUnicode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_SCROLLSCREENBUFFER ScrollScreenBufferRequest = &ApiMessage.Data.ScrollScreenBufferRequest;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ScrollScreenBufferRequest->OutputHandle = hConsoleOutput;
|
|
|
|
ScrollScreenBufferRequest->Unicode = bUnicode;
|
|
|
|
ScrollScreenBufferRequest->ScrollRectangle = *lpScrollRectangle;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
if (lpClipRectangle != NULL)
|
|
|
|
{
|
2013-01-05 23:10:12 +00:00
|
|
|
ScrollScreenBufferRequest->UseClipRectangle = TRUE;
|
|
|
|
ScrollScreenBufferRequest->ClipRectangle = *lpClipRectangle;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-05 23:10:12 +00:00
|
|
|
ScrollScreenBufferRequest->UseClipRectangle = FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ScrollScreenBufferRequest->DestinationOrigin = dwDestinationOrigin;
|
|
|
|
ScrollScreenBufferRequest->Fill = *lpFill;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-30 14:25:00 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepScrollScreenBuffer),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SCROLLSCREENBUFFER));
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-09-01 15:36:45 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-02 20:42:06 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* ScrollConsoleScreenBufferA
|
2004-11-02 20:42:06 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
ScrollConsoleScreenBufferA(HANDLE hConsoleOutput,
|
|
|
|
CONST SMALL_RECT *lpScrollRectangle,
|
|
|
|
CONST SMALL_RECT *lpClipRectangle,
|
|
|
|
COORD dwDestinationOrigin,
|
|
|
|
CONST CHAR_INFO *lpFill)
|
|
|
|
{
|
|
|
|
return IntScrollConsoleScreenBuffer(hConsoleOutput,
|
|
|
|
(PSMALL_RECT)lpScrollRectangle,
|
|
|
|
(PSMALL_RECT)lpClipRectangle,
|
|
|
|
dwDestinationOrigin,
|
|
|
|
(PCHAR_INFO)lpFill,
|
|
|
|
FALSE);
|
2004-11-02 20:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* ScrollConsoleScreenBufferW
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2004-11-02 20:42:06 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
ScrollConsoleScreenBufferW(HANDLE hConsoleOutput,
|
|
|
|
CONST SMALL_RECT *lpScrollRectangle,
|
|
|
|
CONST SMALL_RECT *lpClipRectangle,
|
|
|
|
COORD dwDestinationOrigin,
|
|
|
|
CONST CHAR_INFO *lpFill)
|
|
|
|
{
|
|
|
|
return IntScrollConsoleScreenBuffer(hConsoleOutput,
|
|
|
|
lpScrollRectangle,
|
|
|
|
lpClipRectangle,
|
|
|
|
dwDestinationOrigin,
|
|
|
|
lpFill,
|
|
|
|
TRUE);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleWindowInfo
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2013-04-09 15:21:14 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleWindowInfo(HANDLE hConsoleOutput,
|
|
|
|
BOOL bAbsolute,
|
|
|
|
CONST SMALL_RECT *lpConsoleWindow)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2013-04-09 15:21:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &ApiMessage.Data.SetWindowInfoRequest;
|
|
|
|
|
|
|
|
if (lpConsoleWindow == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowInfoRequest->OutputHandle = hConsoleOutput;
|
2013-05-29 00:29:07 +00:00
|
|
|
SetWindowInfoRequest->Absolute = bAbsolute;
|
|
|
|
SetWindowInfoRequest->WindowRect = *lpConsoleWindow;
|
2013-04-09 15:21:14 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetWindowInfo),
|
|
|
|
sizeof(CONSOLE_SETWINDOWINFO));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
1999-03-30 21:58:05 +00:00
|
|
|
* SetConsoleTextAttribute
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleTextAttribute(HANDLE hConsoleOutput,
|
|
|
|
WORD wAttributes)
|
1999-03-30 21:58:05 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.SetTextAttribRequest.OutputHandle = hConsoleOutput;
|
|
|
|
ApiMessage.Data.SetTextAttribRequest.Attrib = wAttributes;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTextAttribute),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETTEXTATTRIB));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2001-04-04 22:21:32 +00:00
|
|
|
AddConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
|
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
PHANDLER_ROUTINE* NewCtrlHandlers = NULL;
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
if (HandlerRoutine == NULL)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleFlags = TRUE;
|
2010-03-09 20:13:19 +00:00
|
|
|
return TRUE;
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
2010-03-09 20:13:19 +00:00
|
|
|
|
|
|
|
if (NrCtrlHandlers == NrAllocatedHandlers)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
NewCtrlHandlers = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
(NrCtrlHandlers + 4) * sizeof(PHANDLER_ROUTINE));
|
|
|
|
if (NewCtrlHandlers == NULL)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
2004-08-28 22:14:08 +00:00
|
|
|
}
|
2010-03-09 20:13:19 +00:00
|
|
|
|
|
|
|
memmove(NewCtrlHandlers, CtrlHandlers, sizeof(PHANDLER_ROUTINE) * NrCtrlHandlers);
|
|
|
|
|
|
|
|
if (NrAllocatedHandlers > 1) RtlFreeHeap(RtlGetProcessHeap(), 0, CtrlHandlers);
|
|
|
|
|
|
|
|
CtrlHandlers = NewCtrlHandlers;
|
|
|
|
NrAllocatedHandlers += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(NrCtrlHandlers < NrAllocatedHandlers);
|
|
|
|
|
|
|
|
CtrlHandlers[NrCtrlHandlers++] = HandlerRoutine;
|
|
|
|
return TRUE;
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
1999-03-06 10:57:02 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2001-04-04 22:21:32 +00:00
|
|
|
RemoveConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
ULONG i;
|
2001-04-04 22:21:32 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
if (HandlerRoutine == NULL)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleFlags = FALSE;
|
2010-03-09 20:13:19 +00:00
|
|
|
return TRUE;
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
2010-03-09 20:13:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NrCtrlHandlers; i++)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
if (CtrlHandlers[i] == HandlerRoutine)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
if (i < (NrCtrlHandlers - 1))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-03-09 20:13:19 +00:00
|
|
|
memmove(&CtrlHandlers[i],
|
|
|
|
&CtrlHandlers[i+1],
|
|
|
|
(NrCtrlHandlers - i + 1) * sizeof(PHANDLER_ROUTINE));
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2010-03-09 20:13:19 +00:00
|
|
|
|
|
|
|
NrCtrlHandlers--;
|
|
|
|
return TRUE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2010-03-09 20:13:19 +00:00
|
|
|
return FALSE;
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2003-07-09 10:43:08 +00:00
|
|
|
SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine,
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL Add)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL Ret;
|
2001-04-04 22:21:32 +00:00
|
|
|
|
2011-03-29 21:48:13 +00:00
|
|
|
RtlEnterCriticalSection(&BaseDllDirectoryLock);
|
2009-01-30 14:25:00 +00:00
|
|
|
if (Add)
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
Ret = AddConsoleCtrlHandler(HandlerRoutine);
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
else
|
2001-04-04 22:21:32 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
Ret = RemoveConsoleCtrlHandler(HandlerRoutine);
|
2001-04-04 22:21:32 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2011-03-29 21:48:13 +00:00
|
|
|
RtlLeaveCriticalSection(&BaseDllDirectoryLock);
|
2009-01-30 14:25:00 +00:00
|
|
|
return(Ret);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GenerateConsoleCtrlEvent
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2008-08-02 17:01:22 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
|
|
|
|
DWORD dwProcessGroupId)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2008-08-02 17:01:22 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2008-08-02 17:01:22 +00:00
|
|
|
|
|
|
|
if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.GenerateCtrlEventRequest.Event = dwCtrlEvent;
|
|
|
|
ApiMessage.Data.GenerateCtrlEventRequest.ProcessGroup = dwProcessGroupId;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2009-01-07 10:23:29 +00:00
|
|
|
NULL,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGenerateCtrlEvent),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GENERATECTRLEVENT));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2008-08-02 17:01:22 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2008-08-02 17:01:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2008-08-02 17:01:22 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
static DWORD
|
|
|
|
IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD nSize, BOOL bUnicode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &ApiMessage.Data.TitleRequest;
|
2012-11-18 13:10:03 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2003-03-09 21:37:18 +00:00
|
|
|
|
2013-03-09 21:08:23 +00:00
|
|
|
if (nSize == 0) return 0;
|
2010-06-04 06:36:12 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Length = nSize * (bUnicode ? 1 : sizeof(WCHAR));
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
|
2010-06-04 06:36:12 +00:00
|
|
|
if (CaptureBuffer == NULL)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-02-23 14:24:57 +00:00
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2010-06-04 06:36:12 +00:00
|
|
|
return 0;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Length,
|
|
|
|
(PVOID*)&TitleRequest->Title);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
CaptureBuffer,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetTitle),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCONSOLETITLE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
if (bUnicode)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-06-04 06:36:12 +00:00
|
|
|
if (nSize >= sizeof(WCHAR))
|
2012-11-18 13:10:03 +00:00
|
|
|
wcscpy((LPWSTR)lpConsoleTitle, TitleRequest->Title);
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
if (nSize < TitleRequest->Length / sizeof(WCHAR) ||
|
2010-06-04 06:36:12 +00:00
|
|
|
!WideCharToMultiByte(CP_ACP, // ANSI code page
|
|
|
|
0, // performance and mapping flags
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Title, // address of wide-character string
|
2010-06-04 06:36:12 +00:00
|
|
|
-1, // number of characters in string
|
|
|
|
(LPSTR)lpConsoleTitle, // address of buffer for new string
|
|
|
|
nSize, // size of buffer
|
|
|
|
NULL, // FAST
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
/* Yes, if the buffer isn't big enough, it returns 0... Bad API */
|
|
|
|
*(LPSTR)lpConsoleTitle = '\0';
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Length = 0;
|
2010-06-04 06:36:12 +00:00
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
return TitleRequest->Length / sizeof(WCHAR);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
/*--------------------------------------------------------------
|
|
|
|
* GetConsoleTitleW
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleTitleW(LPWSTR lpConsoleTitle,
|
|
|
|
DWORD nSize)
|
|
|
|
{
|
|
|
|
return IntGetConsoleTitle(lpConsoleTitle, nSize, TRUE);
|
|
|
|
}
|
1999-03-06 10:57:02 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleTitleA
|
1999-03-06 10:57:02 +00:00
|
|
|
*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleTitleA(LPSTR lpConsoleTitle,
|
|
|
|
DWORD nSize)
|
|
|
|
{
|
2010-06-04 06:36:12 +00:00
|
|
|
return IntGetConsoleTitle(lpConsoleTitle, nSize, FALSE);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleTitleW
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleTitleW(LPCWSTR lpConsoleTitle)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETSETCONSOLETITLE TitleRequest = &ApiMessage.Data.TitleRequest;
|
2012-11-18 13:10:03 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Length = wcslen(lpConsoleTitle) * sizeof(WCHAR);
|
2010-06-04 06:36:12 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, TitleRequest->Length);
|
2010-06-04 06:36:12 +00:00
|
|
|
if (CaptureBuffer == NULL)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-02-23 14:24:57 +00:00
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpConsoleTitle,
|
2012-11-18 13:10:03 +00:00
|
|
|
TitleRequest->Length,
|
|
|
|
(PVOID*)&TitleRequest->Title);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
CaptureBuffer,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTitle),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETCONSOLETITLE));
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2001-06-22 02:11:44 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2010-06-04 06:36:12 +00:00
|
|
|
return FALSE;
|
2001-06-22 02:11:44 +00:00
|
|
|
}
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleTitleA
|
2005-05-09 01:46:57 +00:00
|
|
|
*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleTitleA(LPCSTR lpConsoleTitle)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2013-02-10 12:36:57 +00:00
|
|
|
BOOL Ret;
|
|
|
|
ULONG Length = strlen(lpConsoleTitle) + 1;
|
2010-06-04 06:36:12 +00:00
|
|
|
LPWSTR WideTitle = HeapAlloc(GetProcessHeap(), 0, Length * sizeof(WCHAR));
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
if (!WideTitle)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpConsoleTitle, -1, WideTitle, Length);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
Ret = SetConsoleTitleW(WideTitle);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, WideTitle);
|
|
|
|
return Ret;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* CreateConsoleScreenBuffer
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
HANDLE
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
CreateConsoleScreenBuffer(DWORD dwDesiredAccess,
|
|
|
|
DWORD dwShareMode,
|
|
|
|
CONST SECURITY_ATTRIBUTES *lpSecurityAttributes,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPVOID lpScreenBufferData)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-05-29 00:29:07 +00:00
|
|
|
PCONSOLE_CREATESCREENBUFFER CreateScreenBufferRequest = &ApiMessage.Data.CreateScreenBufferRequest;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer = NULL;
|
|
|
|
PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo = /*(PCONSOLE_GRAPHICS_BUFFER_INFO)*/lpScreenBufferData;
|
2001-01-21 00:07:03 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)) ||
|
|
|
|
(dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) ||
|
2013-05-29 00:29:07 +00:00
|
|
|
(dwFlags != CONSOLE_TEXTMODE_BUFFER && dwFlags != CONSOLE_GRAPHICS_BUFFER) )
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2008-07-22 17:37:13 +00:00
|
|
|
|
2013-05-29 00:29:07 +00:00
|
|
|
CreateScreenBufferRequest->ScreenBufferType = dwFlags;
|
|
|
|
CreateScreenBufferRequest->Access = dwDesiredAccess;
|
|
|
|
CreateScreenBufferRequest->ShareMode = dwShareMode;
|
|
|
|
CreateScreenBufferRequest->Inheritable =
|
2012-11-17 23:45:14 +00:00
|
|
|
(lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle : FALSE);
|
2008-07-22 17:37:13 +00:00
|
|
|
|
2013-05-29 00:29:07 +00:00
|
|
|
if (dwFlags == CONSOLE_GRAPHICS_BUFFER)
|
|
|
|
{
|
|
|
|
if (CreateScreenBufferRequest->Inheritable || GraphicsBufferInfo == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateScreenBufferRequest->GraphicsBufferInfo = *GraphicsBufferInfo;
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, GraphicsBufferInfo->dwBitMapInfoLength);
|
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)GraphicsBufferInfo->lpBitMapInfo,
|
|
|
|
GraphicsBufferInfo->dwBitMapInfoLength,
|
|
|
|
(PVOID*)&CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMapInfo);
|
|
|
|
}
|
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2013-05-29 00:29:07 +00:00
|
|
|
CaptureBuffer,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCreateScreenBuffer),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_CREATESCREENBUFFER));
|
2013-05-29 00:29:07 +00:00
|
|
|
|
|
|
|
if (CaptureBuffer)
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2012-11-17 23:45:14 +00:00
|
|
|
|
2013-05-29 00:29:07 +00:00
|
|
|
if (dwFlags == CONSOLE_GRAPHICS_BUFFER && GraphicsBufferInfo)
|
|
|
|
{
|
|
|
|
GraphicsBufferInfo->hMutex = CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
|
|
|
|
GraphicsBufferInfo->lpBitMap = CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CreateScreenBufferRequest->OutputHandle;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleCP
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleCP(VOID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Get the Input Code Page */
|
2013-06-14 01:00:49 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
|
|
|
|
ApiMessage.Data.ConsoleCPRequest.CodePage = 0;
|
2012-11-18 13:10:03 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
|
2013-06-14 01:00:49 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
return ApiMessage.Data.ConsoleCPRequest.CodePage;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleCP
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2004-08-24 17:21:12 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleCP(UINT wCodePageID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Set the Input Code Page */
|
2013-06-14 01:00:49 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.InputCP = TRUE;
|
2012-11-18 13:10:03 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
|
2013-06-14 01:00:49 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return NT_SUCCESS(Status);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleOutputCP
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleOutputCP(VOID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Get the Output Code Page */
|
2013-06-14 01:00:49 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
|
|
|
|
ApiMessage.Data.ConsoleCPRequest.CodePage = 0;
|
2012-11-18 13:10:03 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
|
2013-06-14 01:00:49 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
return ApiMessage.Data.ConsoleCPRequest.CodePage;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleOutputCP
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleOutputCP(UINT wCodePageID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Set the Output Code Page */
|
2013-06-14 01:00:49 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.InputCP = FALSE;
|
2012-11-18 13:10:03 +00:00
|
|
|
ApiMessage.Data.ConsoleCPRequest.CodePage = wCodePageID;
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSETINPUTOUTPUTCP));
|
2013-06-14 01:00:49 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return NT_SUCCESS(Status);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-20 00:34:40 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleProcessList
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2005-02-05 01:44:05 +00:00
|
|
|
* @implemented
|
2002-10-20 00:34:40 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2002-10-20 00:34:40 +00:00
|
|
|
GetConsoleProcessList(LPDWORD lpdwProcessList,
|
2005-02-05 01:44:05 +00:00
|
|
|
DWORD dwProcessCount)
|
2002-10-20 00:34:40 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETPROCESSLIST GetProcessListRequest = &ApiMessage.Data.GetProcessListRequest;
|
2010-05-23 17:40:54 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2009-01-30 14:25:00 +00:00
|
|
|
ULONG nProcesses;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
if (lpdwProcessList == NULL || dwProcessCount == 0)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-05 01:44:05 +00:00
|
|
|
|
2010-05-23 17:40:54 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, dwProcessCount * sizeof(DWORD));
|
|
|
|
if (CaptureBuffer == NULL)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-02-23 14:24:57 +00:00
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
2009-01-30 14:25:00 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
GetProcessListRequest->nMaxIds = dwProcessCount;
|
|
|
|
|
2010-05-23 17:40:54 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
dwProcessCount * sizeof(DWORD),
|
2012-11-18 13:10:03 +00:00
|
|
|
(PVOID*)&GetProcessListRequest->pProcessIds);
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2010-05-23 17:40:54 +00:00
|
|
|
CaptureBuffer,
|
2012-11-18 13:10:03 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetProcessList),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETPROCESSLIST));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError (Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
nProcesses = 0;
|
|
|
|
}
|
|
|
|
else
|
2005-02-05 01:44:05 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
nProcesses = GetProcessListRequest->nProcessIdsTotal;
|
2009-01-30 14:25:00 +00:00
|
|
|
if (dwProcessCount >= nProcesses)
|
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
memcpy(lpdwProcessList, GetProcessListRequest->pProcessIds, nProcesses * sizeof(DWORD));
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2005-02-05 01:44:05 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2010-05-23 17:40:54 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2009-01-30 14:25:00 +00:00
|
|
|
return nProcesses;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleSelectionInfo
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2010-05-23 22:38:16 +00:00
|
|
|
* @implemented
|
2002-10-20 00:34:40 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2002-10-20 00:34:40 +00:00
|
|
|
GetConsoleSelectionInfo(PCONSOLE_SELECTION_INFO lpConsoleSelectionInfo)
|
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
|
|
|
|
if (lpConsoleSelectionInfo == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetSelectionInfo),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETSELECTIONINFO));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2010-05-23 22:38:16 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2010-05-23 22:38:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
*lpConsoleSelectionInfo = ApiMessage.Data.GetSelectionInfoRequest.Info;
|
2010-05-23 22:38:16 +00:00
|
|
|
return TRUE;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* AttachConsole
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
2013-01-13 17:07:25 +00:00
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* @note Strongly inspired by AllocConsole.
|
2002-10-20 00:34:40 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2002-10-20 00:34:40 +00:00
|
|
|
AttachConsole(DWORD dwProcessId)
|
|
|
|
{
|
2013-01-13 17:07:25 +00:00
|
|
|
NTSTATUS Status;
|
2013-02-10 12:36:57 +00:00
|
|
|
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
|
2013-01-13 17:07:25 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_ATTACHCONSOLE AttachConsoleRequest = &ApiMessage.Data.AttachConsoleRequest;
|
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
if (Parameters->ConsoleHandle)
|
2013-01-13 17:07:25 +00:00
|
|
|
{
|
|
|
|
DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
|
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttachConsoleRequest->ProcessId = dwProcessId;
|
|
|
|
AttachConsoleRequest->CtrlDispatcher = ConsoleControlDispatcher;
|
[CONSOLE.DLL-KERNEL32-CONSRV]
Fix the console properties dialog, when launching and transmitting console properties. Before, the properties dialog was directly launched by the console server (consrv), running with CSRSS (System) privileges, what constituted a security hole. Now, I create a remote thread in the running process owning the console for launching the properties dialog (thus it has only user privileges, and not System ones anymore). For that purpose, I basically took the technique described in the following paper (Cesar Cerrudo, "Story of a dumb patch", http://www.argeniss.com/research/MSBugPaper.pdf or http://www.scn.rain.com/~neighorn/PDF/MSBugPaper.pdf), where basically the console server shares the console properties via a shared memory section with the console properties dialog dll. The address of the thread which launches the dialog in the context of the console app is given to the console server the same way as we do for the control handler (called e.g. when you press Ctrl-C, etc...)
Of course this is quite hackish, because you have the GUI interface split between the console server and the console properties dialog dll. Something far more elegant would be to put all the GUI thingie into a dedicated dll or exe, running with the same privileges as the console program itself (a kind of console -- or terminal -- emulator).
[CONSOLE.DLL]
Fix retriving / setting colors.c and other things.
[CONSRV.DLL]
- Fix retrieving / setting console properties from the registry (via the HKCU\Console\* keys), via the shell shortcuts (not totally done at the moment, because somebody has to implement properly that thing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb773359(v=vs.85).aspx (NT_CONSOLE_PROPS structure stored as a shortcut data block) (at application launching time), and via the console properties dialog.
- Few DPRINTs removed.
svn path=/branches/ros-csrss/; revision=58415
2013-03-03 15:35:12 +00:00
|
|
|
AttachConsoleRequest->PropDispatcher = PropDialogHandler;
|
2013-01-13 17:07:25 +00:00
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAttach),
|
|
|
|
sizeof(CONSOLE_ATTACHCONSOLE));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2013-01-13 17:07:25 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-07-06 19:57:38 +00:00
|
|
|
Parameters->ConsoleHandle = AttachConsoleRequest->ConsoleHandle;
|
2013-01-13 17:07:25 +00:00
|
|
|
SetStdHandle(STD_INPUT_HANDLE , AttachConsoleRequest->InputHandle );
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, AttachConsoleRequest->OutputHandle);
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE , AttachConsoleRequest->ErrorHandle );
|
|
|
|
|
|
|
|
/* Initialize Console Ctrl Handler */
|
|
|
|
InitConsoleCtrlHandling();
|
|
|
|
|
|
|
|
InputWaitHandle = AttachConsoleRequest->InputWaitHandle;
|
|
|
|
|
2009-08-15 10:04:45 +00:00
|
|
|
return TRUE;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
|
2003-06-19 19:38:26 +00:00
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* GetConsoleWindow
|
2003-07-10 18:50:51 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2003-06-19 19:38:26 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
HWND
|
|
|
|
WINAPI
|
|
|
|
GetConsoleWindow(VOID)
|
2003-06-19 19:38:26 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetConsoleWindow),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETWINDOW));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2013-03-09 22:16:26 +00:00
|
|
|
return (HWND)NULL;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return ApiMessage.Data.GetWindowRequest.WindowHandle;
|
2003-06-19 19:38:26 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 17:53:27 +00:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------
|
2009-01-30 14:25:00 +00:00
|
|
|
* SetConsoleIcon
|
2004-08-22 20:52:28 +00:00
|
|
|
*
|
2004-03-14 17:53:27 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleIcon(HICON hicon)
|
2004-03-14 17:53:27 +00:00
|
|
|
{
|
2009-01-30 14:25:00 +00:00
|
|
|
NTSTATUS Status;
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ApiMessage.Data.SetIconRequest.WindowIcon = hicon;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-10-17 23:10:40 +00:00
|
|
|
NULL,
|
2012-11-17 23:45:14 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetIcon),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_SETICON));
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NT_SUCCESS(Status);
|
2004-03-14 17:53:27 +00:00
|
|
|
}
|
|
|
|
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name SetConsoleInputExeNameW
|
|
|
|
* \brief Sets the console input file name from a unicode string.
|
|
|
|
* \param lpInputExeName Pointer to a unicode string with the name.
|
|
|
|
* \return TRUE if successful, FALSE if unsuccsedful.
|
|
|
|
* \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
|
|
|
|
* the function fails and sets last error to ERROR_INVALID_PARAMETER.
|
2004-12-18 13:26:57 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2004-12-18 13:26:57 +00:00
|
|
|
SetConsoleInputExeNameW(LPCWSTR lpInputExeName)
|
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
int lenName;
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
if ( !lpInputExeName ||
|
|
|
|
(lenName = lstrlenW(lpInputExeName)) == 0 ||
|
|
|
|
lenName > INPUTEXENAME_BUFLEN - 1 )
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
|
|
|
/* Fail if string is empty or too long */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
2009-01-18 10:06:34 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlCopyMemory(InputExeName, lpInputExeName, lenName * sizeof(WCHAR));
|
|
|
|
InputExeName[lenName] = L'\0';
|
2009-01-18 10:06:34 +00:00
|
|
|
}
|
2009-01-19 17:08:47 +00:00
|
|
|
_SEH2_FINALLY
|
2009-01-18 10:06:34 +00:00
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
2009-01-18 10:06:34 +00:00
|
|
|
}
|
|
|
|
_SEH2_END;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
return TRUE;
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name SetConsoleInputExeNameA
|
|
|
|
* \brief Sets the console input file name from an ansi string.
|
|
|
|
* \param lpInputExeName Pointer to an ansi string with the name.
|
|
|
|
* \return TRUE if successful, FALSE if unsuccsedful.
|
|
|
|
* \remarks If lpInputExeName is 0 or the string length is 0 or greater than 255,
|
|
|
|
* the function fails and sets last error to ERROR_INVALID_PARAMETER.
|
2004-12-18 13:26:57 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2004-12-18 13:26:57 +00:00
|
|
|
SetConsoleInputExeNameA(LPCSTR lpInputExeName)
|
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
WCHAR Buffer[INPUTEXENAME_BUFLEN];
|
|
|
|
ANSI_STRING InputExeNameA;
|
|
|
|
UNICODE_STRING InputExeNameU;
|
|
|
|
NTSTATUS Status;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlInitAnsiString(&InputExeNameA, lpInputExeName);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
if ( InputExeNameA.Length == 0 ||
|
|
|
|
InputExeNameA.Length > INPUTEXENAME_BUFLEN - 1 )
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
|
|
|
/* Fail if string is empty or too long */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
InputExeNameU.Buffer = Buffer;
|
|
|
|
InputExeNameU.MaximumLength = sizeof(Buffer);
|
|
|
|
InputExeNameU.Length = 0;
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
Status = RtlAnsiStringToUnicodeString(&InputExeNameU, &InputExeNameA, FALSE);
|
2013-02-10 12:36:57 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2013-02-10 12:36:57 +00:00
|
|
|
return FALSE;
|
2009-01-19 17:08:47 +00:00
|
|
|
}
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
return SetConsoleInputExeNameW(InputExeNameU.Buffer);
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name GetConsoleInputExeNameW
|
|
|
|
* \brief Retrieves the console input file name as unicode string.
|
|
|
|
* \param nBufferLength Length of the buffer in WCHARs.
|
2013-04-14 12:14:00 +00:00
|
|
|
* Specify 0 to receive the needed buffer length.
|
|
|
|
* \param lpBuffer Pointer to a buffer that receives the string.
|
2009-01-19 17:08:47 +00:00
|
|
|
* \return Needed buffer size if \p nBufferLength is 0.
|
|
|
|
* Otherwise 1 if successful, 2 if buffer is too small.
|
|
|
|
* \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
|
|
|
|
* is not big enough.
|
2004-12-18 13:26:57 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2004-12-18 13:26:57 +00:00
|
|
|
GetConsoleInputExeNameW(DWORD nBufferLength, LPWSTR lpBuffer)
|
|
|
|
{
|
2013-04-14 14:49:30 +00:00
|
|
|
ULONG lenName = lstrlenW(InputExeName);
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
if (nBufferLength == 0)
|
2009-01-18 10:06:34 +00:00
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Buffer size is requested, return it */
|
|
|
|
return lenName + 1;
|
|
|
|
}
|
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
if (lenName + 1 > nBufferLength)
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
|
|
|
/* Buffer is not large enough! */
|
2009-01-18 10:06:34 +00:00
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
2009-01-19 17:08:47 +00:00
|
|
|
return 2;
|
2009-01-18 10:06:34 +00:00
|
|
|
}
|
2009-01-19 17:08:47 +00:00
|
|
|
|
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
|
|
|
_SEH2_TRY
|
2009-01-07 10:23:29 +00:00
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlCopyMemory(lpBuffer, InputExeName, lenName * sizeof(WCHAR));
|
|
|
|
lpBuffer[lenName] = '\0';
|
|
|
|
}
|
|
|
|
_SEH2_FINALLY
|
|
|
|
{
|
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
2009-01-07 10:23:29 +00:00
|
|
|
}
|
2009-01-18 10:06:34 +00:00
|
|
|
_SEH2_END;
|
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Success, return 1 */
|
|
|
|
return 1;
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* \name GetConsoleInputExeNameA
|
|
|
|
* \brief Retrieves the console input file name as ansi string.
|
|
|
|
* \param nBufferLength Length of the buffer in CHARs.
|
2013-04-14 12:14:00 +00:00
|
|
|
* \param lpBuffer Pointer to a buffer that receives the string.
|
2009-01-19 17:08:47 +00:00
|
|
|
* \return 1 if successful, 2 if buffer is too small.
|
|
|
|
* \remarks Sets last error value to ERROR_BUFFER_OVERFLOW if the buffer
|
2013-04-14 12:14:00 +00:00
|
|
|
* is not big enough. The buffer receives as much characters as fit.
|
2004-12-18 13:26:57 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2004-12-18 13:26:57 +00:00
|
|
|
GetConsoleInputExeNameA(DWORD nBufferLength, LPSTR lpBuffer)
|
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
WCHAR Buffer[INPUTEXENAME_BUFLEN];
|
|
|
|
DWORD Ret;
|
|
|
|
UNICODE_STRING BufferU;
|
|
|
|
ANSI_STRING BufferA;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Get the unicode name */
|
|
|
|
Ret = GetConsoleInputExeNameW(sizeof(Buffer) / sizeof(Buffer[0]), Buffer);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Initialize strings for conversion */
|
|
|
|
RtlInitUnicodeString(&BufferU, Buffer);
|
|
|
|
BufferA.Length = 0;
|
2013-05-29 00:29:07 +00:00
|
|
|
BufferA.MaximumLength = (USHORT)nBufferLength;
|
2009-01-19 17:08:47 +00:00
|
|
|
BufferA.Buffer = lpBuffer;
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Convert unicode name to ansi, copying as much chars as fit */
|
|
|
|
RtlUnicodeStringToAnsiString(&BufferA, &BufferU, FALSE);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
/* Error handling */
|
2013-02-10 12:36:57 +00:00
|
|
|
if (nBufferLength <= BufferU.Length / sizeof(WCHAR))
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
return 2;
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-19 17:08:47 +00:00
|
|
|
return Ret;
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 02:13:57 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCharType(HANDLE hConsole, COORD Coord, PDWORD Type)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetConsoleCursorMode(HANDLE hConsole, PBOOL pUnknown1, PBOOL pUnknown2)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetConsoleNlsMode(HANDLE hConsole, LPDWORD lpMode)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-18 13:10:03 +00:00
|
|
|
SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-18 13:10:03 +00:00
|
|
|
SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-18 13:10:03 +00:00
|
|
|
SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-18 13:10:03 +00:00
|
|
|
RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-11-18 13:10:03 +00:00
|
|
|
RegisterConsoleOS2(BOOL bUnknown)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleOS2OemFormat(BOOL bUnknown)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
UnregisterConsoleIME(VOID)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameA(LPSTR name)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR name)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetLastConsoleEventActive(VOID)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
/* EOF */
|