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)
|
2012-11-15 16:51:29 +00:00
|
|
|
* Johannes Anderwald (janderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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 ******************************************************************/
|
|
|
|
|
|
|
|
/*
|
2012-11-15 21:02:01 +00:00
|
|
|
* @implemented
|
2012-11-15 16:51:29 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
AddConsoleAliasW(LPCWSTR lpSource,
|
|
|
|
LPCWSTR lpTarget,
|
|
|
|
LPCWSTR lpExeName)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_CONSOLE_ALIAS ConsoleAlias = &ApiMessage.Data.ConsoleAlias;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
|
|
|
ULONG CapturedStrings;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource, lpTarget, lpExeName);
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Determine the needed sizes */
|
|
|
|
ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
|
|
|
|
ConsoleAlias->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
|
|
|
CapturedStrings = 2;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (lpTarget) /* The target can be optional */
|
|
|
|
{
|
|
|
|
ConsoleAlias->TargetLength = (wcslen(lpTarget) + 1) * sizeof(WCHAR);
|
|
|
|
CapturedStrings++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConsoleAlias->TargetLength = 0;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(CapturedStrings,
|
|
|
|
ConsoleAlias->SourceLength +
|
|
|
|
ConsoleAlias->ExeLength +
|
|
|
|
ConsoleAlias->TargetLength);
|
|
|
|
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,
|
|
|
|
(PVOID)lpSource,
|
|
|
|
ConsoleAlias->SourceLength,
|
2012-11-15 23:13:23 +00:00
|
|
|
(PVOID*)&ConsoleAlias->Source);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
|
|
|
ConsoleAlias->ExeLength,
|
2012-11-15 23:13:23 +00:00
|
|
|
(PVOID*)&ConsoleAlias->Exe);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (lpTarget) /* The target can be optional */
|
|
|
|
{
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpTarget,
|
|
|
|
ConsoleAlias->TargetLength,
|
2012-11-15 23:13:23 +00:00
|
|
|
(PVOID*)&ConsoleAlias->Target);
|
2012-11-15 21:02:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConsoleAlias->Target = NULL;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
|
|
|
|
sizeof(CSRSS_CONSOLE_ALIAS));
|
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
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
AddConsoleAliasA(LPCSTR lpSource,
|
|
|
|
LPCSTR lpTarget,
|
|
|
|
LPCSTR lpExeName)
|
|
|
|
{
|
|
|
|
LPWSTR lpSourceW = NULL;
|
|
|
|
LPWSTR lpTargetW = NULL;
|
|
|
|
LPWSTR lpExeNameW = NULL;
|
|
|
|
BOOL bRetVal;
|
|
|
|
|
|
|
|
if (lpSource)
|
2012-11-15 21:02:01 +00:00
|
|
|
BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*)&lpSourceW);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (lpTarget)
|
2012-11-15 21:02:01 +00:00
|
|
|
BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*)&lpTargetW);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (lpExeName)
|
2012-11-15 21:02:01 +00:00
|
|
|
BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
bRetVal = AddConsoleAliasW(lpSourceW, lpTargetW, lpExeNameW);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
if (lpSourceW)
|
2012-11-15 21:02:01 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpSourceW);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (lpTargetW)
|
2012-11-15 21:02:01 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpTargetW);
|
2012-11-15 16:51:29 +00:00
|
|
|
if (lpExeNameW)
|
2012-11-15 21:02:01 +00:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleAliasW(LPWSTR lpSource,
|
|
|
|
LPWSTR lpTargetBuffer,
|
|
|
|
DWORD TargetBufferLength,
|
|
|
|
LPWSTR lpExeName)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_CONSOLE_ALIAS ConsoleAlias = &ApiMessage.Data.ConsoleAlias;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasW entered with lpSource %S lpExeName %S\n", lpSource, lpExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
|
|
|
if (lpTargetBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Determine the needed sizes */
|
|
|
|
ConsoleAlias->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
|
|
|
|
ConsoleAlias->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
ConsoleAlias->Target = NULL;
|
|
|
|
ConsoleAlias->TargetLength = TargetBufferLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(3, ConsoleAlias->SourceLength +
|
|
|
|
ConsoleAlias->ExeLength +
|
|
|
|
ConsoleAlias->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,
|
2012-11-15 21:02:01 +00:00
|
|
|
(PVOID)lpSource,
|
|
|
|
ConsoleAlias->SourceLength,
|
2012-11-15 23:13:23 +00:00
|
|
|
(PVOID*)&ConsoleAlias->Source);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
|
|
|
ConsoleAlias->ExeLength,
|
2012-11-15 23:13:23 +00:00
|
|
|
(PVOID*)&ConsoleAlias->Exe);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate space for the target buffer */
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
ConsoleAlias->TargetLength,
|
|
|
|
(PVOID*)&ConsoleAlias->Target);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 16:51:29 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 21:02:01 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAlias),
|
|
|
|
sizeof(CSRSS_CONSOLE_ALIAS));
|
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned target string into the user buffer */
|
|
|
|
// wcscpy(lpTargetBuffer, ConsoleAlias->Target);
|
|
|
|
memcpy(lpTargetBuffer,
|
|
|
|
ConsoleAlias->Target,
|
|
|
|
ConsoleAlias->TargetLength);
|
|
|
|
|
|
|
|
/* Release the capture buffer and exits */
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
return ConsoleAlias->TargetLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetConsoleAliasA(LPSTR lpSource,
|
|
|
|
LPSTR lpTargetBuffer,
|
|
|
|
DWORD TargetBufferLength,
|
|
|
|
LPSTR lpExeName)
|
|
|
|
{
|
|
|
|
LPWSTR lpwSource;
|
|
|
|
LPWSTR lpwExeName;
|
|
|
|
LPWSTR lpwTargetBuffer;
|
|
|
|
UINT dwSourceSize;
|
|
|
|
UINT dwExeNameSize;
|
|
|
|
UINT dwResult;
|
|
|
|
|
|
|
|
DPRINT("GetConsoleAliasA entered\n");
|
|
|
|
|
|
|
|
if (lpTargetBuffer == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwSourceSize = (strlen(lpSource)+1) * sizeof(WCHAR);
|
|
|
|
lpwSource = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSourceSize);
|
|
|
|
if (lpwSource == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpSource, -1, lpwSource, dwSourceSize);
|
|
|
|
|
|
|
|
dwExeNameSize = (strlen(lpExeName)+1) * sizeof(WCHAR);
|
|
|
|
lpwExeName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwExeNameSize);
|
|
|
|
if (lpwExeName == NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwSource);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpExeName, -1, lpwExeName, dwExeNameSize);
|
|
|
|
|
|
|
|
lpwTargetBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, TargetBufferLength * sizeof(WCHAR));
|
|
|
|
if (lpwTargetBuffer == NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwSource);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwExeName);
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwResult = GetConsoleAliasW(lpwSource, lpwTargetBuffer, TargetBufferLength * sizeof(WCHAR), lpwExeName);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwSource);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwExeName);
|
|
|
|
|
|
|
|
if (dwResult)
|
|
|
|
dwResult = WideCharToMultiByte(CP_ACP, 0, lpwTargetBuffer, dwResult / sizeof(WCHAR), lpTargetBuffer, TargetBufferLength, NULL, NULL);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwTargetBuffer);
|
|
|
|
|
|
|
|
return dwResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasesW(LPWSTR AliasBuffer,
|
|
|
|
DWORD AliasBufferLength,
|
|
|
|
LPWSTR ExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_GET_ALL_CONSOLE_ALIASES GetAllConsoleAliases = &ApiMessage.Data.GetAllConsoleAliases;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasesW entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Determine the needed sizes */
|
|
|
|
GetAllConsoleAliases->ExeLength = GetConsoleAliasesLengthW(ExeName);
|
|
|
|
if (GetAllConsoleAliases->ExeLength == 0 ||
|
|
|
|
GetAllConsoleAliases->ExeLength > AliasBufferLength)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetAllConsoleAliases->AliasesBufferLength = AliasBufferLength;
|
|
|
|
|
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(2, GetAllConsoleAliases->ExeLength +
|
|
|
|
GetAllConsoleAliases->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,
|
|
|
|
(PVOID)ExeName,
|
|
|
|
GetAllConsoleAliases->ExeLength,
|
|
|
|
(PVOID*)&GetAllConsoleAliases->ExeName);
|
|
|
|
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
2012-11-15 21:02:01 +00:00
|
|
|
GetAllConsoleAliases->AliasesBufferLength,
|
|
|
|
(PVOID*)&GetAllConsoleAliases->AliasesBuffer);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 16:51:29 +00:00
|
|
|
CaptureBuffer,
|
2012-11-15 21:02:01 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliases),
|
|
|
|
sizeof(CSRSS_GET_ALL_CONSOLE_ALIASES));
|
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned aliases string into the user buffer */
|
|
|
|
// wcscpy(AliasBuffer, GetAllConsoleAliases->AliasesBuffer);
|
|
|
|
memcpy(AliasBuffer,
|
|
|
|
GetAllConsoleAliases->AliasesBuffer,
|
|
|
|
GetAllConsoleAliases->AliasesBufferLength);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Release the capture buffer and exits */
|
2012-11-15 16:51:29 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
2012-11-15 21:02:01 +00:00
|
|
|
|
|
|
|
return GetAllConsoleAliases->AliasesBufferLength; // / sizeof(WCHAR); (original code)
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasesA(LPSTR AliasBuffer,
|
|
|
|
DWORD AliasBufferLength,
|
|
|
|
LPSTR ExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
DWORD dwRetVal = 0;
|
|
|
|
LPWSTR lpwExeName = NULL;
|
|
|
|
LPWSTR lpwAliasBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasesA entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (ExeName)
|
|
|
|
BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*)&lpwExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength * sizeof(WCHAR), lpwExeName);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (lpwExeName)
|
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpwExeName);
|
|
|
|
|
|
|
|
if (dwRetVal)
|
|
|
|
dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal /**/ / sizeof(WCHAR) /**/, AliasBuffer, AliasBufferLength, NULL, NULL);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
|
|
|
|
return dwRetVal;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasesLengthW(LPWSTR lpExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH GetAllConsoleAliasesLength = &ApiMessage.Data.GetAllConsoleAliasesLength;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasesLengthW entered\n");
|
|
|
|
|
|
|
|
if (lpExeName == NULL)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
GetAllConsoleAliasesLength->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
|
|
|
GetAllConsoleAliasesLength->Length = 0;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
CaptureBuffer = CsrAllocateCaptureBuffer(1, GetAllConsoleAliasesLength->ExeLength);
|
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Capture the exe name */
|
|
|
|
CsrCaptureMessageBuffer(CaptureBuffer,
|
|
|
|
(PVOID)lpExeName,
|
|
|
|
GetAllConsoleAliasesLength->ExeLength,
|
|
|
|
(PVOID)&GetAllConsoleAliasesLength->ExeName);
|
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength),
|
|
|
|
sizeof(CSRSS_GET_ALL_CONSOLE_ALIASES_LENGTH));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
return GetAllConsoleAliasesLength->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasesLengthA(LPSTR lpExeName)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
DWORD dwRetVal = 0;
|
|
|
|
LPWSTR lpExeNameW = NULL;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (lpExeName)
|
|
|
|
BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
dwRetVal = GetConsoleAliasesLengthW(lpExeNameW);
|
|
|
|
if (dwRetVal)
|
|
|
|
dwRetVal /= sizeof(WCHAR);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Clean up */
|
|
|
|
if (lpExeNameW)
|
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
return dwRetVal;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
|
|
|
|
DWORD ExeNameBufferLength)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_GET_CONSOLE_ALIASES_EXES GetConsoleAliasesExes = &ApiMessage.Data.GetConsoleAliasesExes;
|
|
|
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasExesW entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate a Capture Buffer */
|
|
|
|
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
|
|
|
GetConsoleAliasesExes->Length = ExeNameBufferLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Allocate space for the exe name buffer */
|
|
|
|
CsrAllocateMessagePointer(CaptureBuffer,
|
|
|
|
ExeNameBufferLength,
|
|
|
|
(PVOID*)&GetConsoleAliasesExes->ExeNames);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExes),
|
|
|
|
sizeof(CSRSS_GET_CONSOLE_ALIASES_EXES));
|
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
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
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned target string into the user buffer */
|
|
|
|
memcpy(lpExeNameBuffer,
|
|
|
|
GetConsoleAliasesExes->ExeNames,
|
|
|
|
GetConsoleAliasesExes->Length);
|
|
|
|
|
|
|
|
/* Release the capture buffer and exits */
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
|
|
|
|
return GetConsoleAliasesExes->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
|
|
|
|
DWORD ExeNameBufferLength)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
LPWSTR lpwExeNameBuffer;
|
|
|
|
DWORD dwResult;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasExesA entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
lpwExeNameBuffer = HeapAlloc(GetProcessHeap(), 0, ExeNameBufferLength * sizeof(WCHAR));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
dwResult = GetConsoleAliasExesW(lpwExeNameBuffer, ExeNameBufferLength * sizeof(WCHAR));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (dwResult)
|
|
|
|
dwResult = WideCharToMultiByte(CP_ACP, 0, lpwExeNameBuffer, dwResult / sizeof(WCHAR), lpExeNameBuffer, ExeNameBufferLength, NULL, NULL);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwExeNameBuffer);
|
|
|
|
return dwResult;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasExesLengthW(VOID)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2012-11-15 21:02:01 +00:00
|
|
|
CONSOLE_API_MESSAGE ApiMessage;
|
|
|
|
PCSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH GetConsoleAliasesExesLength = &ApiMessage.Data.GetConsoleAliasesExesLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasExesLengthW entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasesExesLength->Length = 0;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
2012-11-15 16:51:29 +00:00
|
|
|
NULL,
|
2012-11-15 21:02:01 +00:00
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasExesLength),
|
|
|
|
sizeof(CSRSS_GET_CONSOLE_ALIASES_EXES_LENGTH));
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = ApiMessage.Status))
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
return GetConsoleAliasesExesLength->Length;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-11-15 21:02:01 +00:00
|
|
|
GetConsoleAliasExesLengthA(VOID)
|
2012-11-15 16:51:29 +00:00
|
|
|
{
|
2012-11-15 21:02:01 +00:00
|
|
|
DWORD dwLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
DPRINT("GetConsoleAliasExesLengthA entered\n");
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
dwLength = GetConsoleAliasExesLengthW();
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
if (dwLength)
|
|
|
|
dwLength /= sizeof(WCHAR);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
return dwLength;
|
2012-11-15 16:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|