/* FUNCTIONS ******************************************************************/
-/*
- * @implemented
- */
-BOOL
-WINAPI
-AddConsoleAliasW(LPCWSTR lpSource,
- LPCWSTR lpTarget,
- LPCWSTR lpExeName)
+static BOOL
+IntAddConsoleAlias(LPCVOID Source,
+ USHORT SourceBufferLength,
+ LPCVOID Target,
+ USHORT TargetBufferLength,
+ LPCVOID lpExeName,
+ BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &ApiMessage.Data.ConsoleAliasRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
ULONG CapturedStrings;
- DPRINT("AddConsoleAliasW enterd with lpSource %S lpTarget %S lpExeName %S\n", lpSource, lpTarget, lpExeName);
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+
+ if (lpExeName == NULL || NumChars == 0)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ ConsoleAliasRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
/* Determine the needed sizes */
- ConsoleAliasRequest->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
- ConsoleAliasRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+ ConsoleAliasRequest->SourceLength = SourceBufferLength;
+ ConsoleAliasRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ ConsoleAliasRequest->Unicode =
+ ConsoleAliasRequest->Unicode2 = bUnicode;
+
CapturedStrings = 2;
- if (lpTarget) /* The target can be optional */
+ if (Target) /* The target can be optional */
{
- ConsoleAliasRequest->TargetLength = (wcslen(lpTarget) + 1) * sizeof(WCHAR);
+ ConsoleAliasRequest->TargetLength = TargetBufferLength;
CapturedStrings++;
}
else
/* Capture the strings */
CsrCaptureMessageBuffer(CaptureBuffer,
- (PVOID)lpSource,
+ (PVOID)Source,
ConsoleAliasRequest->SourceLength,
(PVOID*)&ConsoleAliasRequest->Source);
CsrCaptureMessageBuffer(CaptureBuffer,
(PVOID)lpExeName,
ConsoleAliasRequest->ExeLength,
- (PVOID*)&ConsoleAliasRequest->Exe);
+ (PVOID*)&ConsoleAliasRequest->ExeName);
- if (lpTarget) /* The target can be optional */
+ if (Target) /* The target can be optional */
{
CsrCaptureMessageBuffer(CaptureBuffer,
- (PVOID)lpTarget,
+ (PVOID)Target,
ConsoleAliasRequest->TargetLength,
(PVOID*)&ConsoleAliasRequest->Target);
}
ConsoleAliasRequest->Target = NULL;
}
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
- sizeof(CONSOLE_ADDGETALIAS));
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepAddAlias),
+ sizeof(*ConsoleAliasRequest));
CsrFreeCaptureBuffer(CaptureBuffer);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return FALSE;
}
*/
BOOL
WINAPI
-AddConsoleAliasA(LPCSTR lpSource,
- LPCSTR lpTarget,
- LPCSTR lpExeName)
+AddConsoleAliasW(LPCWSTR lpSource,
+ LPCWSTR lpTarget,
+ LPCWSTR lpExeName)
{
- LPWSTR lpSourceW = NULL;
- LPWSTR lpTargetW = NULL;
- LPWSTR lpExeNameW = NULL;
- BOOL bRetVal;
-
- if (lpSource)
- BasepAnsiStringToHeapUnicodeString(lpSource, (LPWSTR*)&lpSourceW);
- if (lpTarget)
- BasepAnsiStringToHeapUnicodeString(lpTarget, (LPWSTR*)&lpTargetW);
- if (lpExeName)
- BasepAnsiStringToHeapUnicodeString(lpExeName, (LPWSTR*)&lpExeNameW);
-
- bRetVal = AddConsoleAliasW(lpSourceW, lpTargetW, lpExeNameW);
-
- /* Clean up */
- if (lpSourceW)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpSourceW);
- if (lpTargetW)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpTargetW);
- if (lpExeNameW)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpExeNameW);
-
- return bRetVal;
+ USHORT SourceBufferLength = (USHORT)wcslen(lpSource) * sizeof(WCHAR);
+ USHORT TargetBufferLength = (USHORT)(lpTarget ? wcslen(lpTarget) * sizeof(WCHAR) : 0);
+
+ DPRINT1("AddConsoleAliasW entered with lpSource '%S' lpTarget '%S' lpExeName '%S'\n",
+ lpSource, lpTarget, lpExeName);
+
+ return IntAddConsoleAlias(lpSource,
+ SourceBufferLength,
+ lpTarget,
+ TargetBufferLength,
+ lpExeName,
+ TRUE);
}
/*
* @implemented
*/
-DWORD
+BOOL
WINAPI
-GetConsoleAliasW(LPWSTR lpSource,
- LPWSTR lpTargetBuffer,
- DWORD TargetBufferLength,
- LPWSTR lpExeName)
+AddConsoleAliasA(LPCSTR lpSource,
+ LPCSTR lpTarget,
+ LPCSTR lpExeName)
+{
+ USHORT SourceBufferLength = (USHORT)strlen(lpSource) * sizeof(CHAR);
+ USHORT TargetBufferLength = (USHORT)(lpTarget ? strlen(lpTarget) * sizeof(CHAR) : 0);
+
+ DPRINT1("AddConsoleAliasA entered with lpSource '%s' lpTarget '%s' lpExeName '%s'\n",
+ lpSource, lpTarget, lpExeName);
+
+ return IntAddConsoleAlias(lpSource,
+ SourceBufferLength,
+ lpTarget,
+ TargetBufferLength,
+ lpExeName,
+ FALSE);
+}
+
+
+static DWORD
+IntGetConsoleAlias(LPVOID Source,
+ USHORT SourceBufferLength,
+ LPVOID Target,
+ USHORT TargetBufferLength,
+ LPVOID lpExeName,
+ BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_ADDGETALIAS ConsoleAliasRequest = &ApiMessage.Data.ConsoleAliasRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- DPRINT("GetConsoleAliasW entered with lpSource %S lpExeName %S\n", lpSource, lpExeName);
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
- if (lpTargetBuffer == NULL)
+ if (Source == NULL || Target == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
+ if (lpExeName == NULL || NumChars == 0)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+
+ ConsoleAliasRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+
/* Determine the needed sizes */
- ConsoleAliasRequest->SourceLength = (wcslen(lpSource ) + 1) * sizeof(WCHAR);
- ConsoleAliasRequest->ExeLength = (wcslen(lpExeName) + 1) * sizeof(WCHAR);
+ ConsoleAliasRequest->SourceLength = SourceBufferLength;
+ ConsoleAliasRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ ConsoleAliasRequest->Unicode =
+ ConsoleAliasRequest->Unicode2 = bUnicode;
- ConsoleAliasRequest->Target = NULL;
ConsoleAliasRequest->TargetLength = TargetBufferLength;
/* Allocate a Capture Buffer */
/* Capture the strings */
CsrCaptureMessageBuffer(CaptureBuffer,
- (PVOID)lpSource,
+ (PVOID)Source,
ConsoleAliasRequest->SourceLength,
(PVOID*)&ConsoleAliasRequest->Source);
CsrCaptureMessageBuffer(CaptureBuffer,
(PVOID)lpExeName,
ConsoleAliasRequest->ExeLength,
- (PVOID*)&ConsoleAliasRequest->Exe);
+ (PVOID*)&ConsoleAliasRequest->ExeName);
/* Allocate space for the target buffer */
CsrAllocateMessagePointer(CaptureBuffer,
ConsoleAliasRequest->TargetLength,
(PVOID*)&ConsoleAliasRequest->Target);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAlias),
- sizeof(CONSOLE_ADDGETALIAS));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAlias),
+ sizeof(*ConsoleAliasRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
CsrFreeCaptureBuffer(CaptureBuffer);
- BaseSetLastNTError(Status);
- return 0;
+ BaseSetLastNTError(ApiMessage.Status);
+
+ if (ApiMessage.Status == STATUS_BUFFER_TOO_SMALL)
+ return ConsoleAliasRequest->TargetLength;
+ else
+ return 0;
}
/* Copy the returned target string into the user buffer */
- // wcscpy(lpTargetBuffer, ConsoleAliasRequest->Target);
- memcpy(lpTargetBuffer,
- ConsoleAliasRequest->Target,
- ConsoleAliasRequest->TargetLength);
+ RtlCopyMemory(Target,
+ ConsoleAliasRequest->Target,
+ ConsoleAliasRequest->TargetLength);
/* Release the capture buffer and exit */
CsrFreeCaptureBuffer(CaptureBuffer);
*/
DWORD
WINAPI
-GetConsoleAliasA(LPSTR lpSource,
- LPSTR lpTargetBuffer,
+GetConsoleAliasW(LPWSTR lpSource,
+ LPWSTR lpTargetBuffer,
DWORD TargetBufferLength,
- LPSTR lpExeName)
+ LPWSTR 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;
+ DPRINT1("GetConsoleAliasW entered with lpSource '%S' lpExeName '%S'\n",
+ lpSource, lpExeName);
+
+ return IntGetConsoleAlias(lpSource,
+ (USHORT)wcslen(lpSource) * sizeof(WCHAR),
+ lpTargetBuffer,
+ TargetBufferLength,
+ lpExeName,
+ TRUE);
}
*/
DWORD
WINAPI
-GetConsoleAliasesW(LPWSTR AliasBuffer,
- DWORD AliasBufferLength,
- LPWSTR ExeName)
+GetConsoleAliasA(LPSTR lpSource,
+ LPSTR lpTargetBuffer,
+ DWORD TargetBufferLength,
+ LPSTR lpExeName)
+{
+ DPRINT1("GetConsoleAliasA entered with lpSource '%s' lpExeName '%s'\n",
+ lpSource, lpExeName);
+
+ return IntGetConsoleAlias(lpSource,
+ (USHORT)strlen(lpSource) * sizeof(CHAR),
+ lpTargetBuffer,
+ TargetBufferLength,
+ lpExeName,
+ FALSE);
+}
+
+
+static DWORD
+IntGetConsoleAliases(LPVOID AliasBuffer,
+ DWORD AliasBufferLength,
+ LPVOID lpExeName,
+ BOOLEAN bUnicode)
{
- NTSTATUS Status;
CONSOLE_API_MESSAGE ApiMessage;
PCONSOLE_GETALLALIASES GetAllAliasesRequest = &ApiMessage.Data.GetAllAliasesRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- DPRINT("GetConsoleAliasesW entered\n");
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
- /* Determine the needed sizes */
- GetAllAliasesRequest->ExeLength = GetConsoleAliasesLengthW(ExeName);
- if (GetAllAliasesRequest->ExeLength == 0 ||
- GetAllAliasesRequest->ExeLength > AliasBufferLength)
+ if (lpExeName == NULL || NumChars == 0)
{
+ SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
+ GetAllAliasesRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
+
+ /* Determine the needed sizes */
+ GetAllAliasesRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ GetAllAliasesRequest->Unicode =
+ GetAllAliasesRequest->Unicode2 = bUnicode;
+
GetAllAliasesRequest->AliasesBufferLength = AliasBufferLength;
/* Allocate a Capture Buffer */
/* Capture the exe name and allocate space for the aliases buffer */
CsrCaptureMessageBuffer(CaptureBuffer,
- (PVOID)ExeName,
+ (PVOID)lpExeName,
GetAllAliasesRequest->ExeLength,
(PVOID*)&GetAllAliasesRequest->ExeName);
GetAllAliasesRequest->AliasesBufferLength,
(PVOID*)&GetAllAliasesRequest->AliasesBuffer);
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- CaptureBuffer,
- CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliases),
- sizeof(CONSOLE_GETALLALIASES));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ CaptureBuffer,
+ CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetAliases),
+ sizeof(*GetAllAliasesRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- BaseSetLastNTError(Status);
+ CsrFreeCaptureBuffer(CaptureBuffer);
+ BaseSetLastNTError(ApiMessage.Status);
return 0;
}
/* Copy the returned aliases string into the user buffer */
- // wcscpy(AliasBuffer, GetAllAliasesRequest->AliasesBuffer);
- memcpy(AliasBuffer,
- GetAllAliasesRequest->AliasesBuffer,
- GetAllAliasesRequest->AliasesBufferLength);
+ RtlCopyMemory(AliasBuffer,
+ GetAllAliasesRequest->AliasesBuffer,
+ GetAllAliasesRequest->AliasesBufferLength);
/* Release the capture buffer and exit */
CsrFreeCaptureBuffer(CaptureBuffer);
- return GetAllAliasesRequest->AliasesBufferLength; // / sizeof(WCHAR); (original code)
+ return GetAllAliasesRequest->AliasesBufferLength;
}
*/
DWORD
WINAPI
-GetConsoleAliasesA(LPSTR AliasBuffer,
+GetConsoleAliasesW(LPWSTR AliasBuffer,
DWORD AliasBufferLength,
- LPSTR ExeName)
+ LPWSTR ExeName)
{
- DWORD dwRetVal = 0;
- LPWSTR lpwExeName = NULL;
- LPWSTR lpwAliasBuffer;
-
- DPRINT("GetConsoleAliasesA entered\n");
-
- if (ExeName)
- BasepAnsiStringToHeapUnicodeString(ExeName, (LPWSTR*)&lpwExeName);
+ DPRINT1("GetConsoleAliasesW entered with lpExeName '%S'\n",
+ ExeName);
- lpwAliasBuffer = HeapAlloc(GetProcessHeap(), 0, AliasBufferLength * sizeof(WCHAR));
-
- dwRetVal = GetConsoleAliasesW(lpwAliasBuffer, AliasBufferLength * sizeof(WCHAR), lpwExeName);
+ return IntGetConsoleAliases(AliasBuffer,
+ AliasBufferLength,
+ ExeName,
+ TRUE);
+}
- if (lpwExeName)
- RtlFreeHeap(GetProcessHeap(), 0, (LPWSTR*)lpwExeName);
- if (dwRetVal)
- dwRetVal = WideCharToMultiByte(CP_ACP, 0, lpwAliasBuffer, dwRetVal /**/ / sizeof(WCHAR) /**/, AliasBuffer, AliasBufferLength, NULL, NULL);
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+GetConsoleAliasesA(LPSTR AliasBuffer,
+ DWORD AliasBufferLength,
+ LPSTR ExeName)
+{
+ DPRINT1("GetConsoleAliasesA entered with lpExeName '%s'\n",
+ ExeName);
- HeapFree(GetProcessHeap(), 0, lpwAliasBuffer);
- return dwRetVal;
+ return IntGetConsoleAliases(AliasBuffer,
+ AliasBufferLength,
+ ExeName,
+ FALSE);
}
PCONSOLE_GETALLALIASESLENGTH GetAllAliasesLengthRequest = &ApiMessage.Data.GetAllAliasesLengthRequest;
PCSR_CAPTURE_BUFFER CaptureBuffer;
- DWORD dwNumChars = (lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
+ USHORT NumChars = (USHORT)(lpExeName ? (bUnicode ? wcslen(lpExeName) : strlen(lpExeName)) : 0);
- if (lpExeName == NULL || dwNumChars == 0)
+ if (lpExeName == NULL || NumChars == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
GetAllAliasesLengthRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
- GetAllAliasesLengthRequest->ExeLength = dwNumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
+ GetAllAliasesLengthRequest->ExeLength = NumChars * (bUnicode ? sizeof(WCHAR) : sizeof(CHAR));
GetAllAliasesLengthRequest->Unicode =
GetAllAliasesLengthRequest->Unicode2 = bUnicode;
return 0;
}
- memcpy(lpExeNameBuffer,
- GetAliasesExesRequest->ExeNames,
- GetAliasesExesRequest->Length);
+ RtlCopyMemory(lpExeNameBuffer,
+ GetAliasesExesRequest->ExeNames,
+ GetAliasesExesRequest->Length);
CsrFreeCaptureBuffer(CaptureBuffer);
GetConsoleAliasExesW(LPWSTR lpExeNameBuffer,
DWORD ExeNameBufferLength)
{
+ DPRINT1("GetConsoleAliasExesW called\n");
return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, TRUE);
}
GetConsoleAliasExesA(LPSTR lpExeNameBuffer,
DWORD ExeNameBufferLength)
{
+ DPRINT1("GetConsoleAliasExesA called\n");
return IntGetConsoleAliasExes(lpExeNameBuffer, ExeNameBufferLength, FALSE);
}
WINAPI
GetConsoleAliasExesLengthW(VOID)
{
+ DPRINT1("GetConsoleAliasExesLengthW called\n");
return IntGetConsoleAliasExesLength(TRUE);
}
WINAPI
GetConsoleAliasExesLengthA(VOID)
{
+ DPRINT1("GetConsoleAliasExesLengthA called\n");
return IntGetConsoleAliasExesLength(FALSE);
}