2012-11-15 16:51:29 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2012-11-15 21:02:01 +00:00
|
|
|
* FILE: dll/win32/kernel32/client/console/alias.c
|
|
|
|
* PURPOSE: Win32 Console Client Alias support functions
|
2012-11-15 18:06:17 +00:00
|
|
|
* PROGRAMMERS: David Welch (welch@cwcom.net) (welch@mcmail.com)
|
|
|
|
* Christoph von Wittich (christoph_vw@reactos.org)
|
2013-09-15 13:06:05 +00:00
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
2012-11-15 16:51:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <k32.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2012-11-15 16:51:29 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
static BOOL
|
|
|
|
IntAddConsoleAlias(LPCVOID Source,
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT SourceBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPCVOID Target,
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT TargetBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPCVOID lpExeName,
|
|
|
|
BOOLEAN bUnicode)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &ApiMessage.Data.ConsoleAliasRequest;
|
2012-11-15 21:02:01 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
|
|
|
ULONG CapturedStrings;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
|
2014-07-28 13:20:54 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
if (lpExeName == NULL || NumChars == 0)
|
2014-07-28 13:20:54 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleAliasRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Determine the needed sizes */
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->SourceLength = SourceBufferLength;
|
2014-08-04 17:13:43 +00:00
|
|
|
ConsoleAliasRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->Unicode =
|
|
|
|
ConsoleAliasRequest->Unicode2 = bUnicode;
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CapturedStrings = 2;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
if (Target) /* The target can be optional */
|
2012-11-15 21:02:01 +00:00
|
|
|
{
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->TargetLength = TargetBufferLength;
|
2012-11-15 21:02:01 +00:00
|
|
|
CapturedStrings++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength = 0;
|
2012-11-15 21:02:01 +00:00
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(CapturedStrings,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->SourceLength +
|
|
|
|
ConsoleAliasRequest->ExeLength +
|
|
|
|
ConsoleAliasRequest->TargetLength);
|
2012-11-15 21:02:01 +00:00
|
|
|
if (CaptureBuffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Capture the strings */
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID)Source,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->SourceLength,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->Source);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->ExeLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID*)&ConsoleAliasRequest->ExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
if (Target) /* The target can be optional */
|
2012-11-15 21:02:01 +00:00
|
|
|
{
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID)Target,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->Target);
|
2012-11-15 21:02:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->Target = NULL;
|
2012-11-15 21:02:01 +00:00
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
|
|
|
|
sizeof(*ConsoleAliasRequest));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-07-28 13:20:54 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 16:51:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
AddConsoleAliasW(LPCWSTR lpSource,
|
|
|
|
LPCWSTR lpTarget,
|
|
|
|
LPCWSTR lpExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT SourceBufferLength = (USHORT)wcslen(lpSource) * sizeof(WCHAR);
|
|
|
|
USHORT TargetBufferLength = (USHORT)(lpTarget ? wcslen(lpTarget) * sizeof(WCHAR) : 0);
|
2014-07-28 13:20:54 +00:00
|
|
|
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("AddConsoleAliasW entered with lpSource '%S' lpTarget '%S' lpExeName '%S'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
lpSource, lpTarget, lpExeName);
|
|
|
|
|
|
|
|
return IntAddConsoleAlias(lpSource,
|
|
|
|
SourceBufferLength,
|
|
|
|
lpTarget,
|
|
|
|
TargetBufferLength,
|
|
|
|
lpExeName,
|
|
|
|
TRUE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2014-07-28 13:20:54 +00:00
|
|
|
BOOL
|
2012-11-15 16:51:29 +00:00
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
AddConsoleAliasA(LPCSTR lpSource,
|
|
|
|
LPCSTR lpTarget,
|
|
|
|
LPCSTR lpExeName)
|
|
|
|
{
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT SourceBufferLength = (USHORT)strlen(lpSource) * sizeof(CHAR);
|
|
|
|
USHORT TargetBufferLength = (USHORT)(lpTarget ? strlen(lpTarget) * sizeof(CHAR) : 0);
|
2014-07-28 13:20:54 +00:00
|
|
|
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("AddConsoleAliasA entered with lpSource '%s' lpTarget '%s' lpExeName '%s'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
lpSource, lpTarget, lpExeName);
|
|
|
|
|
|
|
|
return IntAddConsoleAlias(lpSource,
|
|
|
|
SourceBufferLength,
|
|
|
|
lpTarget,
|
|
|
|
TargetBufferLength,
|
|
|
|
lpExeName,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
IntGetConsoleAlias(LPVOID Source,
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT SourceBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPVOID Target,
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT TargetBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPVOID lpExeName,
|
|
|
|
BOOLEAN bUnicode)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &ApiMessage.Data.ConsoleAliasRequest;
|
2012-11-15 21:02:01 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
|
2014-07-28 13:20:54 +00:00
|
|
|
|
|
|
|
if (Source == NULL || Target == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
if (lpExeName == NULL || NumChars == 0)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Determine the needed sizes */
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->SourceLength = SourceBufferLength;
|
2014-08-04 17:13:43 +00:00
|
|
|
ConsoleAliasRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2014-07-28 13:20:54 +00:00
|
|
|
ConsoleAliasRequest->Unicode =
|
|
|
|
ConsoleAliasRequest->Unicode2 = bUnicode;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength = TargetBufferLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
2013-01-05 23:10:12 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(3, ConsoleAliasRequest->SourceLength +
|
|
|
|
ConsoleAliasRequest->ExeLength +
|
|
|
|
ConsoleAliasRequest->TargetLength);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Capture the strings */
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID)Source,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->SourceLength,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->Source);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->ExeLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID*)&ConsoleAliasRequest->ExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate space for the target buffer */
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->Target);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAlias),
|
|
|
|
sizeof(*ConsoleAliasRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2014-07-28 13:20:54 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
|
|
|
|
|
|
|
if (ApiMessage.Status == STATUS_BUFFER_TOO_SMALL)
|
|
|
|
return ConsoleAliasRequest->TargetLength;
|
|
|
|
else
|
|
|
|
return 0;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned target string into the user buffer */
|
2014-08-04 17:13:43 +00:00
|
|
|
RtlCopyMemory(Target,
|
|
|
|
ConsoleAliasRequest->Target,
|
|
|
|
ConsoleAliasRequest->TargetLength);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
/* Release the capture buffer and exit */
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return ConsoleAliasRequest->TargetLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
GetConsoleAliasW(LPWSTR lpSource,
|
|
|
|
LPWSTR lpTargetBuffer,
|
2012-11-15 16:51:29 +00:00
|
|
|
DWORD TargetBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPWSTR lpExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasW entered with lpSource '%S' lpExeName '%S'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
lpSource, lpExeName);
|
|
|
|
|
|
|
|
return IntGetConsoleAlias(lpSource,
|
2014-08-04 17:13:43 +00:00
|
|
|
(USHORT)wcslen(lpSource) * sizeof(WCHAR),
|
2014-07-28 13:20:54 +00:00
|
|
|
lpTargetBuffer,
|
|
|
|
TargetBufferLength,
|
|
|
|
lpExeName,
|
|
|
|
TRUE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
GetConsoleAliasA(LPSTR lpSource,
|
|
|
|
LPSTR lpTargetBuffer,
|
|
|
|
DWORD TargetBufferLength,
|
|
|
|
LPSTR lpExeName)
|
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasA entered with lpSource '%s' lpExeName '%s'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
lpSource, lpExeName);
|
|
|
|
|
|
|
|
return IntGetConsoleAlias(lpSource,
|
2014-08-04 17:13:43 +00:00
|
|
|
(USHORT)strlen(lpSource) * sizeof(CHAR),
|
2014-07-28 13:20:54 +00:00
|
|
|
lpTargetBuffer,
|
|
|
|
TargetBufferLength,
|
|
|
|
lpExeName,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
IntGetConsoleAliases(LPVOID AliasBuffer,
|
|
|
|
DWORD AliasBufferLength,
|
|
|
|
LPVOID lpExeName,
|
|
|
|
BOOLEAN bUnicode)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETALLALIASES GetAllAliasesRequest = &ApiMessage.Data.GetAllAliasesRequest;
|
2012-11-15 21:02:01 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
if (lpExeName == NULL || NumChars == 0)
|
2012-11-15 21:02:01 +00:00
|
|
|
{
|
2014-07-28 13:20:54 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2012-11-15 21:02:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
GetAllAliasesRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
|
|
|
|
/* Determine the needed sizes */
|
2014-08-04 17:13:43 +00:00
|
|
|
GetAllAliasesRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2014-07-28 13:20:54 +00:00
|
|
|
GetAllAliasesRequest->Unicode =
|
|
|
|
GetAllAliasesRequest->Unicode2 = bUnicode;
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesRequest->AliasesBufferLength = AliasBufferLength;
|
2012-11-15 21:02:01 +00:00
|
|
|
|
|
|
|
/* Allocate a Capture Buffer */
|
2013-01-05 23:10:12 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(2, GetAllAliasesRequest->ExeLength +
|
|
|
|
GetAllAliasesRequest->AliasesBufferLength);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Capture the exe name and allocate space for the aliases buffer */
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
2014-07-28 13:20:54 +00:00
|
|
|
(PVOID)lpExeName,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesRequest->ExeLength,
|
|
|
|
(PVOID*)&GetAllAliasesRequest->ExeName);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesRequest->AliasesBufferLength,
|
|
|
|
(PVOID*)&GetAllAliasesRequest->AliasesBuffer);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliases),
|
|
|
|
sizeof(*GetAllAliasesRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-07-28 13:20:54 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 16:51:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned aliases string into the user buffer */
|
2014-08-04 17:13:43 +00:00
|
|
|
RtlCopyMemory(AliasBuffer,
|
|
|
|
GetAllAliasesRequest->AliasesBuffer,
|
|
|
|
GetAllAliasesRequest->AliasesBufferLength);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2013-02-10 12:36:57 +00:00
|
|
|
/* Release the capture buffer and exit */
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
return GetAllAliasesRequest->AliasesBufferLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
GetConsoleAliasesW(LPWSTR AliasBuffer,
|
2012-11-15 21:02:01 +00:00
|
|
|
DWORD AliasBufferLength,
|
2014-07-28 13:20:54 +00:00
|
|
|
LPWSTR ExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasesW entered with lpExeName '%S'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
ExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
return IntGetConsoleAliases(AliasBuffer,
|
|
|
|
AliasBufferLength,
|
|
|
|
ExeName,
|
|
|
|
TRUE);
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-07-28 13:20:54 +00:00
|
|
|
GetConsoleAliasesA(LPSTR AliasBuffer,
|
|
|
|
DWORD AliasBufferLength,
|
|
|
|
LPSTR ExeName)
|
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasesA entered with lpExeName '%s'\n",
|
2014-07-28 13:20:54 +00:00
|
|
|
ExeName);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2014-07-28 13:20:54 +00:00
|
|
|
return IntGetConsoleAliases(AliasBuffer,
|
|
|
|
AliasBufferLength,
|
|
|
|
ExeName,
|
|
|
|
FALSE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
static DWORD
|
2014-05-08 22:24:38 +00:00
|
|
|
IntGetConsoleAliasesLength(LPVOID lpExeName, BOOLEAN bUnicode)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &ApiMessage.Data.GetAllAliasesLengthRequest;
|
2012-11-15 21:02:01 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
|
2014-05-08 22:24:38 +00:00
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
if (lpExeName == NULL || NumChars == 0)
|
2012-11-15 21:02:01 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
GetAllAliasesLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
2014-08-04 17:13:43 +00:00
|
|
|
GetAllAliasesLengthRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2014-05-08 18:08:07 +00:00
|
|
|
GetAllAliasesLengthRequest->Unicode =
|
|
|
|
GetAllAliasesLengthRequest->Unicode2 = bUnicode;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, GetAllAliasesLengthRequest->ExeLength);
|
2012-11-15 21:02:01 +00:00
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesLengthRequest->ExeLength,
|
|
|
|
(PVOID)&GetAllAliasesLengthRequest->ExeName);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength),
|
|
|
|
sizeof(*GetAllAliasesLengthRequest));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-05-08 18:08:07 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 16:51:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAllAliasesLengthRequest->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasesLengthW(LPWSTR lpExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-05-08 22:24:38 +00:00
|
|
|
return IntGetConsoleAliasesLength(lpExeName, TRUE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasesLengthA(LPSTR lpExeName)
|
|
|
|
{
|
2014-05-08 22:24:38 +00:00
|
|
|
return IntGetConsoleAliasesLength(lpExeName, FALSE);
|
2014-05-08 18:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
IntGetConsoleAliasExes(PVOID lpExeNameBuffer,
|
|
|
|
DWORD ExeNameBufferLength,
|
|
|
|
BOOLEAN bUnicode)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETALIASESEXES GetAliasesExesRequest = &ApiMessage.Data.GetAliasesExesRequest;
|
2012-11-15 21:02:01 +00:00
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
GetAliasesExesRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetAliasesExesRequest->Length = ExeNameBufferLength;
|
|
|
|
GetAliasesExesRequest->Unicode = bUnicode;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, ExeNameBufferLength);
|
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2012-11-15 16:51:29 +00:00
|
|
|
return 0;
|
2012-11-15 21:02:01 +00:00
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
ExeNameBufferLength,
|
2013-01-05 23:10:12 +00:00
|
|
|
(PVOID*)&GetAliasesExesRequest->ExeNames);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExes),
|
|
|
|
sizeof(*GetAliasesExesRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2014-05-08 18:08:07 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 16:51:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-04 17:13:43 +00:00
|
|
|
RtlCopyMemory(lpExeNameBuffer,
|
|
|
|
GetAliasesExesRequest->ExeNames,
|
|
|
|
GetAliasesExesRequest->Length);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAliasesExesRequest->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
|
2012-11-15 21:02:01 +00:00
|
|
|
DWORD ExeNameBufferLength)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasExesW called\n");
|
2014-05-08 18:08:07 +00:00
|
|
|
return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, TRUE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
|
|
|
|
DWORD ExeNameBufferLength)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasExesA called\n");
|
2014-05-08 18:08:07 +00:00
|
|
|
return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, FALSE);
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
static DWORD
|
|
|
|
IntGetConsoleAliasExesLength(BOOLEAN bUnicode)
|
|
|
|
{
|
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &ApiMessage.Data.GetAliasesExesLengthRequest;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
GetAliasesExesLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
|
|
|
|
GetAliasesExesLengthRequest->Unicode = bUnicode;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExesLength),
|
|
|
|
sizeof(*GetAliasesExesLengthRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-05-08 18:08:07 +00:00
|
|
|
BaseSetLastNTError(ApiMessage.Status);
|
2012-11-15 16:51:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAliasesExesLengthRequest->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasExesLengthW(VOID)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasExesLengthW called\n");
|
2014-05-08 18:08:07 +00:00
|
|
|
return IntGetConsoleAliasExesLength(TRUE);
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
|
2014-05-08 18:08:07 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2014-11-01 15:35:45 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2014-05-08 18:08:07 +00:00
|
|
|
GetConsoleAliasExesLengthA(VOID)
|
|
|
|
{
|
2014-11-08 22:19:07 +00:00
|
|
|
DPRINT("GetConsoleAliasExesLengthA called\n");
|
2014-05-08 18:08:07 +00:00
|
|
|
return IntGetConsoleAliasExesLength(FALSE);
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|