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;
|
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
|
|
|
|
|
|
|
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 */
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
|
|
|
|
ConsoleAliasRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
2012-11-15 21:02:01 +00:00
|
|
|
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 */
|
|
|
|
{
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength = (wcslen(lpTarget) + 1) * sizeof(WCHAR);
|
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,
|
|
|
|
(PVOID)lpSource,
|
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,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->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,
|
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
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_ADDGETALIAS));
|
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;
|
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
|
|
|
|
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 */
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
|
|
|
|
ConsoleAliasRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
2012-11-15 16:51:29 +00:00
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->Target = NULL;
|
|
|
|
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,
|
2012-11-15 21:02:01 +00:00
|
|
|
(PVOID)lpSource,
|
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,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->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,
|
2013-01-05 23:10:12 +00:00
|
|
|
ConsoleAliasRequest->TargetLength,
|
|
|
|
(PVOID*)&ConsoleAliasRequest->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),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_ADDGETALIAS));
|
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
|
|
|
{
|
|
|
|
CsrFreeCaptureBuffer(CaptureBuffer);
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:02:01 +00:00
|
|
|
/* Copy the returned target string into the user buffer */
|
2013-01-05 23:10:12 +00:00
|
|
|
// wcscpy(lpTargetBuffer, ConsoleAliasRequest->Target);
|
2012-11-15 21:02:01 +00:00
|
|
|
memcpy(lpTargetBuffer,
|
2013-01-05 23:10:12 +00:00
|
|
|
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
|
|
|
|
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;
|
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
|
|
|
|
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 */
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesRequest->ExeLength = GetConsoleAliasesLengthW(ExeName);
|
|
|
|
if (GetAllAliasesRequest->ExeLength == 0 ||
|
|
|
|
GetAllAliasesRequest->ExeLength > AliasBufferLength)
|
2012-11-15 21:02:01 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
(PVOID)ExeName,
|
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
|
|
|
|
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),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETALLALIASES));
|
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
|
|
|
/* Copy the returned aliases string into the user buffer */
|
2013-01-05 23:10:12 +00:00
|
|
|
// wcscpy(AliasBuffer, GetAllAliasesRequest->AliasesBuffer);
|
2012-11-15 21:02:01 +00:00
|
|
|
memcpy(AliasBuffer,
|
2013-01-05 23:10:12 +00:00
|
|
|
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
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAllAliasesRequest->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;
|
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
|
|
|
|
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
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAllAliasesLengthRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
|
|
|
|
GetAllAliasesLengthRequest->Length = 0;
|
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(1, GetAllAliasesLengthRequest->ExeLength);
|
2012-11-15 21:02:01 +00:00
|
|
|
if (!CaptureBuffer)
|
|
|
|
{
|
|
|
|
DPRINT1("CsrAllocateCaptureBuffer failed!\n");
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Capture the exe name */
|
|
|
|
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
|
|
|
|
|
|
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
CaptureBuffer,
|
|
|
|
CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliasesLength),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETALLALIASESLENGTH));
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAllAliasesLengthRequest->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;
|
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
|
|
|
|
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
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAliasesExesRequest->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,
|
2013-01-05 23:10:12 +00:00
|
|
|
(PVOID*)&GetAliasesExesRequest->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),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETALIASESEXES));
|
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
|
|
|
{
|
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,
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAliasesExesRequest->ExeNames,
|
|
|
|
GetAliasesExesRequest->Length);
|
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 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
|
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;
|
2013-01-05 23:10:12 +00:00
|
|
|
PCONSOLE_GETALIASESEXESLENGTH GetAliasesExesLengthRequest = &ApiMessage.Data.GetAliasesExesLengthRequest;
|
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
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
GetAliasesExesLengthRequest->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),
|
2013-01-05 23:10:12 +00:00
|
|
|
sizeof(CONSOLE_GETALIASESEXESLENGTH));
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-05 23:10:12 +00:00
|
|
|
return GetAliasesExesLengthRequest->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 */
|