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
|
2014-09-09 21:24:44 +00:00
|
|
|
* PROGRAMMERS: James Tabor <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
|
|
|
|
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
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;
|
2014-09-07 22:53:49 +00:00
|
|
|
extern BOOLEAN ConsoleInitialized;
|
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;
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Console Control handling */
|
|
|
|
static PHANDLER_ROUTINE InitialHandler[1];
|
|
|
|
static PHANDLER_ROUTINE* CtrlHandlers;
|
|
|
|
static ULONG NrCtrlHandlers;
|
|
|
|
static ULONG NrAllocatedHandlers;
|
|
|
|
static BOOLEAN LastCloseNotify = FALSE;
|
|
|
|
|
|
|
|
extern BOOL WINAPI IsDebuggerPresent(VOID);
|
2010-03-09 20:13:19 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Console Input facilities */
|
2013-01-01 23:36:19 +00:00
|
|
|
HANDLE InputWaitHandle = INVALID_HANDLE_VALUE;
|
|
|
|
|
2017-12-16 19:58:08 +00:00
|
|
|
#define EXENAME_LENGTH (255 + 1)
|
2014-09-07 22:53:49 +00:00
|
|
|
static RTL_CRITICAL_SECTION ExeNameLock;
|
|
|
|
static BOOLEAN ExeNameInitialized;
|
|
|
|
static WCHAR ExeNameBuffer[EXENAME_LENGTH]; // NULL-terminated
|
|
|
|
static USHORT ExeNameLength; // Count in number of characters without NULL
|
|
|
|
static WCHAR StartDirBuffer[MAX_PATH + 1]; // NULL-terminated
|
|
|
|
static USHORT StartDirLength; // Count in number of characters without NULL
|
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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
static BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
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;
|
|
|
|
|
2014-04-21 01:36:00 +00:00
|
|
|
case CTRL_LAST_CLOSE_EVENT:
|
|
|
|
DPRINT("Ctrl Last Close Event\n");
|
|
|
|
break;
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
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
|
|
|
|
2014-04-21 01:22:17 +00:00
|
|
|
case CTRL_LAST_CLOSE_EVENT:
|
|
|
|
/*
|
|
|
|
* In case the console app hasn't register for last close notification,
|
|
|
|
* just kill this console handler thread. We don't want that such apps
|
|
|
|
* get killed for unexpected reasons. On the contrary apps that registered
|
|
|
|
* can be killed because they expect to be.
|
|
|
|
*/
|
|
|
|
if (!LastCloseNotify) ExitThread(0);
|
2010-03-09 20:13:19 +00:00
|
|
|
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:
|
2014-04-21 01:36:00 +00:00
|
|
|
case CTRL_LAST_CLOSE_EVENT:
|
2009-01-30 14:25:00 +00:00
|
|
|
case CTRL_LOGOFF_EVENT:
|
|
|
|
case CTRL_SHUTDOWN_EVENT:
|
|
|
|
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
|
2014-09-07 22:53:49 +00:00
|
|
|
InitializeCtrlHandling(VOID)
|
2013-01-01 23:36:19 +00:00
|
|
|
{
|
|
|
|
/* Initialize Console Ctrl Handler */
|
|
|
|
NrAllocatedHandlers = NrCtrlHandlers = 1;
|
|
|
|
CtrlHandlers = InitialHandler;
|
|
|
|
CtrlHandlers[0] = DefaultConsoleCtrlHandler;
|
|
|
|
}
|
|
|
|
|
2003-08-16 17:37:51 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Input EXE Name Support *****************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
InitExeName(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PPEB Peb = NtCurrentPeb();
|
|
|
|
PCURDIR CurrentDirectory = &Peb->ProcessParameters->CurrentDirectory;
|
|
|
|
PLDR_DATA_TABLE_ENTRY ImageEntry;
|
|
|
|
|
|
|
|
if (ExeNameInitialized) return;
|
|
|
|
|
|
|
|
/* Initialize the EXE name lock */
|
|
|
|
Status = RtlInitializeCriticalSection(&ExeNameLock);
|
|
|
|
if (!NT_SUCCESS(Status)) return;
|
|
|
|
ExeNameInitialized = TRUE;
|
|
|
|
|
|
|
|
ImageEntry = CONTAINING_RECORD(Peb->Ldr->InLoadOrderModuleList.Flink,
|
|
|
|
LDR_DATA_TABLE_ENTRY,
|
|
|
|
InLoadOrderLinks);
|
|
|
|
|
|
|
|
/* Retrieve the EXE name, NULL-terminate it... */
|
|
|
|
ExeNameLength = min(sizeof(ExeNameBuffer)/sizeof(ExeNameBuffer[0]),
|
|
|
|
ImageEntry->BaseDllName.Length / sizeof(WCHAR));
|
|
|
|
RtlCopyMemory(ExeNameBuffer,
|
|
|
|
ImageEntry->BaseDllName.Buffer,
|
|
|
|
ImageEntry->BaseDllName.Length);
|
|
|
|
ExeNameBuffer[ExeNameLength] = UNICODE_NULL;
|
|
|
|
|
|
|
|
/* ... and retrieve the current directory path and NULL-terminate it. */
|
|
|
|
StartDirLength = min(sizeof(StartDirBuffer)/sizeof(StartDirBuffer[0]),
|
|
|
|
CurrentDirectory->DosPath.Length / sizeof(WCHAR));
|
|
|
|
RtlCopyMemory(StartDirBuffer,
|
|
|
|
CurrentDirectory->DosPath.Buffer,
|
|
|
|
CurrentDirectory->DosPath.Length);
|
|
|
|
StartDirBuffer[StartDirLength] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* The "LPDWORD Length" parameters point on input to the maximum size of
|
|
|
|
* the buffers that can hold data (if != 0), and on output they hold the
|
|
|
|
* real size of the data. If "Length" are == 0 on input, then on output
|
|
|
|
* they receive the full size of the data.
|
|
|
|
* The "LPWSTR* String" parameters have a double meaning:
|
|
|
|
* - when "CaptureStrings" is TRUE, data is copied to the buffers pointed
|
|
|
|
* by the pointers (*String).
|
|
|
|
* - when "CaptureStrings" is FALSE, "*String" are set to the addresses of
|
|
|
|
* the source data.
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
SetUpAppName(IN BOOLEAN CaptureStrings,
|
|
|
|
IN OUT LPDWORD CurDirLength,
|
|
|
|
IN OUT LPWSTR* CurDir,
|
|
|
|
IN OUT LPDWORD AppNameLength,
|
|
|
|
IN OUT LPWSTR* AppName)
|
|
|
|
{
|
|
|
|
DWORD Length;
|
|
|
|
|
|
|
|
/* Retrieve the needed buffer size */
|
|
|
|
Length = (StartDirLength + 1) * sizeof(WCHAR);
|
|
|
|
if (*CurDirLength > 0) Length = min(Length, *CurDirLength);
|
|
|
|
*CurDirLength = Length;
|
|
|
|
|
|
|
|
/* Capture the data if needed, or, return a pointer to it */
|
|
|
|
if (CaptureStrings)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Length is always >= sizeof(WCHAR). Copy everything but the
|
|
|
|
* possible trailing NULL character, and then NULL-terminate.
|
|
|
|
*/
|
|
|
|
Length -= sizeof(WCHAR);
|
|
|
|
RtlCopyMemory(*CurDir, StartDirBuffer, Length);
|
|
|
|
(*CurDir)[Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*CurDir = StartDirBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the needed buffer size */
|
|
|
|
Length = (ExeNameLength + 1) * sizeof(WCHAR);
|
|
|
|
if (*AppNameLength > 0) Length = min(Length, *AppNameLength);
|
|
|
|
*AppNameLength = Length;
|
|
|
|
|
|
|
|
/* Capture the data if needed, or, return a pointer to it */
|
|
|
|
if (CaptureStrings)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Length is always >= sizeof(WCHAR). Copy everything but the
|
|
|
|
* possible trailing NULL character, and then NULL-terminate.
|
|
|
|
*/
|
|
|
|
Length -= sizeof(WCHAR);
|
|
|
|
RtlCopyMemory(*AppName, ExeNameBuffer, Length);
|
|
|
|
(*AppName)[Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*AppName = ExeNameBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
USHORT
|
|
|
|
GetCurrentExeName(OUT PWCHAR ExeName,
|
|
|
|
IN USHORT BufferSize)
|
|
|
|
{
|
|
|
|
USHORT ExeLength;
|
|
|
|
|
|
|
|
if (ExeNameInitialized)
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection(&ExeNameLock);
|
|
|
|
|
|
|
|
if (BufferSize > ExeNameLength * sizeof(WCHAR))
|
|
|
|
BufferSize = ExeNameLength * sizeof(WCHAR);
|
|
|
|
|
|
|
|
RtlCopyMemory(ExeName, ExeNameBuffer, BufferSize);
|
|
|
|
|
|
|
|
RtlLeaveCriticalSection(&ExeNameLock);
|
|
|
|
ExeLength = BufferSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ExeName = UNICODE_NULL;
|
|
|
|
ExeLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExeLength;
|
|
|
|
}
|
|
|
|
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
MenuControlRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
MenuControlRequest->OutputHandle = hConsoleOutput;
|
|
|
|
MenuControlRequest->CmdIdLow = dwCmdIdLow;
|
|
|
|
MenuControlRequest->CmdIdHigh = dwCmdIdHigh;
|
|
|
|
MenuControlRequest->MenuHandle = NULL;
|
2013-05-30 00:50:03 +00:00
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepMenuControl),
|
2014-03-08 15:31:05 +00:00
|
|
|
sizeof(*MenuControlRequest));
|
2013-05-30 00:50:03 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return MenuControlRequest->MenuHandle;
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
DuplicateConsoleHandle(HANDLE hConsole,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
DWORD dwOptions)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
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
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2009-01-30 14:25:00 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2003-03-09 21:37:18 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
DuplicateHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
DuplicateHandleRequest->SourceHandle = hConsole;
|
|
|
|
DuplicateHandleRequest->DesiredAccess = dwDesiredAccess;
|
|
|
|
DuplicateHandleRequest->InheritHandle = bInheritHandle;
|
|
|
|
DuplicateHandleRequest->Options = dwOptions;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepDuplicateHandle),
|
|
|
|
sizeof(*DuplicateHandleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2003-03-09 21:37:18 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
return DuplicateHandleRequest->TargetHandle;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
2014-04-20 14:39:38 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetConsoleHandleInformation(IN HANDLE hHandle,
|
|
|
|
OUT LPDWORD lpdwFlags)
|
|
|
|
{
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETHANDLEINFO GetHandleInfoRequest = &ApiMessage.Data.GetHandleInfoRequest;
|
|
|
|
|
|
|
|
GetHandleInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetHandleInfoRequest->Handle = hHandle;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHandleInformation),
|
|
|
|
sizeof(*GetHandleInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpdwFlags = GetHandleInfoRequest->Flags;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetConsoleHandleInformation(IN HANDLE hHandle,
|
|
|
|
IN DWORD dwMask,
|
|
|
|
IN DWORD dwFlags)
|
|
|
|
{
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETHANDLEINFO SetHandleInfoRequest = &ApiMessage.Data.SetHandleInfoRequest;
|
|
|
|
|
|
|
|
SetHandleInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetHandleInfoRequest->Handle = hHandle;
|
|
|
|
SetHandleInfoRequest->Mask = dwMask;
|
|
|
|
SetHandleInfoRequest->Flags = dwFlags;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHandleInformation),
|
|
|
|
sizeof(*SetHandleInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
GetDisplayModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2013-04-01 00:23:34 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetDisplayMode),
|
|
|
|
sizeof(*GetDisplayModeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-04-01 00:23:34 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-04-01 00:23:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
*lpModeFlags = GetDisplayModeRequest->DisplayMode; // ModeFlags
|
2014-04-20 11:25:38 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
2015-12-04 00:43:31 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2015-12-04 00:43:31 +00:00
|
|
|
GetConsoleFontInfo(IN HANDLE hConsoleOutput,
|
|
|
|
IN BOOL bMaximumWindow,
|
|
|
|
IN DWORD nFontCount,
|
|
|
|
OUT PCONSOLE_FONT_INFO lpConsoleFontInfo)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETFONTINFO GetFontInfoRequest = &ApiMessage.Data.GetFontInfoRequest;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
|
|
|
|
|
|
|
GetFontInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetFontInfoRequest->OutputHandle = hConsoleOutput;
|
|
|
|
GetFontInfoRequest->MaximumWindow = bMaximumWindow;
|
|
|
|
GetFontInfoRequest->NumFonts = nFontCount;
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, nFontCount * sizeof(CONSOLE_FONT_INFO));
|
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
nFontCount * sizeof(CONSOLE_FONT_INFO),
|
|
|
|
(PVOID*)&GetFontInfoRequest->FontInfo);
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetFontInfo),
|
|
|
|
sizeof(*GetFontInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(lpConsoleFontInfo,
|
|
|
|
GetFontInfoRequest->FontInfo,
|
|
|
|
GetFontInfoRequest->NumFonts * sizeof(CONSOLE_FONT_INFO));
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
return GetFontInfoRequest->NumFonts;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2015-12-04 00:43:31 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
COORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2015-12-04 00:43:31 +00:00
|
|
|
GetConsoleFontSize(IN HANDLE hConsoleOutput,
|
|
|
|
IN DWORD nFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETFONTSIZE GetFontSizeRequest = &ApiMessage.Data.GetFontSizeRequest;
|
2009-01-30 14:25:00 +00:00
|
|
|
COORD Empty = {0, 0};
|
2015-12-04 00:43:31 +00:00
|
|
|
|
|
|
|
GetFontSizeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetFontSizeRequest->OutputHandle = hConsoleOutput;
|
|
|
|
GetFontSizeRequest->FontIndex = nFont;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetFontSize),
|
|
|
|
sizeof(*GetFontSizeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetFontSizeRequest->FontSize;
|
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,
|
2014-03-08 15:31:05 +00:00
|
|
|
PDWORD Flags,
|
2009-01-30 14:25:00 +00:00
|
|
|
PDWORD State)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
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-08-29 20:37:02 +00:00
|
|
|
DPRINT1("GetConsoleHardwareState(%lu, 0x%p) UNIMPLEMENTED!\n", Flags, State);
|
2013-04-01 00:23:34 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
if (Flags == NULL || State == NULL)
|
2013-04-09 15:21:14 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
HardwareStateRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
HardwareStateRequest->OutputHandle = hConsoleOutput;
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHardwareState),
|
|
|
|
sizeof(*HardwareStateRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
*Flags = HardwareStateRequest->Flags;
|
2013-01-05 23:10:12 +00:00
|
|
|
*State = HardwareStateRequest->State;
|
2014-04-20 11:25:38 +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
|
|
|
* @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
|
|
|
|
|
|
|
/*
|
2015-12-04 00:43:31 +00:00
|
|
|
* @implemented
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2013-06-16 21:35:18 +00:00
|
|
|
BOOL
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2015-12-04 00:43:31 +00:00
|
|
|
GetCurrentConsoleFont(IN HANDLE hConsoleOutput,
|
|
|
|
IN BOOL bMaximumWindow,
|
|
|
|
OUT PCONSOLE_FONT_INFO lpConsoleCurrentFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETCURRENTFONT GetCurrentFontRequest = &ApiMessage.Data.GetCurrentFontRequest;
|
|
|
|
|
|
|
|
GetCurrentFontRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetCurrentFontRequest->OutputHandle = hConsoleOutput;
|
|
|
|
GetCurrentFontRequest->MaximumWindow = bMaximumWindow;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCurrentFont),
|
|
|
|
sizeof(*GetCurrentFontRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpConsoleCurrentFont->dwFontSize = GetCurrentFontRequest->FontSize;
|
|
|
|
lpConsoleCurrentFont->nFont = GetCurrentFontRequest->FontIndex;
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2015-12-04 00:43:31 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2015-12-04 00:43:31 +00:00
|
|
|
DWORD
|
2009-01-30 14:25:00 +00:00
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
GetNumberOfConsoleFonts(VOID)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETNUMFONTS GetNumFontsRequest = &ApiMessage.Data.GetNumFontsRequest;
|
|
|
|
|
|
|
|
GetNumFontsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfFonts),
|
|
|
|
sizeof(*GetNumFontsRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetNumFontsRequest->NumFonts;
|
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
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest = &ApiMessage.Data.InvalidateDIBitsRequest;
|
|
|
|
|
|
|
|
if (lpRect == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
InvalidateDIBitsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
InvalidateDIBitsRequest->OutputHandle = hConsoleOutput;
|
|
|
|
InvalidateDIBitsRequest->Region = *lpRect;
|
2013-05-29 00:29:07 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepInvalidateBitMapRect),
|
|
|
|
sizeof(*InvalidateDIBitsRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-05-29 00:29:07 +00:00
|
|
|
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
|
|
|
/*
|
2014-08-14 20:10:00 +00:00
|
|
|
* @implemented (Undocumented)
|
2009-01-30 14:25:00 +00:00
|
|
|
*/
|
|
|
|
HANDLE
|
|
|
|
WINAPI
|
|
|
|
OpenConsoleW(LPCWSTR wsName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
BOOL bInheritHandle,
|
|
|
|
DWORD dwShareMode)
|
|
|
|
{
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
if (wsName && (_wcsicmp(wsName, BaseConInputFileName) == 0))
|
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
|
|
|
}
|
2014-04-20 11:25:38 +00:00
|
|
|
else if (wsName && (_wcsicmp(wsName, BaseConOutputFileName) == 0))
|
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
|
|
|
}
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
OpenConsoleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
OpenConsoleRequest->HandleType = HandleType;
|
|
|
|
OpenConsoleRequest->DesiredAccess = dwDesiredAccess;
|
|
|
|
OpenConsoleRequest->InheritHandle = bInheritHandle;
|
|
|
|
OpenConsoleRequest->ShareMode = dwShareMode;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepOpenConsole),
|
|
|
|
sizeof(*OpenConsoleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
return OpenConsoleRequest->Handle;
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-03-08 15:31:05 +00:00
|
|
|
SetConsoleCursor(HANDLE hConsoleOutput,
|
2013-06-01 22:49:50 +00:00
|
|
|
HCURSOR hCursor)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-06-01 22:49:50 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETCURSOR SetCursorRequest = &ApiMessage.Data.SetCursorRequest;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
SetCursorRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetCursorRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetCursorRequest->CursorHandle = hCursor;
|
2013-06-01 22:49:50 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursor),
|
|
|
|
sizeof(*SetCursorRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-06-01 22:49:50 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-06-01 22:49:50 +00:00
|
|
|
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,
|
2014-03-08 15:31:05 +00:00
|
|
|
DWORD dwFlags, // dwModeFlags
|
2013-04-01 00:23:34 +00:00
|
|
|
PCOORD lpNewScreenBufferDimensions)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-04-01 00:23:34 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETDISPLAYMODE SetDisplayModeRequest = &ApiMessage.Data.SetDisplayModeRequest;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
SetDisplayModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetDisplayModeRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetDisplayModeRequest->DisplayMode = dwFlags; // ModeFlags ; dwModeFlags
|
|
|
|
SetDisplayModeRequest->NewSBDim.X = 0;
|
|
|
|
SetDisplayModeRequest->NewSBDim.Y = 0;
|
|
|
|
/* SetDisplayModeRequest->EventHandle; */
|
2013-04-01 00:23:34 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetDisplayMode),
|
|
|
|
sizeof(*SetDisplayModeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-04-01 00:23:34 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-04-01 00:23:34 +00:00
|
|
|
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
|
|
|
|
|
|
|
/*
|
2015-12-04 00:43:31 +00:00
|
|
|
* @implemented (Undocumented)
|
|
|
|
* @note See http://cboard.cprogramming.com/windows-programming/102187-console-font-size.html
|
2003-07-10 18:50:51 +00:00
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2015-12-04 00:43:31 +00:00
|
|
|
SetConsoleFont(IN HANDLE hConsoleOutput,
|
|
|
|
IN DWORD nFont)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETFONT SetFontRequest = &ApiMessage.Data.SetFontRequest;
|
|
|
|
|
|
|
|
SetFontRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetFontRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetFontRequest->FontIndex = nFont;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetFont),
|
|
|
|
sizeof(*SetFontRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
* @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
|
|
|
{
|
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-08-29 20:37:02 +00:00
|
|
|
DPRINT1("SetConsoleHardwareState(%lu, %lu) UNIMPLEMENTED!\n", Flags, State);
|
2013-04-01 00:23:34 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
HardwareStateRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
HardwareStateRequest->OutputHandle = hConsoleOutput;
|
|
|
|
HardwareStateRequest->Flags = Flags;
|
|
|
|
HardwareStateRequest->State = State;
|
2003-06-19 19:38:26 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHardwareState),
|
|
|
|
sizeof(*HardwareStateRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
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-08-29 20:37:02 +00:00
|
|
|
DPRINT1("SetConsoleMaximumWindowSize(0x%p, {%d, %d}) does nothing\n",
|
2013-06-01 22:49:50 +00:00
|
|
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETMENUCLOSE SetMenuCloseRequest = &ApiMessage.Data.SetMenuCloseRequest;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
SetMenuCloseRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetMenuCloseRequest->Enable = bEnable;
|
2013-05-30 00:50:03 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMenuClose),
|
|
|
|
sizeof(*SetMenuCloseRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-05-30 00:50:03 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-05-30 00:50:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-03-31 01:17:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
|
|
|
|
/*
|
2013-08-12 16:12:58 +00:00
|
|
|
* @implemented (Undocumented)
|
2013-08-11 17:06:19 +00:00
|
|
|
* @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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2013-08-11 17:06:19 +00:00
|
|
|
SetConsolePalette(HANDLE hConsoleOutput,
|
|
|
|
HPALETTE hPalette,
|
|
|
|
UINT dwUsage)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2013-08-12 16:12:58 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETPALETTE SetPaletteRequest = &ApiMessage.Data.SetPaletteRequest;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
SetPaletteRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2013-08-12 16:12:58 +00:00
|
|
|
SetPaletteRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetPaletteRequest->PaletteHandle = hPalette;
|
|
|
|
SetPaletteRequest->Usage = dwUsage;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetPalette),
|
|
|
|
sizeof(*SetPaletteRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-08-12 16:12:58 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-08-12 16:12:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-11 17:06:19 +00:00
|
|
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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;
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
ShowCursorRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ShowCursorRequest->OutputHandle = hConsoleOutput;
|
|
|
|
ShowCursorRequest->Show = bShow;
|
|
|
|
ShowCursorRequest->RefCount = 0;
|
2013-06-01 22:49:50 +00:00
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepShowCursor),
|
2014-03-08 15:31:05 +00:00
|
|
|
sizeof(*ShowCursorRequest));
|
2013-06-01 22:49:50 +00:00
|
|
|
|
|
|
|
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:
|
2014-03-08 15:31:05 +00:00
|
|
|
* hIoHandle - Handle to be checked.
|
2012-11-17 23:29:53 +00:00
|
|
|
*
|
2003-03-05 22:51:48 +00:00
|
|
|
* RETURNS:
|
2014-03-08 15:31:05 +00:00
|
|
|
* TRUE : Handle is a valid console handle.
|
2003-03-05 22:51:48 +00:00
|
|
|
* 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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-03-08 15:31:05 +00:00
|
|
|
VerifyConsoleIoHandle(HANDLE hIoHandle)
|
2001-03-31 01:17:30 +00:00
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_VERIFYHANDLE VerifyHandleRequest = &ApiMessage.Data.VerifyHandleRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
VerifyHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
VerifyHandleRequest->Handle = hIoHandle;
|
|
|
|
VerifyHandleRequest->IsValid = FALSE;
|
2002-08-22 15:21:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
/* If the process is not attached to a console, return invalid handle */
|
|
|
|
if (VerifyHandleRequest->ConsoleHandle == NULL) return FALSE;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepVerifyIoHandle),
|
|
|
|
sizeof(*VerifyHandleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 18:06:17 +00:00
|
|
|
return FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2002-08-22 15:21:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return VerifyHandleRequest->IsValid;
|
2004-11-02 20:42:06 +00:00
|
|
|
}
|
2002-08-22 15:21:57 +00:00
|
|
|
|
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented (Undocumented)
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-03-08 15:31:05 +00:00
|
|
|
CloseConsoleHandle(HANDLE hHandle)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_CLOSEHANDLE CloseHandleRequest = &ApiMessage.Data.CloseHandleRequest;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CloseHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
CloseHandleRequest->Handle = hHandle;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCloseHandle),
|
|
|
|
sizeof(*CloseHandleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2002-10-20 00:34:40 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2012-11-15 18:06:17 +00:00
|
|
|
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;
|
2014-03-08 15:31:05 +00:00
|
|
|
HANDLE Handle = INVALID_HANDLE_VALUE;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
switch (nStdHandle)
|
|
|
|
{
|
|
|
|
case STD_INPUT_HANDLE:
|
2014-03-08 15:31:05 +00:00
|
|
|
Handle = Ppb->StandardInput;
|
|
|
|
break;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_OUTPUT_HANDLE:
|
2014-03-08 15:31:05 +00:00
|
|
|
Handle = Ppb->StandardOutput;
|
|
|
|
break;
|
2002-10-20 00:34:40 +00:00
|
|
|
|
2012-11-15 18:06:17 +00:00
|
|
|
case STD_ERROR_HANDLE:
|
2014-03-08 15:31:05 +00:00
|
|
|
Handle = Ppb->StandardError;
|
|
|
|
break;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
/* If the returned handle is invalid, set last error */
|
|
|
|
if (Handle == INVALID_HANDLE_VALUE) SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
|
|
|
|
return Handle;
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-03-08 15:31:05 +00:00
|
|
|
SetStdHandle(DWORD nStdHandle,
|
2012-11-15 18:06:17 +00:00
|
|
|
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
|
|
|
|
2014-03-08 15:31:05 +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
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
/* nStdHandle was invalid, bail out */
|
2012-11-15 18:06:17 +00:00
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-11-02 20:42:06 +00:00
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2012-11-15 18:06:17 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2014-09-07 22:53:49 +00:00
|
|
|
static BOOL
|
|
|
|
IntAllocConsole(LPWSTR Title,
|
|
|
|
DWORD TitleLength,
|
|
|
|
LPWSTR Desktop,
|
|
|
|
DWORD DesktopLength,
|
|
|
|
LPWSTR CurDir,
|
|
|
|
DWORD CurDirLength,
|
|
|
|
LPWSTR AppName,
|
|
|
|
DWORD AppNameLength,
|
|
|
|
LPTHREAD_START_ROUTINE CtrlRoutine,
|
|
|
|
LPTHREAD_START_ROUTINE PropRoutine,
|
|
|
|
PCONSOLE_START_INFO ConsoleStartInfo)
|
|
|
|
{
|
|
|
|
BOOL Success = TRUE;
|
2012-11-15 18:06:17 +00:00
|
|
|
NTSTATUS Status;
|
2014-09-07 22:53:49 +00:00
|
|
|
|
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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsoleRequest->CtrlRoutine = CtrlRoutine;
|
|
|
|
AllocConsoleRequest->PropRoutine = PropRoutine;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(5, TitleLength +
|
|
|
|
DesktopLength +
|
|
|
|
CurDirLength +
|
|
|
|
AppNameLength +
|
|
|
|
sizeof(CONSOLE_START_INFO));
|
2013-02-10 12:36:57 +00:00
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2014-09-07 22:53:49 +00:00
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2013-02-10 12:36:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
ConsoleStartInfo,
|
|
|
|
sizeof(CONSOLE_START_INFO),
|
|
|
|
(PVOID*)&AllocConsoleRequest->ConsoleStartInfo);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsoleRequest->TitleLength = TitleLength;
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
Title,
|
|
|
|
TitleLength,
|
|
|
|
(PVOID*)&AllocConsoleRequest->ConsoleTitle);
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsoleRequest->DesktopLength = DesktopLength;
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
Desktop,
|
|
|
|
DesktopLength,
|
|
|
|
(PVOID*)&AllocConsoleRequest->Desktop);
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsoleRequest->CurDirLength = CurDirLength;
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
CurDir,
|
|
|
|
CurDirLength,
|
|
|
|
(PVOID*)&AllocConsoleRequest->CurDir);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsoleRequest->AppNameLength = AppNameLength;
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
AppName,
|
|
|
|
AppNameLength,
|
|
|
|
(PVOID*)&AllocConsoleRequest->AppName);
|
2013-02-10 12:36:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAlloc),
|
|
|
|
sizeof(*AllocConsoleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
2014-11-22 22:13:08 +00:00
|
|
|
// Is AllocConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
|
|
|
|
Status = NtWaitForMultipleObjects(MAX_INIT_EVENTS,
|
|
|
|
AllocConsoleRequest->ConsoleStartInfo->InitEvents,
|
2014-09-07 22:53:49 +00:00
|
|
|
WaitAny, FALSE, NULL);
|
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);
|
2014-09-07 22:53:49 +00:00
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2014-11-22 22:13:08 +00:00
|
|
|
NtClose(AllocConsoleRequest->ConsoleStartInfo->InitEvents[INIT_SUCCESS]);
|
|
|
|
NtClose(AllocConsoleRequest->ConsoleStartInfo->InitEvents[INIT_FAILURE]);
|
|
|
|
if (Status != INIT_SUCCESS)
|
2014-09-07 22:53:49 +00:00
|
|
|
{
|
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
|
|
|
|
Success = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(ConsoleStartInfo,
|
|
|
|
AllocConsoleRequest->ConsoleStartInfo,
|
|
|
|
sizeof(CONSOLE_START_INFO));
|
|
|
|
Success = TRUE;
|
|
|
|
}
|
2012-11-15 18:06:17 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
Quit:
|
|
|
|
if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-09-07 22:53:49 +00:00
|
|
|
AllocConsole(VOID)
|
|
|
|
{
|
|
|
|
BOOL Success;
|
|
|
|
CONSOLE_START_INFO ConsoleStartInfo;
|
2013-01-01 23:36:19 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
PWCHAR ConsoleTitle;
|
|
|
|
PWCHAR Desktop;
|
|
|
|
PWCHAR AppName;
|
|
|
|
PWCHAR CurDir;
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
ULONG TitleLength = (MAX_PATH + 1) * sizeof(WCHAR);
|
|
|
|
ULONG DesktopLength = (MAX_PATH + 1) * sizeof(WCHAR);
|
|
|
|
ULONG AppNameLength = 128 * sizeof(WCHAR);
|
|
|
|
ULONG CurDirLength = (MAX_PATH + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
LCID lcid;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
|
|
|
|
|
|
|
if (NtCurrentPeb()->ProcessParameters->ConsoleHandle)
|
|
|
|
{
|
|
|
|
DPRINT1("AllocConsole: Allocating a console to a process already having one\n");
|
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the console properties */
|
|
|
|
SetUpConsoleInfo(FALSE,
|
|
|
|
&TitleLength,
|
|
|
|
&ConsoleTitle,
|
|
|
|
&DesktopLength,
|
|
|
|
&Desktop,
|
|
|
|
&ConsoleStartInfo);
|
|
|
|
DPRINT("ConsoleTitle = '%S' - Desktop = '%S'\n",
|
|
|
|
ConsoleTitle, Desktop);
|
|
|
|
|
|
|
|
/* Initialize the Input EXE name */
|
|
|
|
InitExeName();
|
|
|
|
SetUpAppName(FALSE,
|
|
|
|
&CurDirLength,
|
|
|
|
&CurDir,
|
|
|
|
&AppNameLength,
|
|
|
|
&AppName);
|
|
|
|
DPRINT("CurDir = '%S' - AppName = '%S'\n",
|
|
|
|
CurDir, AppName);
|
|
|
|
|
|
|
|
Success = IntAllocConsole(ConsoleTitle,
|
|
|
|
TitleLength,
|
|
|
|
Desktop,
|
|
|
|
DesktopLength,
|
|
|
|
CurDir,
|
|
|
|
CurDirLength,
|
|
|
|
AppName,
|
|
|
|
AppNameLength,
|
|
|
|
ConsoleControlDispatcher,
|
|
|
|
PropDialogHandler,
|
|
|
|
&ConsoleStartInfo);
|
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
/* Set up the handles */
|
|
|
|
SetUpHandles(&ConsoleStartInfo);
|
|
|
|
InputWaitHandle = ConsoleStartInfo.InputWaitHandle;
|
|
|
|
|
|
|
|
/* Initialize Console Ctrl Handling */
|
|
|
|
InitializeCtrlHandling();
|
|
|
|
|
2014-09-09 21:24:44 +00:00
|
|
|
/* Sets the current console locale for this thread */
|
2014-09-07 22:53:49 +00:00
|
|
|
SetTEBLangID(lcid);
|
|
|
|
}
|
|
|
|
|
|
|
|
Quit:
|
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
|
|
|
return Success;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-11-02 20:42:06 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2012-11-15 18:06:17 +00:00
|
|
|
FreeConsole(VOID)
|
2004-11-02 20:42:06 +00:00
|
|
|
{
|
2015-04-05 23:42:26 +00:00
|
|
|
BOOL Success = TRUE;
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-08-06 21:01:23 +00:00
|
|
|
PCONSOLE_FREECONSOLE FreeConsoleRequest = &ApiMessage.Data.FreeConsoleRequest;
|
|
|
|
HANDLE ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2004-11-02 20:42:06 +00:00
|
|
|
|
2015-04-05 23:42:26 +00:00
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
|
|
|
|
2014-08-06 21:01:23 +00:00
|
|
|
/* We must have a non-trivial handle to close */
|
|
|
|
if (ConsoleHandle == NULL) // IsConsoleHandle(ConsoleHandle)
|
2012-11-15 18:06:17 +00:00
|
|
|
{
|
2014-08-06 21:01:23 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2015-04-05 23:42:26 +00:00
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2012-11-15 18:06:17 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 21:01:23 +00:00
|
|
|
/* Set up the data to send to the Console Server */
|
|
|
|
FreeConsoleRequest->ConsoleHandle = ConsoleHandle;
|
|
|
|
|
|
|
|
/* Call the server */
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFree),
|
|
|
|
sizeof(*FreeConsoleRequest));
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2015-04-05 23:42:26 +00:00
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2014-08-06 21:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the console handle */
|
2012-11-15 18:06:17 +00:00
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
|
2013-01-01 23:36:19 +00:00
|
|
|
|
2014-08-06 21:01:23 +00:00
|
|
|
/* Close the associated input handle */
|
2013-01-01 23:36:19 +00:00
|
|
|
CloseHandle(InputWaitHandle);
|
|
|
|
InputWaitHandle = INVALID_HANDLE_VALUE;
|
|
|
|
|
2015-04-05 23:42:26 +00:00
|
|
|
Quit:
|
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
|
|
|
return Success;
|
2003-07-09 10:43:08 +00:00
|
|
|
}
|
1999-03-06 10:57:02 +00:00
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
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
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_GETSCREENBUFFERINFO ScreenBufferInfoRequest = &ApiMessage.Data.ScreenBufferInfoRequest;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
ScreenBufferInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ScreenBufferInfoRequest->OutputHandle = hConsoleOutput;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetScreenBufferInfo),
|
|
|
|
sizeof(*ScreenBufferInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 18:06:17 +00:00
|
|
|
return FALSE;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2012-11-17 23:29:53 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
lpConsoleScreenBufferInfo->dwSize = ScreenBufferInfoRequest->ScreenBufferSize;
|
|
|
|
lpConsoleScreenBufferInfo->dwCursorPosition = ScreenBufferInfoRequest->CursorPosition;
|
|
|
|
lpConsoleScreenBufferInfo->wAttributes = ScreenBufferInfoRequest->Attributes;
|
|
|
|
lpConsoleScreenBufferInfo->srWindow.Left = ScreenBufferInfoRequest->ViewOrigin.X;
|
|
|
|
lpConsoleScreenBufferInfo->srWindow.Top = ScreenBufferInfoRequest->ViewOrigin.Y;
|
|
|
|
lpConsoleScreenBufferInfo->srWindow.Right = ScreenBufferInfoRequest->ViewOrigin.X + ScreenBufferInfoRequest->ViewSize.X - 1;
|
|
|
|
lpConsoleScreenBufferInfo->srWindow.Bottom = ScreenBufferInfoRequest->ViewOrigin.Y + ScreenBufferInfoRequest->ViewSize.Y - 1;
|
|
|
|
lpConsoleScreenBufferInfo->dwMaximumWindowSize = ScreenBufferInfoRequest->MaximumViewSize;
|
2012-11-17 23:29:53 +00:00
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2012-11-15 18:06:17 +00:00
|
|
|
SetConsoleCursorPosition(HANDLE hConsoleOutput,
|
|
|
|
COORD dwCursorPosition)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_SETCURSORPOSITION SetCursorPositionRequest = &ApiMessage.Data.SetCursorPositionRequest;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
SetCursorPositionRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetCursorPositionRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetCursorPositionRequest->Position = dwCursorPosition;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorPosition),
|
|
|
|
sizeof(*SetCursorPositionRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
GetConsoleMode(HANDLE hConsoleHandle,
|
|
|
|
LPDWORD lpMode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
ConsoleModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ConsoleModeRequest->Handle = hConsoleHandle;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMode),
|
|
|
|
sizeof(*ConsoleModeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
*lpMode = ConsoleModeRequest->Mode;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2014-04-20 11:25:38 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-04-20 11:25:38 +00:00
|
|
|
SetConsoleMode(HANDLE hConsoleHandle,
|
|
|
|
DWORD dwMode)
|
|
|
|
{
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &ApiMessage.Data.ConsoleModeRequest;
|
|
|
|
|
|
|
|
ConsoleModeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ConsoleModeRequest->Handle = hConsoleHandle;
|
|
|
|
ConsoleModeRequest->Mode = dwMode;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetMode),
|
|
|
|
sizeof(*ConsoleModeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-30 14:25:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,
|
|
|
|
LPDWORD lpNumberOfEvents)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
GetNumInputEventsRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetNumInputEventsRequest->InputHandle = hConsoleInput;
|
|
|
|
GetNumInputEventsRequest->NumberOfEvents = 0;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetNumberOfInputEvents),
|
|
|
|
sizeof(*GetNumInputEventsRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
*lpNumberOfEvents = GetNumInputEventsRequest->NumberOfEvents;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2013-04-09 15:21:14 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
COORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest = &ApiMessage.Data.GetLargestWindowSizeRequest;
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
GetLargestWindowSizeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetLargestWindowSize),
|
|
|
|
sizeof(*GetLargestWindowSizeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-04-09 15:21:14 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-04-09 15:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 21:01:23 +00:00
|
|
|
DPRINT("GetLargestConsoleWindowSize, X = %d, Y = %d\n", GetLargestWindowSizeRequest->Size.X, GetLargestWindowSizeRequest->Size.Y);
|
2013-04-09 15:21:14 +00:00
|
|
|
return GetLargestWindowSizeRequest->Size;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
GetConsoleCursorInfo(HANDLE hConsoleOutput,
|
|
|
|
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &ApiMessage.Data.CursorInfoRequest;
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CursorInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
CursorInfoRequest->OutputHandle = hConsoleOutput;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCursorInfo),
|
|
|
|
sizeof(*CursorInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
*lpConsoleCursorInfo = 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-04-20 11:25:38 +00:00
|
|
|
SetConsoleCursorInfo(HANDLE hConsoleOutput,
|
|
|
|
CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:07:59 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_GETSETCURSORINFO CursorInfoRequest = &ApiMessage.Data.CursorInfoRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CursorInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
CursorInfoRequest->OutputHandle = hConsoleOutput;
|
|
|
|
CursorInfoRequest->Info = *lpConsoleCursorInfo;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCursorInfo),
|
|
|
|
sizeof(*CursorInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2014-07-28 13:20:54 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-04-20 11:25:38 +00:00
|
|
|
GetNumberOfConsoleMouseButtons(LPDWORD lpNumberOfMouseButtons)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2014-07-28 13:20:54 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETMOUSEINFO GetMouseInfoRequest = &ApiMessage.Data.GetMouseInfoRequest;
|
|
|
|
|
|
|
|
GetMouseInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetMouseInfo),
|
|
|
|
sizeof(*GetMouseInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpNumberOfMouseButtons = GetMouseInfoRequest->NumButtons;
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-04-20 11:25:38 +00:00
|
|
|
SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_SETACTIVESCREENBUFFER SetScreenBufferRequest = &ApiMessage.Data.SetScreenBufferRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
SetScreenBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetScreenBufferRequest->OutputHandle = hConsoleOutput;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetActiveScreenBuffer),
|
|
|
|
sizeof(*SetScreenBufferRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2010-05-12 03:34:02 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-04-20 11:25:38 +00:00
|
|
|
FlushConsoleInputBuffer(HANDLE hConsoleInput)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_FLUSHINPUTBUFFER FlushInputBufferRequest = &ApiMessage.Data.FlushInputBufferRequest;
|
2010-05-12 03:34:02 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
FlushInputBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
FlushInputBufferRequest->InputHandle = hConsoleInput;
|
2010-05-12 03:34:02 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepFlushInputBuffer),
|
|
|
|
sizeof(*FlushInputBufferRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2010-05-12 03:34:02 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-04-20 11:25:38 +00:00
|
|
|
SetConsoleScreenBufferSize(HANDLE hConsoleOutput,
|
|
|
|
COORD dwSize)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-17 23:29:53 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_SETSCREENBUFFERSIZE SetScreenBufferSizeRequest = &ApiMessage.Data.SetScreenBufferSizeRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
SetScreenBufferSizeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetScreenBufferSizeRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetScreenBufferSizeRequest->Size = dwSize;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetScreenBufferSize),
|
|
|
|
sizeof(*SetScreenBufferSizeRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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,
|
2014-05-08 18:08:07 +00:00
|
|
|
CONST SMALL_RECT* lpScrollRectangle,
|
|
|
|
CONST SMALL_RECT* lpClipRectangle,
|
2004-11-02 20:42:06 +00:00
|
|
|
COORD dwDestinationOrigin,
|
2014-05-08 18:08:07 +00:00
|
|
|
CONST CHAR_INFO* lpFill,
|
2004-11-02 20:42:06 +00:00
|
|
|
BOOL bUnicode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
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
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
ScrollScreenBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
ScrollScreenBufferRequest->OutputHandle = hConsoleOutput;
|
2013-01-05 23:10:12 +00:00
|
|
|
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;
|
2014-05-08 18:08:07 +00:00
|
|
|
ScrollScreenBufferRequest->Fill = *lpFill;
|
|
|
|
ScrollScreenBufferRequest->Unicode = bUnicode;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepScrollScreenBuffer),
|
|
|
|
sizeof(*ScrollScreenBufferRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-05-08 18:08:07 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-11-02 20:42:06 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
ScrollConsoleScreenBufferA(HANDLE hConsoleOutput,
|
2014-05-08 18:08:07 +00:00
|
|
|
CONST SMALL_RECT* lpScrollRectangle,
|
|
|
|
CONST SMALL_RECT* lpClipRectangle,
|
2009-01-30 14:25:00 +00:00
|
|
|
COORD dwDestinationOrigin,
|
2014-05-08 18:08:07 +00:00
|
|
|
CONST CHAR_INFO* lpFill)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
|
|
|
return IntScrollConsoleScreenBuffer(hConsoleOutput,
|
2014-05-08 18:08:07 +00:00
|
|
|
lpScrollRectangle,
|
|
|
|
lpClipRectangle,
|
2009-01-30 14:25:00 +00:00
|
|
|
dwDestinationOrigin,
|
2014-05-08 18:08:07 +00:00
|
|
|
lpFill,
|
2009-01-30 14:25:00 +00:00
|
|
|
FALSE);
|
2004-11-02 20:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-11-02 20:42:06 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_SETWINDOWINFO SetWindowInfoRequest = &ApiMessage.Data.SetWindowInfoRequest;
|
|
|
|
|
|
|
|
if (lpConsoleWindow == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
SetWindowInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetWindowInfoRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetWindowInfoRequest->Absolute = bAbsolute;
|
|
|
|
SetWindowInfoRequest->WindowRect = *lpConsoleWindow;
|
2013-04-09 15:21:14 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetWindowInfo),
|
|
|
|
sizeof(*SetWindowInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2013-04-09 15:21:14 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2013-04-09 15:21:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleTextAttribute(HANDLE hConsoleOutput,
|
|
|
|
WORD wAttributes)
|
1999-03-30 21:58:05 +00:00
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_SETTEXTATTRIB SetTextAttribRequest = &ApiMessage.Data.SetTextAttribRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
SetTextAttribRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetTextAttribRequest->OutputHandle = hConsoleOutput;
|
|
|
|
SetTextAttribRequest->Attributes = wAttributes;
|
2000-05-26 06:06:42 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTextAttribute),
|
|
|
|
sizeof(*SetTextAttribRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
|
|
|
2015-04-05 23:42:26 +00:00
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
|
|
|
|
2009-01-30 14:25:00 +00:00
|
|
|
if (Add)
|
|
|
|
Ret = AddConsoleCtrlHandler(HandlerRoutine);
|
|
|
|
else
|
|
|
|
Ret = RemoveConsoleCtrlHandler(HandlerRoutine);
|
|
|
|
|
2015-04-05 23:42:26 +00:00
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
|
|
|
return Ret;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
|
|
|
|
DWORD dwProcessGroupId)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-04-20 11:25:38 +00:00
|
|
|
PCONSOLE_GENERATECTRLEVENT GenerateCtrlEventRequest = &ApiMessage.Data.GenerateCtrlEventRequest;
|
2008-08-02 17:01:22 +00:00
|
|
|
|
|
|
|
if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
GenerateCtrlEventRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GenerateCtrlEventRequest->CtrlEvent = dwCtrlEvent;
|
|
|
|
GenerateCtrlEventRequest->ProcessGroupId = dwProcessGroupId;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGenerateCtrlEvent),
|
|
|
|
sizeof(*GenerateCtrlEventRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2008-08-02 17:01:22 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
2014-04-20 11:25:38 +00:00
|
|
|
IntGetConsoleTitle(LPVOID lpConsoleTitle, DWORD dwNumChars, BOOLEAN bUnicode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
if (dwNumChars == 0) return 0;
|
|
|
|
|
|
|
|
TitleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
TitleRequest->Length = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
|
|
|
TitleRequest->Unicode = bUnicode;
|
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);
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetTitle),
|
|
|
|
sizeof(*TitleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
dwNumChars = TitleRequest->Length / (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
|
|
|
|
|
|
|
if (dwNumChars > 0)
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
RtlCopyMemory(lpConsoleTitle, TitleRequest->Title, TitleRequest->Length);
|
2014-04-20 11:25:38 +00:00
|
|
|
|
|
|
|
if (bUnicode)
|
2014-09-07 22:53:49 +00:00
|
|
|
((LPWSTR)lpConsoleTitle)[dwNumChars] = UNICODE_NULL;
|
2014-04-20 11:25:38 +00:00
|
|
|
else
|
2014-09-07 22:53:49 +00:00
|
|
|
((LPSTR)lpConsoleTitle)[dwNumChars] = ANSI_NULL;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
2014-04-20 11:25:38 +00:00
|
|
|
|
2010-06-04 06:36:12 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2005-08-28 12:03:25 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
return dwNumChars;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2010-06-04 06:36:12 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2010-06-04 06:36:12 +00:00
|
|
|
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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
static BOOL
|
2014-05-08 22:24:38 +00:00
|
|
|
IntSetConsoleTitle(CONST VOID *lpConsoleTitle, BOOLEAN bUnicode)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
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
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
ULONG NumChars = (ULONG)(lpConsoleTitle ? (bUnicode ? wcslen(lpConsoleTitle) : strlen(lpConsoleTitle)) : 0);
|
2014-05-08 22:24:38 +00:00
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
TitleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2014-08-04 17:13:43 +00:00
|
|
|
TitleRequest->Length = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2014-04-20 11:25:38 +00:00
|
|
|
TitleRequest->Unicode = bUnicode;
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetTitle),
|
|
|
|
sizeof(*TitleRequest));
|
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
|
|
|
|
2014-04-20 11:25:38 +00:00
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2001-06-22 02:11:44 +00:00
|
|
|
{
|
2014-04-20 11:25:38 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
}
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2014-04-20 11:25:38 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-04-20 11:25:38 +00:00
|
|
|
SetConsoleTitleW(LPCWSTR lpConsoleTitle)
|
|
|
|
{
|
2014-05-08 22:24:38 +00:00
|
|
|
return IntSetConsoleTitle(lpConsoleTitle, TRUE);
|
2014-04-20 11:25:38 +00:00
|
|
|
}
|
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2003-07-10 18:50:51 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleTitleA(LPCSTR lpConsoleTitle)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2014-05-08 22:24:38 +00:00
|
|
|
return IntSetConsoleTitle(lpConsoleTitle, FALSE);
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
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
|
|
|
{
|
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;
|
2014-04-20 22:40:39 +00:00
|
|
|
PCONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo = 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
|
|
|
|
2014-04-20 22:40:39 +00:00
|
|
|
CreateScreenBufferRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
CreateScreenBufferRequest->DesiredAccess = dwDesiredAccess;
|
|
|
|
CreateScreenBufferRequest->InheritHandle =
|
2012-11-17 23:45:14 +00:00
|
|
|
(lpSecurityAttributes ? lpSecurityAttributes->bInheritHandle : FALSE);
|
2014-04-20 22:40:39 +00:00
|
|
|
CreateScreenBufferRequest->ShareMode = dwShareMode;
|
|
|
|
CreateScreenBufferRequest->ScreenBufferType = dwFlags;
|
2008-07-22 17:37:13 +00:00
|
|
|
|
2013-05-29 00:29:07 +00:00
|
|
|
if (dwFlags == CONSOLE_GRAPHICS_BUFFER)
|
|
|
|
{
|
2014-04-20 22:40:39 +00:00
|
|
|
if (CreateScreenBufferRequest->InheritHandle || GraphicsBufferInfo == NULL)
|
2013-05-29 00:29:07 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateScreenBufferRequest->GraphicsBufferInfo = *GraphicsBufferInfo;
|
|
|
|
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, GraphicsBufferInfo->dwBitMapInfoLength);
|
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2014-04-20 22:40:39 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)GraphicsBufferInfo->lpBitMapInfo,
|
|
|
|
GraphicsBufferInfo->dwBitMapInfoLength,
|
|
|
|
(PVOID*)&CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMapInfo);
|
|
|
|
}
|
|
|
|
|
2014-04-20 22:40:39 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepCreateScreenBuffer),
|
|
|
|
sizeof(*CreateScreenBufferRequest));
|
2013-05-29 00:29:07 +00:00
|
|
|
|
2014-04-20 22:40:39 +00:00
|
|
|
if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
|
2013-05-29 00:29:07 +00:00
|
|
|
|
2014-04-20 22:40:39 +00:00
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-04-20 22:40:39 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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)
|
|
|
|
{
|
2014-04-20 22:40:39 +00:00
|
|
|
GraphicsBufferInfo->hMutex = CreateScreenBufferRequest->hMutex ; // CreateScreenBufferRequest->GraphicsBufferInfo.hMutex ;
|
|
|
|
GraphicsBufferInfo->lpBitMap = CreateScreenBufferRequest->lpBitMap; // CreateScreenBufferRequest->GraphicsBufferInfo.lpBitMap;
|
2013-05-29 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CreateScreenBufferRequest->OutputHandle;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleCP(VOID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest = &ApiMessage.Data.GetConsoleCPRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Get the Input Code Page */
|
2014-03-08 15:31:05 +00:00
|
|
|
GetConsoleCPRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetConsoleCPRequest->OutputCP = FALSE;
|
2013-06-14 01:00:49 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
|
|
|
|
sizeof(*GetConsoleCPRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return GetConsoleCPRequest->CodePage;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-08-24 17:21:12 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleCP(UINT wCodePageID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest = &ApiMessage.Data.SetConsoleCPRequest;
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Set the Input Code Page */
|
2014-03-08 15:31:05 +00:00
|
|
|
SetConsoleCPRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetConsoleCPRequest->CodePage = wCodePageID;
|
|
|
|
SetConsoleCPRequest->OutputCP = FALSE;
|
|
|
|
/* SetConsoleCPRequest->EventHandle; */
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
|
|
|
|
sizeof(*SetConsoleCPRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
UINT
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleOutputCP(VOID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_GETINPUTOUTPUTCP GetConsoleCPRequest = &ApiMessage.Data.GetConsoleCPRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Get the Output Code Page */
|
2014-03-08 15:31:05 +00:00
|
|
|
GetConsoleCPRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetConsoleCPRequest->OutputCP = TRUE;
|
2012-11-18 13:10:03 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetCP),
|
|
|
|
sizeof(*GetConsoleCPRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return GetConsoleCPRequest->CodePage;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-08-22 20:52:28 +00:00
|
|
|
* @implemented
|
1999-03-06 10:57:02 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
SetConsoleOutputCP(UINT wCodePageID)
|
1999-03-06 10:57:02 +00:00
|
|
|
{
|
2012-11-18 13:10:03 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_SETINPUTOUTPUTCP SetConsoleCPRequest = &ApiMessage.Data.SetConsoleCPRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2012-11-18 13:10:03 +00:00
|
|
|
/* Set the Output Code Page */
|
2014-03-08 15:31:05 +00:00
|
|
|
SetConsoleCPRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetConsoleCPRequest->CodePage = wCodePageID;
|
|
|
|
SetConsoleCPRequest->OutputCP = TRUE;
|
|
|
|
/* SetConsoleCPRequest->EventHandle; */
|
2012-10-17 23:10:40 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetCP),
|
|
|
|
sizeof(*SetConsoleCPRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return TRUE;
|
1999-03-06 10:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
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;
|
2014-03-08 15:31:05 +00:00
|
|
|
ULONG nProcesses = 0;
|
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);
|
2014-03-08 15:31:05 +00:00
|
|
|
return 0;
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
GetProcessListRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetProcessListRequest->ProcessCount = dwProcessCount;
|
2012-11-18 13:10:03 +00:00
|
|
|
|
2010-05-23 17:40:54 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
dwProcessCount * sizeof(DWORD),
|
2014-03-08 15:31:05 +00:00
|
|
|
(PVOID*)&GetProcessListRequest->ProcessIdsList);
|
2009-01-30 14:25:00 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetProcessList),
|
|
|
|
sizeof(*GetProcessListRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
}
|
|
|
|
else
|
2005-02-05 01:44:05 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
nProcesses = GetProcessListRequest->ProcessCount;
|
2009-01-30 14:25:00 +00:00
|
|
|
if (dwProcessCount >= nProcesses)
|
|
|
|
{
|
2015-12-04 00:43:31 +00:00
|
|
|
RtlCopyMemory(lpdwProcessList, GetProcessListRequest->ProcessIdsList, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +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
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_GETSELECTIONINFO GetSelectionInfoRequest = &ApiMessage.Data.GetSelectionInfoRequest;
|
2012-11-17 23:45:14 +00:00
|
|
|
|
|
|
|
if (lpConsoleSelectionInfo == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
GetSelectionInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetSelectionInfo),
|
|
|
|
sizeof(*GetSelectionInfoRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2010-05-23 22:38:16 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2010-05-23 22:38:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
*lpConsoleSelectionInfo = GetSelectionInfoRequest->Info;
|
2014-04-20 11:25:38 +00:00
|
|
|
|
2010-05-23 22:38:16 +00:00
|
|
|
return TRUE;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2013-01-13 17:07:25 +00:00
|
|
|
* @implemented
|
|
|
|
* @note Strongly inspired by AllocConsole.
|
2002-10-20 00:34:40 +00:00
|
|
|
*/
|
2014-09-07 22:53:49 +00:00
|
|
|
static BOOL
|
|
|
|
IntAttachConsole(DWORD ProcessId,
|
|
|
|
LPTHREAD_START_ROUTINE CtrlRoutine,
|
|
|
|
LPTHREAD_START_ROUTINE PropRoutine,
|
|
|
|
PCONSOLE_START_INFO ConsoleStartInfo)
|
2002-10-20 00:34:40 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
BOOL Success = TRUE;
|
2013-01-13 17:07:25 +00:00
|
|
|
NTSTATUS Status;
|
2014-09-07 22:53:49 +00:00
|
|
|
|
2013-01-13 17:07:25 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_ATTACHCONSOLE AttachConsoleRequest = &ApiMessage.Data.AttachConsoleRequest;
|
2014-09-07 22:53:49 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
|
|
|
|
|
|
|
AttachConsoleRequest->ProcessId = ProcessId;
|
|
|
|
AttachConsoleRequest->CtrlRoutine = CtrlRoutine;
|
|
|
|
AttachConsoleRequest->PropRoutine = PropRoutine;
|
2013-01-13 17:07:25 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, sizeof(CONSOLE_START_INFO));
|
|
|
|
if (CaptureBuffer == NULL)
|
2013-01-13 17:07:25 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2013-01-13 17:07:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
ConsoleStartInfo,
|
|
|
|
sizeof(CONSOLE_START_INFO),
|
|
|
|
(PVOID*)&AttachConsoleRequest->ConsoleStartInfo);
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAttach),
|
|
|
|
sizeof(*AttachConsoleRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
2013-01-13 17:07:25 +00:00
|
|
|
|
2014-11-22 22:13:08 +00:00
|
|
|
// Is AttachConsoleRequest->ConsoleStartInfo->InitEvents aligned on handle boundary ????
|
|
|
|
Status = NtWaitForMultipleObjects(MAX_INIT_EVENTS,
|
|
|
|
AttachConsoleRequest->ConsoleStartInfo->InitEvents,
|
2014-09-07 22:53:49 +00:00
|
|
|
WaitAny, FALSE, NULL);
|
2013-03-09 22:16:26 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2013-01-13 17:07:25 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
2014-09-07 22:53:49 +00:00
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
2013-01-13 17:07:25 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 22:13:08 +00:00
|
|
|
NtClose(AttachConsoleRequest->ConsoleStartInfo->InitEvents[INIT_SUCCESS]);
|
|
|
|
NtClose(AttachConsoleRequest->ConsoleStartInfo->InitEvents[INIT_FAILURE]);
|
|
|
|
if (Status != INIT_SUCCESS)
|
2014-09-07 22:53:49 +00:00
|
|
|
{
|
|
|
|
NtCurrentPeb()->ProcessParameters->ConsoleHandle = NULL;
|
|
|
|
Success = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RtlCopyMemory(ConsoleStartInfo,
|
|
|
|
AttachConsoleRequest->ConsoleStartInfo,
|
|
|
|
sizeof(CONSOLE_START_INFO));
|
|
|
|
Success = TRUE;
|
|
|
|
}
|
2013-01-13 17:07:25 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
Quit:
|
|
|
|
if (CaptureBuffer) CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
return Success;
|
|
|
|
}
|
2013-01-13 17:07:25 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
AttachConsole(DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
BOOL Success;
|
|
|
|
CONSOLE_START_INFO ConsoleStartInfo;
|
2013-01-13 17:07:25 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
DWORD dummy;
|
|
|
|
LCID lcid;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection(&ConsoleLock);
|
|
|
|
|
|
|
|
if (NtCurrentPeb()->ProcessParameters->ConsoleHandle)
|
|
|
|
{
|
|
|
|
DPRINT1("AttachConsole: Attaching a console to a process already having one\n");
|
|
|
|
SetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
Success = FALSE;
|
|
|
|
goto Quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the console properties */
|
|
|
|
SetUpConsoleInfo(FALSE,
|
|
|
|
&dummy,
|
|
|
|
NULL,
|
|
|
|
&dummy,
|
|
|
|
NULL,
|
|
|
|
&ConsoleStartInfo);
|
|
|
|
|
|
|
|
Success = IntAttachConsole(dwProcessId,
|
|
|
|
ConsoleControlDispatcher,
|
|
|
|
PropDialogHandler,
|
|
|
|
&ConsoleStartInfo);
|
|
|
|
if (Success)
|
|
|
|
{
|
|
|
|
/* Set up the handles */
|
|
|
|
SetUpHandles(&ConsoleStartInfo);
|
|
|
|
InputWaitHandle = ConsoleStartInfo.InputWaitHandle;
|
|
|
|
|
|
|
|
/* Initialize Console Ctrl Handling */
|
|
|
|
InitializeCtrlHandling();
|
|
|
|
|
2014-09-09 21:24:44 +00:00
|
|
|
/* Sets the current console locale for this thread */
|
2014-09-07 22:53:49 +00:00
|
|
|
SetTEBLangID(lcid);
|
|
|
|
}
|
|
|
|
|
|
|
|
Quit:
|
|
|
|
RtlLeaveCriticalSection(&ConsoleLock);
|
|
|
|
return Success;
|
2002-10-20 00:34:40 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 23:45:14 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2009-01-30 14:25:00 +00:00
|
|
|
GetConsoleWindow(VOID)
|
2003-06-19 19:38:26 +00:00
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_GETWINDOW GetWindowRequest = &ApiMessage.Data.GetWindowRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
GetWindowRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetConsoleWindow),
|
|
|
|
sizeof(*GetWindowRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.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
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return GetWindowRequest->WindowHandle;
|
2003-06-19 19:38:26 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 17:53:27 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/*
|
2004-03-14 17:53:27 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-30 14:25:00 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-03-08 15:31:05 +00:00
|
|
|
SetConsoleIcon(HICON hIcon)
|
2004-03-14 17:53:27 +00:00
|
|
|
{
|
2012-11-17 23:45:14 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2014-03-08 15:31:05 +00:00
|
|
|
PCONSOLE_SETICON SetIconRequest = &ApiMessage.Data.SetIconRequest;
|
2009-01-07 10:23:29 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
SetIconRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
SetIconRequest->IconHandle = hIcon;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetIcon),
|
|
|
|
sizeof(*SetIconRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2009-01-30 14:25:00 +00:00
|
|
|
{
|
2014-03-08 15:31:05 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2009-01-30 14:25:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-08 15:31:05 +00:00
|
|
|
return TRUE;
|
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.
|
2014-09-07 22:53:49 +00:00
|
|
|
* \param lpExeName Pointer to a unicode string with the name.
|
2016-11-12 21:53:33 +00:00
|
|
|
* \return TRUE if successful, FALSE if unsuccessful.
|
2014-09-07 22:53:49 +00:00
|
|
|
* \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
|
2009-01-19 17:08:47 +00:00
|
|
|
* 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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2017-12-10 16:04:29 +00:00
|
|
|
SetConsoleInputExeNameW(IN LPCWSTR lpExeName)
|
2004-12-18 13:26:57 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
DWORD ExeLength;
|
2004-12-18 13:26:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
ExeLength = lstrlenW(lpExeName);
|
|
|
|
if ((ExeLength == 0) || (ExeLength >= EXENAME_LENGTH))
|
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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
RtlEnterCriticalSection(&ExeNameLock);
|
2009-01-18 10:06:34 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Set the input EXE name, not NULL terminated */
|
|
|
|
RtlCopyMemory(ExeNameBuffer, lpExeName, ExeLength * sizeof(WCHAR));
|
|
|
|
ExeNameLength = (USHORT)ExeLength;
|
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
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
RtlLeaveCriticalSection(&ExeNameLock);
|
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.
|
2014-09-07 22:53:49 +00:00
|
|
|
* \param lpExeName Pointer to an ansi string with the name.
|
2016-11-12 21:53:33 +00:00
|
|
|
* \return TRUE if successful, FALSE if unsuccessful.
|
2014-09-07 22:53:49 +00:00
|
|
|
* \remarks If lpExeName is 0 or the string length is 0 or greater than 255,
|
2009-01-19 17:08:47 +00:00
|
|
|
* 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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2017-12-10 16:04:29 +00:00
|
|
|
SetConsoleInputExeNameA(IN LPCSTR lpExeName)
|
2004-12-18 13:26:57 +00:00
|
|
|
{
|
2009-01-19 17:08:47 +00:00
|
|
|
NTSTATUS Status;
|
2014-09-07 22:53:49 +00:00
|
|
|
#ifdef USE_TEB_STATIC_USTR
|
|
|
|
PUNICODE_STRING ExeNameU;
|
|
|
|
#else
|
|
|
|
UNICODE_STRING ExeNameU;
|
|
|
|
#endif
|
|
|
|
ANSI_STRING ExeNameA;
|
|
|
|
#ifndef USE_TEB_STATIC_USTR
|
|
|
|
WCHAR Buffer[EXENAME_LENGTH];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_TEB_STATIC_USTR
|
|
|
|
/*
|
|
|
|
* Use the TEB static UNICODE string for storage. It is already
|
|
|
|
* initialized at process creation time by the Memory Manager.
|
|
|
|
*/
|
|
|
|
ExeNameU = &NtCurrentTeb()->StaticUnicodeString;
|
|
|
|
#endif
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Initialize string for conversion */
|
|
|
|
RtlInitAnsiString(&ExeNameA, lpExeName);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
#if 1
|
|
|
|
if ((ExeNameA.Length == 0) || (ExeNameA.Length >= EXENAME_LENGTH))
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
|
|
|
/* Fail if string is empty or too long */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-07 22:53:49 +00:00
|
|
|
#endif
|
|
|
|
#ifndef USE_TEB_STATIC_USTR
|
|
|
|
ExeNameU.Length = 0;
|
|
|
|
ExeNameU.MaximumLength = (USHORT)sizeof(Buffer);
|
|
|
|
ExeNameU.Buffer = Buffer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_TEB_STATIC_USTR
|
|
|
|
Status = RtlAnsiStringToUnicodeString(ExeNameU, &ExeNameA, FALSE);
|
|
|
|
#else
|
|
|
|
Status = RtlAnsiStringToUnicodeString(&ExeNameU, &ExeNameA, FALSE);
|
|
|
|
#endif
|
2013-02-10 12:36:57 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Fail if string is empty or too long */
|
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
|
|
|
else
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
|
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
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
#ifdef USE_TEB_STATIC_USTR
|
|
|
|
return SetConsoleInputExeNameW(ExeNameU->Buffer);
|
|
|
|
#else
|
|
|
|
return SetConsoleInputExeNameW(ExeNameU.Buffer);
|
|
|
|
#endif
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-09-07 22:53:49 +00:00
|
|
|
GetConsoleInputExeNameW(IN DWORD nBufferLength,
|
|
|
|
OUT LPWSTR lpExeName)
|
2004-12-18 13:26:57 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
if (nBufferLength <= ExeNameLength)
|
2009-01-18 10:06:34 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Buffer is not large enough! Return the correct size. */
|
2009-01-18 10:06:34 +00:00
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
2014-09-07 22:53:49 +00:00
|
|
|
return ExeNameLength + 1;
|
2009-01-18 10:06:34 +00:00
|
|
|
}
|
2009-01-19 17:08:47 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
RtlEnterCriticalSection(&ExeNameLock);
|
2009-01-19 17:08:47 +00:00
|
|
|
_SEH2_TRY
|
2009-01-07 10:23:29 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Copy the input EXE name and NULL-terminate it */
|
|
|
|
RtlCopyMemory(lpExeName, ExeNameBuffer, ExeNameLength * sizeof(WCHAR));
|
|
|
|
lpExeName[ExeNameLength] = UNICODE_NULL;
|
2009-01-19 17:08:47 +00:00
|
|
|
}
|
|
|
|
_SEH2_FINALLY
|
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
RtlLeaveCriticalSection(&ExeNameLock);
|
2009-01-07 10:23:29 +00:00
|
|
|
}
|
2009-01-18 10:06:34 +00:00
|
|
|
_SEH2_END;
|
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
return TRUE;
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-09-07 22:53:49 +00:00
|
|
|
GetConsoleInputExeNameA(IN DWORD nBufferLength,
|
|
|
|
OUT LPSTR lpExeName)
|
2004-12-18 13:26:57 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
DWORD ExeLength;
|
2009-01-19 17:08:47 +00:00
|
|
|
UNICODE_STRING BufferU;
|
|
|
|
ANSI_STRING BufferA;
|
2014-09-07 22:53:49 +00:00
|
|
|
WCHAR Buffer[EXENAME_LENGTH];
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Get the UNICODE name */
|
|
|
|
ExeLength = GetConsoleInputExeNameW(EXENAME_LENGTH, Buffer);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
if ((ExeLength == 0) || (ExeLength >= EXENAME_LENGTH))
|
|
|
|
return ExeLength;
|
|
|
|
|
|
|
|
/* Initialize the strings for conversion */
|
2009-01-19 17:08:47 +00:00
|
|
|
RtlInitUnicodeString(&BufferU, Buffer);
|
|
|
|
BufferA.Length = 0;
|
2013-05-29 00:29:07 +00:00
|
|
|
BufferA.MaximumLength = (USHORT)nBufferLength;
|
2014-09-07 22:53:49 +00:00
|
|
|
BufferA.Buffer = lpExeName;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
/* Convert UNICODE name to ANSI, copying as much chars as it can fit */
|
|
|
|
Status = RtlUnicodeStringToAnsiString(&BufferA, &BufferU, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2009-01-19 17:08:47 +00:00
|
|
|
{
|
2014-09-07 22:53:49 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
return ExeLength + 1;
|
|
|
|
}
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2004-12-18 13:26:57 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2014-09-07 22:53:49 +00:00
|
|
|
return ExeLength;
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2011-07-22 02:13:57 +00:00
|
|
|
GetConsoleCursorMode(HANDLE hConsole, PBOOL pUnknown1, PBOOL pUnknown2)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
SetConsoleCursorMode(HANDLE hConsole, BOOL Unknown1, BOOL Unknown2)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
GetConsoleNlsMode(HANDLE hConsole, LPDWORD lpMode)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
SetConsoleNlsMode(HANDLE hConsole, DWORD dwMode)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
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
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2012-11-18 13:10:03 +00:00
|
|
|
RegisterConsoleOS2(BOOL bUnknown)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2011-07-22 02:13:57 +00:00
|
|
|
SetConsoleOS2OemFormat(BOOL bUnknown)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2011-07-22 02:13:57 +00:00
|
|
|
UnregisterConsoleIME(VOID)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-01 15:35:45 +00:00
|
|
|
static
|
2014-08-06 21:01:23 +00:00
|
|
|
BOOL
|
|
|
|
IntGetConsoleKeyboardLayoutName(OUT PVOID pszLayoutName,
|
|
|
|
IN BOOL bAnsi)
|
|
|
|
{
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETKBDLAYOUTNAME GetKbdLayoutNameRequest = &ApiMessage.Data.GetKbdLayoutNameRequest;
|
|
|
|
|
|
|
|
/* Set up the data to send to the Console Server */
|
|
|
|
GetKbdLayoutNameRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetKbdLayoutNameRequest->Ansi = bAnsi;
|
|
|
|
|
|
|
|
/* Call the server */
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetKeyboardLayoutName),
|
|
|
|
sizeof(*GetKbdLayoutNameRequest));
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the results */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Copy only KL_NAMELENGTH == 9 characters, ANSI or UNICODE */
|
|
|
|
if (bAnsi)
|
|
|
|
strncpy(pszLayoutName, (PCHAR)GetKbdLayoutNameRequest->LayoutBuffer, KL_NAMELENGTH);
|
|
|
|
else
|
|
|
|
wcsncpy(pszLayoutName, (PWCHAR)GetKbdLayoutNameRequest->LayoutBuffer, KL_NAMELENGTH);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_ACCESS);
|
|
|
|
_SEH2_YIELD(return FALSE);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-22 02:13:57 +00:00
|
|
|
/*
|
2014-08-06 21:01:23 +00:00
|
|
|
* @implemented (undocumented)
|
2011-07-22 02:13:57 +00:00
|
|
|
*/
|
2014-08-06 21:01:23 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-08-06 21:01:23 +00:00
|
|
|
GetConsoleKeyboardLayoutNameA(OUT LPSTR pszLayoutName)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
2014-08-06 21:01:23 +00:00
|
|
|
return IntGetConsoleKeyboardLayoutName(pszLayoutName, TRUE);
|
2011-07-22 02:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-06 21:01:23 +00:00
|
|
|
* @implemented (undocumented)
|
2011-07-22 02:13:57 +00:00
|
|
|
*/
|
2014-08-06 21:01:23 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-08-06 21:01:23 +00:00
|
|
|
GetConsoleKeyboardLayoutNameW(OUT LPWSTR pszLayoutName)
|
2011-07-22 02:13:57 +00:00
|
|
|
{
|
2014-08-06 21:01:23 +00:00
|
|
|
return IntGetConsoleKeyboardLayoutName(pszLayoutName, FALSE);
|
2011-07-22 02:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-04-21 01:22:17 +00:00
|
|
|
* @implemented
|
2011-07-22 02:13:57 +00:00
|
|
|
*/
|
2014-04-21 01:22:17 +00:00
|
|
|
DWORD
|
2011-07-22 02:13:57 +00:00
|
|
|
WINAPI
|
|
|
|
SetLastConsoleEventActive(VOID)
|
|
|
|
{
|
2014-04-21 01:22:17 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_NOTIFYLASTCLOSE NotifyLastCloseRequest = &ApiMessage.Data.NotifyLastCloseRequest;
|
|
|
|
|
|
|
|
/* Set the flag used by the console control dispatcher */
|
|
|
|
LastCloseNotify = TRUE;
|
|
|
|
|
|
|
|
/* Set up the input arguments */
|
|
|
|
NotifyLastCloseRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
/* Call CSRSS; just return the NTSTATUS cast to DWORD */
|
|
|
|
return CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepNotifyLastClose),
|
|
|
|
sizeof(*NotifyLastCloseRequest));
|
2011-07-22 02:13:57 +00:00
|
|
|
}
|
|
|
|
|
1999-03-06 10:57:02 +00:00
|
|
|
/* EOF */
|