2004-05-31 19:33:59 +00:00
|
|
|
/*
|
2005-09-08 00:09:32 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Unicode Conversion Routines
|
|
|
|
* FILE: lib/rtl/unicode.c
|
2005-09-23 06:37:14 +00:00
|
|
|
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
|
|
|
* Emanuele Aliberti
|
|
|
|
* Gunnar Dalsnes
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
2005-09-08 00:09:32 +00:00
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-26 08:39:07 +00:00
|
|
|
#include <rtl.h>
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2008-12-13 21:22:07 +00:00
|
|
|
#include <wine/unicode.h>
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
extern BOOLEAN NlsMbCodePageTag;
|
|
|
|
extern BOOLEAN NlsMbOemCodePageTag;
|
2005-09-23 06:37:14 +00:00
|
|
|
extern PUSHORT NlsLeadByteInfo;
|
2009-10-10 13:22:41 +00:00
|
|
|
extern USHORT NlsOemDefaultChar;
|
|
|
|
extern USHORT NlsUnicodeDefaultChar;
|
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2013-08-30 06:34:16 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlMultiAppendUnicodeStringBuffer(IN PVOID Unknown,
|
|
|
|
IN ULONG Unknown2,
|
|
|
|
IN PVOID Unknown3)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2004-08-07 19:13:27 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-09-23 06:37:14 +00:00
|
|
|
WCHAR
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2011-02-20 19:28:34 +00:00
|
|
|
RtlAnsiCharToUnicodeChar(IN OUT PUCHAR *AnsiChar)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ULONG Size;
|
|
|
|
NTSTATUS Status;
|
2005-09-23 11:12:18 +00:00
|
|
|
WCHAR UnicodeChar = L' ';
|
2011-02-20 19:28:34 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
|
|
|
if (NlsLeadByteInfo)
|
|
|
|
{
|
|
|
|
Size = (NlsLeadByteInfo[**AnsiChar] == 0) ? 1 : 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-21 09:12:43 +00:00
|
|
|
DPRINT("HACK::Shouldn't have happened! Consider fixing Usetup and registry entries it creates on install\n");
|
2011-02-20 19:28:34 +00:00
|
|
|
Size = 1;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlMultiByteToUnicodeN(&UnicodeChar,
|
|
|
|
sizeof(WCHAR),
|
|
|
|
NULL,
|
2005-09-23 11:12:18 +00:00
|
|
|
(PCHAR)*AnsiChar,
|
2005-09-23 06:37:14 +00:00
|
|
|
Size);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2005-09-23 11:12:18 +00:00
|
|
|
UnicodeChar = L' ';
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
*AnsiChar += Size;
|
|
|
|
return UnicodeChar;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function always writes a terminating '\0'.
|
|
|
|
* If the dest buffer is too small a partial copy is NOT performed!
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlAnsiStringToUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PANSI_STRING AnsiSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2011-02-07 23:23:33 +00:00
|
|
|
if (NlsMbCodePageTag == FALSE)
|
|
|
|
{
|
|
|
|
Length = AnsiSource->Length * 2 + sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Length = RtlxAnsiStringToUnicodeSize(AnsiSource);
|
|
|
|
}
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
|
|
|
UniDest->Length = (USHORT)Length - sizeof(WCHAR);
|
|
|
|
|
2005-12-30 00:18:48 +00:00
|
|
|
if (AllocateDestinationString)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
UniDest->MaximumLength = (USHORT)Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!UniDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
2005-12-30 00:18:48 +00:00
|
|
|
else if (UniDest->Length >= UniDest->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
2005-12-30 00:18:48 +00:00
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-07 23:23:33 +00:00
|
|
|
/* UniDest->MaximumLength must be even due to sizeof(WCHAR) being 2 */
|
|
|
|
ASSERT(!(UniDest->MaximumLength & 1) && UniDest->Length <= UniDest->MaximumLength);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlMultiByteToUnicodeN(UniDest->Buffer,
|
|
|
|
UniDest->Length,
|
|
|
|
&Index,
|
|
|
|
AnsiSource->Buffer,
|
|
|
|
AnsiSource->Length);
|
|
|
|
|
2005-12-30 00:18:48 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
2005-12-30 00:18:48 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
|
|
|
|
UniDest->Buffer = NULL;
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniDest->Buffer[Index / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The calculated size in bytes including nullterm.
|
|
|
|
*/
|
|
|
|
ULONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-06 17:33:56 +00:00
|
|
|
RtlxAnsiStringToUnicodeSize(IN PCANSI_STRING AnsiString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-06 19:47:06 +00:00
|
|
|
ULONG Size;
|
2011-02-07 23:23:33 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Convert from Mb String to Unicode Size */
|
|
|
|
RtlMultiByteToUnicodeSize(&Size,
|
|
|
|
AnsiString->Buffer,
|
|
|
|
AnsiString->Length);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Return the size plus the null-char */
|
|
|
|
return(Size + sizeof(WCHAR));
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If src->length is zero dest is unchanged.
|
|
|
|
* Dest is never nullterminated.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlAppendStringToString(IN PSTRING Destination,
|
2013-11-05 20:40:01 +00:00
|
|
|
IN const STRING *Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
USHORT SourceLength = Source->Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (SourceLength)
|
|
|
|
{
|
|
|
|
if (Destination->Length + SourceLength > Destination->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlMoveMemory(&Destination->Buffer[Destination->Length],
|
|
|
|
Source->Buffer,
|
|
|
|
SourceLength);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Destination->Length += SourceLength;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If src->length is zero dest is unchanged.
|
|
|
|
* Dest is nullterminated when the MaximumLength allowes it.
|
|
|
|
* When dest fits exactly in MaximumLength characters the nullterm is ommitted.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAppendUnicodeStringToString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING Destination,
|
|
|
|
IN PCUNICODE_STRING Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
USHORT SourceLength = Source->Length;
|
|
|
|
PWCHAR Buffer = &Destination->Buffer[Destination->Length / sizeof(WCHAR)];
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (SourceLength)
|
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
if ((SourceLength + Destination->Length) > Destination->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlMoveMemory(Buffer, Source->Buffer, SourceLength);
|
|
|
|
Destination->Length += SourceLength;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* append terminating '\0' if enough space */
|
|
|
|
if (Destination->MaximumLength > Destination->Length)
|
|
|
|
{
|
|
|
|
Buffer[SourceLength / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-05-07 22:17:03 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* RtlCharToInteger (NTDLL.@)
|
2004-05-31 19:33:59 +00:00
|
|
|
* @implemented
|
2005-05-07 22:17:03 +00:00
|
|
|
* Converts a character string into its integer equivalent.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS. value contains the converted number
|
|
|
|
* Failure: STATUS_INVALID_PARAMETER, if base is not 0, 2, 8, 10 or 16.
|
|
|
|
* STATUS_ACCESS_VIOLATION, if value is NULL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* For base 0 it uses 10 as base and the string should be in the format
|
|
|
|
* "{whitespace} [+|-] [0[x|o|b]] {digits}".
|
|
|
|
* For other bases the string should be in the format
|
|
|
|
* "{whitespace} [+|-] {digits}".
|
|
|
|
* No check is made for value overflow, only the lower 32 bits are assigned.
|
|
|
|
* If str is NULL it crashes, as the native function does.
|
|
|
|
*
|
|
|
|
* DIFFERENCES
|
|
|
|
* This function does not read garbage behind '\0' as the native version does.
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCharToInteger(
|
2005-05-07 22:17:03 +00:00
|
|
|
PCSZ str, /* [I] '\0' terminated single-byte string containing a number */
|
|
|
|
ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
|
|
|
PULONG value) /* [O] Destination for the converted value */
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-05-07 22:17:03 +00:00
|
|
|
CHAR chCurrent;
|
|
|
|
int digit;
|
|
|
|
ULONG RunningTotal = 0;
|
|
|
|
char bMinus = 0;
|
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
/* skip leading whitespaces */
|
|
|
|
while (*str != '\0' && *str <= ' ') str++;
|
|
|
|
|
|
|
|
/* Check for +/- */
|
|
|
|
if (*str == '+')
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
else if (*str == '-')
|
|
|
|
{
|
|
|
|
bMinus = 1;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* base = 0 means autobase */
|
|
|
|
if (base == 0)
|
|
|
|
{
|
|
|
|
base = 10;
|
|
|
|
|
|
|
|
if (str[0] == '0')
|
|
|
|
{
|
|
|
|
if (str[1] == 'b')
|
|
|
|
{
|
|
|
|
str += 2;
|
|
|
|
base = 2;
|
|
|
|
}
|
|
|
|
else if (str[1] == 'o')
|
|
|
|
{
|
|
|
|
str += 2;
|
|
|
|
base = 8;
|
|
|
|
}
|
|
|
|
else if (str[1] == 'x')
|
|
|
|
{
|
|
|
|
str += 2;
|
|
|
|
base = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (base != 2 && base != 8 && base != 10 && base != 16)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == NULL) return STATUS_ACCESS_VIOLATION;
|
|
|
|
|
|
|
|
while (*str != '\0')
|
|
|
|
{
|
|
|
|
chCurrent = *str;
|
|
|
|
|
|
|
|
if (chCurrent >= '0' && chCurrent <= '9')
|
|
|
|
{
|
|
|
|
digit = chCurrent - '0';
|
|
|
|
}
|
|
|
|
else if (chCurrent >= 'A' && chCurrent <= 'Z')
|
|
|
|
{
|
|
|
|
digit = chCurrent - 'A' + 10;
|
|
|
|
}
|
|
|
|
else if (chCurrent >= 'a' && chCurrent <= 'z')
|
|
|
|
{
|
|
|
|
digit = chCurrent - 'a' + 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
digit = -1;
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (digit < 0 || digit >= (int)base) break;
|
2008-10-25 07:12:41 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
RunningTotal = RunningTotal * base + digit;
|
|
|
|
str++;
|
|
|
|
}
|
2005-05-07 22:17:03 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
*value = bMinus ? (0 - RunningTotal) : RunningTotal;
|
2005-05-07 22:17:03 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCompareString(
|
2013-11-05 20:40:01 +00:00
|
|
|
IN const STRING *s1,
|
|
|
|
IN const STRING *s2,
|
2011-09-18 22:15:37 +00:00
|
|
|
IN BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
unsigned int len;
|
|
|
|
LONG ret = 0;
|
|
|
|
LPCSTR p1, p2;
|
|
|
|
|
|
|
|
len = min(s1->Length, s2->Length);
|
|
|
|
p1 = s1->Buffer;
|
|
|
|
p2 = s2->Buffer;
|
|
|
|
|
|
|
|
if (CaseInsensitive)
|
|
|
|
{
|
|
|
|
while (!ret && len--)
|
|
|
|
ret = RtlUpperChar(*p1++) - RtlUpperChar(*p2++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (!ret && len--) ret = *p1++ - *p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) ret = s1->Length - s2->Length;
|
|
|
|
|
|
|
|
return ret;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if strings are equal.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlEqualString(
|
2013-11-05 20:40:01 +00:00
|
|
|
IN const STRING *s1,
|
|
|
|
IN const STRING *s2,
|
2011-09-18 22:15:37 +00:00
|
|
|
IN BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
if (s1->Length != s2->Length) return FALSE;
|
|
|
|
return !RtlCompareString(s1, s2, CaseInsensitive);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if strings are equal.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlEqualUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN CONST UNICODE_STRING *s1,
|
|
|
|
IN CONST UNICODE_STRING *s2,
|
|
|
|
IN BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
if (s1->Length != s2->Length) return FALSE;
|
|
|
|
return !RtlCompareUnicodeString(s1, s2, CaseInsensitive );
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlFreeAnsiString(IN PANSI_STRING AnsiString)
|
|
|
|
{
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AnsiString->Buffer)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(AnsiString->Buffer, TAG_ASTR);
|
2005-11-01 23:37:26 +00:00
|
|
|
RtlZeroMemory(AnsiString, sizeof(ANSI_STRING));
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlFreeOemString(IN POEM_STRING OemString)
|
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-11-01 22:45:35 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if (OemString->Buffer) RtlpFreeStringMemory(OemString->Buffer, TAG_OSTR);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString)
|
|
|
|
{
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (UnicodeString->Buffer)
|
|
|
|
{
|
2007-08-24 07:43:42 +00:00
|
|
|
RtlpFreeStringMemory(UnicodeString->Buffer, TAG_USTR);
|
2005-11-01 23:37:26 +00:00
|
|
|
RtlZeroMemory(UnicodeString, sizeof(UNICODE_STRING));
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-10 13:22:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
2009-10-13 18:43:42 +00:00
|
|
|
*
|
2009-10-10 13:22:41 +00:00
|
|
|
* NOTES
|
2009-10-13 18:43:42 +00:00
|
|
|
* Check the OEM string to match the Unicode string.
|
2009-10-10 13:22:41 +00:00
|
|
|
*
|
2009-10-13 18:43:42 +00:00
|
|
|
* Functions which convert Unicode strings to OEM strings will set a
|
|
|
|
* DefaultChar from the OEM codepage when the characters are unknown.
|
|
|
|
* So check it against the Unicode string and return false when the
|
|
|
|
* Unicode string does not contain a TransDefaultChar.
|
2009-10-10 13:22:41 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
RtlpDidUnicodeToOemWork(IN PCUNICODE_STRING UnicodeString,
|
|
|
|
IN POEM_STRING OemString)
|
|
|
|
{
|
2009-10-13 18:43:42 +00:00
|
|
|
ULONG i = 0;
|
2009-10-10 13:22:41 +00:00
|
|
|
|
2009-10-13 18:43:42 +00:00
|
|
|
if (NlsMbOemCodePageTag == FALSE)
|
|
|
|
{
|
|
|
|
/* single-byte code page */
|
|
|
|
/* Go through all characters of a string */
|
|
|
|
while (i < OemString->Length)
|
|
|
|
{
|
|
|
|
/* Check if it got translated into a default char,
|
|
|
|
* but source char wasn't a default char equivalent
|
|
|
|
*/
|
|
|
|
if ((OemString->Buffer[i] == NlsOemDefaultChar) &&
|
|
|
|
(UnicodeString->Buffer[i] != NlsUnicodeDefaultChar))
|
|
|
|
{
|
|
|
|
/* Yes, it means unmappable characters were found */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next char */
|
|
|
|
i++;
|
|
|
|
}
|
2009-10-10 13:22:41 +00:00
|
|
|
|
2009-10-13 18:43:42 +00:00
|
|
|
/* All chars were translated successfuly */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* multibyte code page */
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-10-10 13:22:41 +00:00
|
|
|
}
|
|
|
|
|
2004-08-05 18:17:37 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlIsValidOemCharacter(IN PWCHAR Char)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
return FALSE;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If source is NULL the length of source is assumed to be 0.
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlInitAnsiString(IN OUT PANSI_STRING DestinationString,
|
|
|
|
IN PCSZ SourceString)
|
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (SourceString)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = strlen(SourceString);
|
|
|
|
if (Size > (MAXUSHORT - sizeof(CHAR))) Size = MAXUSHORT - sizeof(CHAR);
|
|
|
|
DestinationString->Length = (USHORT)Size;
|
|
|
|
DestinationString->MaximumLength = (USHORT)Size + sizeof(CHAR);
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
DestinationString->MaximumLength = 0;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
DestinationString->Buffer = (PCHAR)SourceString;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2008-06-02 10:21:49 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlInitAnsiStringEx(IN OUT PANSI_STRING DestinationString,
|
|
|
|
IN PCSZ SourceString)
|
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2008-06-02 10:21:49 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (SourceString)
|
2008-06-02 10:21:49 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = strlen(SourceString);
|
|
|
|
if (Size > (MAXUSHORT - sizeof(CHAR))) return STATUS_NAME_TOO_LONG;
|
|
|
|
DestinationString->Length = (USHORT)Size;
|
|
|
|
DestinationString->MaximumLength = (USHORT)Size + sizeof(CHAR);
|
2008-06-02 10:21:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
DestinationString->MaximumLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestinationString->Buffer = (PCHAR)SourceString;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If source is NULL the length of source is assumed to be 0.
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlInitString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PSTRING DestinationString,
|
|
|
|
IN PCSZ SourceString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlInitAnsiString(DestinationString, SourceString);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If source is NULL the length of source is assumed to be 0.
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2011-09-19 11:09:09 +00:00
|
|
|
RtlInitUnicodeString(
|
|
|
|
IN OUT PUNICODE_STRING DestinationString,
|
|
|
|
IN PCWSTR SourceString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2013-02-16 17:21:34 +00:00
|
|
|
CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(UNICODE_NULL); // an even number
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (SourceString)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = wcslen(SourceString) * sizeof(WCHAR);
|
2013-02-16 17:21:34 +00:00
|
|
|
__analysis_assume(Size <= MaxSize);
|
|
|
|
|
|
|
|
if (Size > MaxSize)
|
|
|
|
Size = MaxSize;
|
2011-09-19 11:09:09 +00:00
|
|
|
DestinationString->Length = (USHORT)Size;
|
2013-02-16 17:21:34 +00:00
|
|
|
DestinationString->MaximumLength = (USHORT)Size + sizeof(UNICODE_NULL);
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
DestinationString->MaximumLength = 0;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
DestinationString->Buffer = (PWCHAR)SourceString;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2004-12-05 21:16:01 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2011-09-19 11:09:09 +00:00
|
|
|
RtlInitUnicodeStringEx(
|
|
|
|
OUT PUNICODE_STRING DestinationString,
|
|
|
|
IN PCWSTR SourceString)
|
2004-12-05 21:16:01 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2011-10-09 09:55:40 +00:00
|
|
|
CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(WCHAR); // an even number
|
2004-12-05 21:16:01 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (SourceString)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = wcslen(SourceString) * sizeof(WCHAR);
|
2011-10-09 09:55:40 +00:00
|
|
|
if (Size > MaxSize) return STATUS_NAME_TOO_LONG;
|
2011-09-19 11:09:09 +00:00
|
|
|
DestinationString->Length = (USHORT)Size;
|
|
|
|
DestinationString->MaximumLength = (USHORT)Size + sizeof(WCHAR);
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
DestinationString->MaximumLength = 0;
|
|
|
|
}
|
2004-12-05 21:16:01 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
DestinationString->Buffer = (PWCHAR)SourceString;
|
|
|
|
return STATUS_SUCCESS;
|
2004-12-05 21:16:01 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Writes at most length characters to the string str.
|
|
|
|
* Str is nullterminated when length allowes it.
|
|
|
|
* When str fits exactly in length characters the nullterm is ommitted.
|
|
|
|
*/
|
2006-06-27 04:09:03 +00:00
|
|
|
NTSTATUS NTAPI RtlIntegerToChar(
|
|
|
|
ULONG value, /* [I] Value to be converted */
|
|
|
|
ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
|
|
|
ULONG length, /* [I] Length of the str buffer in bytes */
|
|
|
|
PCHAR str) /* [O] Destination for the converted value */
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2006-06-27 04:09:03 +00:00
|
|
|
CHAR buffer[33];
|
|
|
|
PCHAR pos;
|
|
|
|
CHAR digit;
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T len;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if (base == 0)
|
|
|
|
{
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
else if (base != 2 && base != 8 && base != 10 && base != 16)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2006-06-27 04:09:03 +00:00
|
|
|
pos = &buffer[32];
|
|
|
|
*pos = '\0';
|
2004-09-13 16:58:58 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
pos--;
|
2011-09-19 11:09:09 +00:00
|
|
|
digit = (CHAR)(value % base);
|
2011-09-18 22:15:37 +00:00
|
|
|
value = value / base;
|
|
|
|
|
|
|
|
if (digit < 10)
|
|
|
|
{
|
|
|
|
*pos = '0' + digit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pos = 'A' + digit - 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (value != 0L);
|
2004-09-13 16:58:58 +00:00
|
|
|
|
2006-06-27 04:09:03 +00:00
|
|
|
len = &buffer[32] - pos;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
|
|
|
if (len > length)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
else if (str == NULL)
|
|
|
|
{
|
|
|
|
return STATUS_ACCESS_VIOLATION;
|
|
|
|
}
|
|
|
|
else if (len == length)
|
|
|
|
{
|
|
|
|
memcpy(str, pos, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(str, pos, len + 1);
|
|
|
|
}
|
|
|
|
|
2006-06-27 04:09:03 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-09-13 16:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-09-13 16:58:58 +00:00
|
|
|
RtlIntegerToUnicode(
|
|
|
|
IN ULONG Value,
|
|
|
|
IN ULONG Base OPTIONAL,
|
|
|
|
IN ULONG Length OPTIONAL,
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT LPWSTR String)
|
2004-09-13 16:58:58 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
ULONG Radix;
|
|
|
|
WCHAR temp[33];
|
|
|
|
ULONG v = Value;
|
|
|
|
ULONG i;
|
|
|
|
PWCHAR tp;
|
|
|
|
PWCHAR sp;
|
|
|
|
|
|
|
|
Radix = Base;
|
|
|
|
|
|
|
|
if (Radix == 0) Radix = 10;
|
|
|
|
|
|
|
|
if ((Radix != 2) && (Radix != 8) &&
|
|
|
|
(Radix != 10) && (Radix != 16))
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
tp = temp;
|
|
|
|
|
|
|
|
while (v || tp == temp)
|
|
|
|
{
|
|
|
|
i = v % Radix;
|
|
|
|
v = v / Radix;
|
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (i < 10) *tp = (WCHAR)(i + L'0');
|
|
|
|
else *tp = (WCHAR)(i + L'a' - 10);
|
2011-09-18 22:15:37 +00:00
|
|
|
|
|
|
|
tp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) >= Length)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp = String;
|
|
|
|
|
|
|
|
while (tp > temp) *sp++ = *--tp;
|
|
|
|
|
|
|
|
*sp = 0;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlIntegerToUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN ULONG Value,
|
|
|
|
IN ULONG Base OPTIONAL,
|
|
|
|
IN OUT PUNICODE_STRING String)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ANSI_STRING AnsiString;
|
2006-04-10 17:21:46 +00:00
|
|
|
CHAR Buffer[33];
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
2004-09-13 17:27:23 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlIntegerToChar(Value, Base, sizeof(Buffer), Buffer);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
AnsiString.Buffer = Buffer;
|
|
|
|
AnsiString.Length = (USHORT)strlen(Buffer);
|
|
|
|
AnsiString.MaximumLength = sizeof(Buffer);
|
2004-09-13 17:27:23 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlAnsiStringToUnicodeString(String, &AnsiString, FALSE);
|
|
|
|
}
|
2004-09-13 17:27:23 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2004-09-13 17:27:23 +00:00
|
|
|
|
|
|
|
/*
|
2005-09-23 06:37:14 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2004-09-13 17:27:23 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-09-13 17:27:23 +00:00
|
|
|
RtlInt64ToUnicodeString (
|
2005-09-23 06:37:14 +00:00
|
|
|
IN ULONGLONG Value,
|
|
|
|
IN ULONG Base OPTIONAL,
|
|
|
|
IN OUT PUNICODE_STRING String)
|
2004-09-13 17:27:23 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
LARGE_INTEGER LargeInt;
|
|
|
|
ANSI_STRING AnsiString;
|
2006-04-10 17:21:46 +00:00
|
|
|
CHAR Buffer[65];
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
LargeInt.QuadPart = Value;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlLargeIntegerToChar(&LargeInt, Base, sizeof(Buffer), Buffer);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
AnsiString.Buffer = Buffer;
|
|
|
|
AnsiString.Length = (USHORT)strlen(Buffer);
|
|
|
|
AnsiString.MaximumLength = sizeof(Buffer);
|
|
|
|
|
|
|
|
Status = RtlAnsiStringToUnicodeString(String, &AnsiString, FALSE);
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if String2 contains String1 as a prefix.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlPrefixString(
|
2013-11-05 20:40:01 +00:00
|
|
|
const STRING *String1,
|
|
|
|
const STRING *String2,
|
2013-09-13 22:27:41 +00:00
|
|
|
BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
PCHAR pc1;
|
|
|
|
PCHAR pc2;
|
2013-09-13 22:27:41 +00:00
|
|
|
ULONG NumChars;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2013-09-13 22:27:41 +00:00
|
|
|
if (String2->Length < String1->Length)
|
|
|
|
return FALSE;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2013-09-13 22:27:41 +00:00
|
|
|
NumChars = String1->Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
pc1 = String1->Buffer;
|
|
|
|
pc2 = String2->Buffer;
|
|
|
|
|
|
|
|
if (pc1 && pc2)
|
|
|
|
{
|
|
|
|
if (CaseInsensitive)
|
|
|
|
{
|
2013-09-13 22:27:41 +00:00
|
|
|
while (NumChars--)
|
2011-09-18 22:15:37 +00:00
|
|
|
{
|
2013-09-13 22:27:41 +00:00
|
|
|
if (RtlUpperChar(*pc1++) != RtlUpperChar(*pc2++))
|
2011-09-18 22:15:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-13 22:27:41 +00:00
|
|
|
while (NumChars--)
|
2011-09-18 22:15:37 +00:00
|
|
|
{
|
|
|
|
if (*pc1++ != *pc2++)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if String2 contains String1 as a prefix.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlPrefixUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
PCUNICODE_STRING String1,
|
|
|
|
PCUNICODE_STRING String2,
|
2013-06-02 22:44:09 +00:00
|
|
|
BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
PWCHAR pc1;
|
|
|
|
PWCHAR pc2;
|
2013-09-13 22:27:41 +00:00
|
|
|
ULONG NumChars;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
|
|
|
if (String2->Length < String1->Length)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-06-02 22:44:09 +00:00
|
|
|
NumChars = String1->Length / sizeof(WCHAR);
|
2011-09-18 22:15:37 +00:00
|
|
|
pc1 = String1->Buffer;
|
2013-06-02 22:44:09 +00:00
|
|
|
pc2 = String2->Buffer;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
|
|
|
if (pc1 && pc2)
|
|
|
|
{
|
|
|
|
if (CaseInsensitive)
|
|
|
|
{
|
2013-06-02 22:44:09 +00:00
|
|
|
while (NumChars--)
|
2011-09-18 22:15:37 +00:00
|
|
|
{
|
|
|
|
if (RtlUpcaseUnicodeChar(*pc1++) !=
|
|
|
|
RtlUpcaseUnicodeChar(*pc2++))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-02 22:44:09 +00:00
|
|
|
while (NumChars--)
|
2011-09-18 22:15:37 +00:00
|
|
|
{
|
2013-06-02 22:44:09 +00:00
|
|
|
if (*pc1++ != *pc2++)
|
2011-09-18 22:15:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
2013-09-13 22:27:41 +00:00
|
|
|
|
2006-06-27 04:09:03 +00:00
|
|
|
/*
|
2004-05-31 19:33:59 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2011-09-18 22:15:37 +00:00
|
|
|
RtlUnicodeStringToInteger(
|
|
|
|
const UNICODE_STRING *str, /* [I] Unicode string to be converted */
|
2005-05-07 22:17:03 +00:00
|
|
|
ULONG base, /* [I] Number base for conversion (allowed 0, 2, 8, 10 or 16) */
|
2006-06-27 04:09:03 +00:00
|
|
|
ULONG *value) /* [O] Destination for the converted value */
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-05-07 22:17:03 +00:00
|
|
|
LPWSTR lpwstr = str->Buffer;
|
|
|
|
USHORT CharsRemaining = str->Length / sizeof(WCHAR);
|
|
|
|
WCHAR wchCurrent;
|
|
|
|
int digit;
|
|
|
|
ULONG RunningTotal = 0;
|
|
|
|
char bMinus = 0;
|
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
while (CharsRemaining >= 1 && *lpwstr <= ' ')
|
|
|
|
{
|
2008-10-25 07:12:41 +00:00
|
|
|
lpwstr++;
|
|
|
|
CharsRemaining--;
|
2011-09-18 22:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CharsRemaining >= 1)
|
|
|
|
{
|
|
|
|
if (*lpwstr == '+')
|
|
|
|
{
|
|
|
|
lpwstr++;
|
|
|
|
CharsRemaining--;
|
|
|
|
}
|
|
|
|
else if (*lpwstr == '-')
|
|
|
|
{
|
|
|
|
bMinus = 1;
|
|
|
|
lpwstr++;
|
|
|
|
CharsRemaining--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base == 0)
|
|
|
|
{
|
|
|
|
base = 10;
|
|
|
|
|
|
|
|
if (CharsRemaining >= 2 && lpwstr[0] == '0')
|
|
|
|
{
|
|
|
|
if (lpwstr[1] == 'b')
|
|
|
|
{
|
|
|
|
lpwstr += 2;
|
|
|
|
CharsRemaining -= 2;
|
|
|
|
base = 2;
|
|
|
|
}
|
|
|
|
else if (lpwstr[1] == 'o')
|
|
|
|
{
|
|
|
|
lpwstr += 2;
|
|
|
|
CharsRemaining -= 2;
|
|
|
|
base = 8;
|
|
|
|
}
|
|
|
|
else if (lpwstr[1] == 'x')
|
|
|
|
{
|
|
|
|
lpwstr += 2;
|
|
|
|
CharsRemaining -= 2;
|
|
|
|
base = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (base != 2 && base != 8 && base != 10 && base != 16)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
return STATUS_ACCESS_VIOLATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (CharsRemaining >= 1)
|
|
|
|
{
|
|
|
|
wchCurrent = *lpwstr;
|
|
|
|
|
|
|
|
if (wchCurrent >= '0' && wchCurrent <= '9')
|
|
|
|
{
|
|
|
|
digit = wchCurrent - '0';
|
|
|
|
}
|
|
|
|
else if (wchCurrent >= 'A' && wchCurrent <= 'Z')
|
|
|
|
{
|
|
|
|
digit = wchCurrent - 'A' + 10;
|
|
|
|
}
|
|
|
|
else if (wchCurrent >= 'a' && wchCurrent <= 'z')
|
|
|
|
{
|
|
|
|
digit = wchCurrent - 'a' + 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
digit = -1;
|
|
|
|
}
|
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (digit < 0 || (ULONG)digit >= base) break;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
|
|
|
RunningTotal = RunningTotal * base + digit;
|
2008-10-25 07:12:41 +00:00
|
|
|
lpwstr++;
|
|
|
|
CharsRemaining--;
|
2011-09-18 22:15:37 +00:00
|
|
|
}
|
2005-05-07 22:17:03 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
*value = bMinus ? (0 - RunningTotal) : RunningTotal;
|
2005-05-07 22:17:03 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Bytes necessary for the conversion including nullterm.
|
|
|
|
*/
|
|
|
|
ULONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-06 19:47:06 +00:00
|
|
|
RtlxUnicodeStringToOemSize(IN PCUNICODE_STRING UnicodeString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-06 19:47:06 +00:00
|
|
|
ULONG Size;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Convert the Unicode String to Mb Size */
|
|
|
|
RtlUnicodeToMultiByteSize(&Size,
|
2004-05-31 19:33:59 +00:00
|
|
|
UnicodeString->Buffer,
|
|
|
|
UnicodeString->Length);
|
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Return the size + the null char */
|
|
|
|
return (Size + sizeof(CHAR));
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function always writes a terminating '\0'.
|
|
|
|
* It performs a partial copy if ansi is too small.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUnicodeStringToAnsiString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PANSI_STRING AnsiDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
NTSTATUS RealStatus;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2011-02-07 23:23:33 +00:00
|
|
|
ASSERT(!(UniSource->Length & 1));
|
|
|
|
|
|
|
|
if (NlsMbCodePageTag == FALSE)
|
|
|
|
{
|
|
|
|
Length = (UniSource->Length + sizeof(WCHAR)) / sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Length = RtlxUnicodeStringToAnsiSize(UniSource);
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
AnsiDest->Length = (USHORT)Length - sizeof(CHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
AnsiDest->MaximumLength = (USHORT)Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!AnsiDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (AnsiDest->Length >= AnsiDest->MaximumLength)
|
|
|
|
{
|
|
|
|
if (!AnsiDest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
AnsiDest->Length = AnsiDest->MaximumLength - 1;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RealStatus = RtlUnicodeToMultiByteN(AnsiDest->Buffer,
|
|
|
|
AnsiDest->Length,
|
|
|
|
&Index,
|
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(RealStatus) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
|
|
|
|
return RealStatus;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
AnsiDest->Buffer[Index] = ANSI_NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function always writes a terminating '\0'.
|
|
|
|
* Does NOT perform a partial copy if unicode is too small!
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlOemStringToUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PCOEM_STRING OemSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlOemStringToUnicodeSize(OemSource);
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
UniDest->Length = (USHORT)Length - sizeof(WCHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
UniDest->MaximumLength = (USHORT)Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!UniDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (UniDest->Length >= UniDest->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlOemToUnicodeN(UniDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
OemSource->Buffer,
|
|
|
|
OemSource->Length);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
|
|
|
|
UniDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
UniDest->Buffer[Index / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function always '\0' terminates the string returned.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUnicodeStringToOemString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT POEM_STRING OemDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlUnicodeStringToOemSize(UniSource);
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
OemDest->Length = (USHORT)Length - sizeof(CHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
OemDest->MaximumLength = (USHORT)Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (OemDest->Length >= OemDest->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlUnicodeToOemN(OemDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
OemDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
|
|
|
|
OemDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
OemDest->Buffer[Index] = ANSI_NULL;
|
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ITU_IMPLEMENTED_TESTS (IS_TEXT_UNICODE_ODD_LENGTH|IS_TEXT_UNICODE_SIGNATURE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The length of the string if all tests were passed, 0 otherwise.
|
|
|
|
*/
|
2008-06-06 21:33:43 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2008-12-01 15:12:23 +00:00
|
|
|
RtlIsTextUnicode( PVOID buf, INT len, INT *pf )
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
static const WCHAR std_control_chars[] = {'\r', '\n', '\t', ' ', 0x3000, 0};
|
|
|
|
static const WCHAR byterev_control_chars[] = {0x0d00, 0x0a00, 0x0900, 0x2000, 0};
|
2008-06-06 21:33:43 +00:00
|
|
|
const WCHAR *s = buf;
|
|
|
|
int i;
|
2009-09-27 20:07:43 +00:00
|
|
|
unsigned int flags = MAXULONG, out_flags = 0;
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
if (len < sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
/* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
|
|
|
|
if (pf) *pf = 0;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
if (pf)
|
|
|
|
flags = *pf;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/*
|
|
|
|
* Apply various tests to the text string. According to the
|
|
|
|
* docs, each test "passed" sets the corresponding flag in
|
|
|
|
* the output flags. But some of the tests are mutually
|
|
|
|
* exclusive, so I don't see how you could pass all tests ...
|
|
|
|
*/
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* Check for an odd length ... pass if even. */
|
|
|
|
if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
if (((char *)buf)[len - 1] == 0)
|
|
|
|
len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
len /= sizeof(WCHAR);
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* Windows only checks the first 256 characters */
|
|
|
|
if (len > 256) len = 256;
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* Check for the special byte order unicode marks. */
|
|
|
|
if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
|
|
|
|
if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* apply some statistical analysis */
|
|
|
|
if (flags & IS_TEXT_UNICODE_STATISTICS)
|
|
|
|
{
|
|
|
|
int stats = 0;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* FIXME: checks only for ASCII characters in the unicode stream */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (s[i] <= 255) stats++;
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
if (stats > len / 2)
|
|
|
|
out_flags |= IS_TEXT_UNICODE_STATISTICS;
|
|
|
|
}
|
2008-12-13 21:22:07 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* Check for unicode NULL chars */
|
|
|
|
if (flags & IS_TEXT_UNICODE_NULL_BYTES)
|
|
|
|
{
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (!(s[i] & 0xff) || !(s[i] >> 8))
|
|
|
|
{
|
|
|
|
out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-13 21:22:07 +00:00
|
|
|
|
|
|
|
if (flags & IS_TEXT_UNICODE_CONTROLS)
|
|
|
|
{
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (strchrW(std_control_chars, s[i]))
|
|
|
|
{
|
|
|
|
out_flags |= IS_TEXT_UNICODE_CONTROLS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
|
|
|
|
{
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (strchrW(byterev_control_chars, s[i]))
|
|
|
|
{
|
|
|
|
out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
if (pf)
|
|
|
|
{
|
|
|
|
out_flags &= *pf;
|
|
|
|
*pf = out_flags;
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* check for flags that indicate it's definitely not valid Unicode */
|
|
|
|
if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* now check for invalid ASCII, and assume Unicode if so */
|
|
|
|
if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* now check for Unicode flags */
|
|
|
|
if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
/* no flags set */
|
|
|
|
return FALSE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 21:33:43 +00:00
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Same as RtlOemStringToUnicodeString but doesn't write terminating null
|
|
|
|
* A partial copy is NOT performed if the dest buffer is too small!
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlOemStringToCountedUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PCOEM_STRING OemSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* Calculate size of the string */
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlOemStringToCountedUnicodeSize(OemSource);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* If it's 0 then zero out dest string and return */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!Length)
|
|
|
|
{
|
|
|
|
RtlZeroMemory(UniDest, sizeof(UNICODE_STRING));
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* Check if length is a sane value */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* Store it in dest string */
|
2005-09-23 06:37:14 +00:00
|
|
|
UniDest->Length = (USHORT)Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* If we're asked to alloc the string - do so */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory(Length, TAG_USTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
UniDest->MaximumLength = (USHORT)Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!UniDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
2009-01-17 08:38:25 +00:00
|
|
|
else if (UniDest->Length > UniDest->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
|
2009-01-17 08:38:25 +00:00
|
|
|
/* Do the conversion */
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlOemToUnicodeN(UniDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
OemSource->Buffer,
|
|
|
|
OemSource->Length);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
2009-01-17 08:38:25 +00:00
|
|
|
/* Conversion failed, free dest string and return status code */
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlpFreeStringMemory(UniDest->Buffer, TAG_USTR);
|
|
|
|
UniDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
2004-06-20 23:35:14 +00:00
|
|
|
* TRUE if the names are equal, FALSE if not
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The comparison is case insensitive.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlEqualComputerName(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PUNICODE_STRING ComputerName1,
|
|
|
|
IN PUNICODE_STRING ComputerName2)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
OEM_STRING OemString1;
|
|
|
|
OEM_STRING OemString2;
|
|
|
|
BOOLEAN Result = FALSE;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString(&OemString1,
|
|
|
|
ComputerName1,
|
|
|
|
TRUE)))
|
|
|
|
{
|
|
|
|
if (NT_SUCCESS(RtlUpcaseUnicodeStringToOemString(&OemString2,
|
|
|
|
ComputerName2,
|
|
|
|
TRUE)))
|
|
|
|
{
|
|
|
|
Result = RtlEqualString(&OemString1, &OemString2, FALSE);
|
|
|
|
RtlFreeOemString(&OemString2);
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlFreeOemString(&OemString1);
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return Result;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
2004-06-20 23:35:14 +00:00
|
|
|
* TRUE if the names are equal, FALSE if not
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The comparison is case insensitive.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlEqualDomainName (
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PUNICODE_STRING DomainName1,
|
2011-09-19 11:09:09 +00:00
|
|
|
IN PUNICODE_STRING DomainName2)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
return RtlEqualComputerName(DomainName1, DomainName2);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RIPPED FROM WINE's ntdll\rtlstr.c rev 1.45
|
|
|
|
*
|
|
|
|
* Convert a string representation of a GUID into a GUID.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* str [I] String representation in the format "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
|
|
|
|
* guid [O] Destination for the converted GUID
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS. guid contains the converted value.
|
|
|
|
* Failure: STATUS_INVALID_PARAMETER, if str is not in the expected format.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* See RtlStringFromGUID.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlGUIDFromString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN UNICODE_STRING *str,
|
2011-09-19 11:09:09 +00:00
|
|
|
OUT GUID* guid)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
int i = 0;
|
|
|
|
const WCHAR *lpszCLSID = str->Buffer;
|
|
|
|
BYTE* lpOut = (BYTE*)guid;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
//TRACE("(%s,%p)\n", debugstr_us(str), guid);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
/* Convert string: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
|
|
|
* to memory: DWORD... WORD WORD BYTES............
|
|
|
|
*/
|
|
|
|
while (i <= 37)
|
|
|
|
{
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (*lpszCLSID != '{')
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
case 14:
|
|
|
|
case 19:
|
|
|
|
case 24:
|
|
|
|
if (*lpszCLSID != '-')
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 37:
|
|
|
|
if (*lpszCLSID != '}')
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
WCHAR ch = *lpszCLSID, ch2 = lpszCLSID[1];
|
|
|
|
unsigned char byte;
|
|
|
|
|
|
|
|
/* Read two hex digits as a byte value */
|
|
|
|
if (ch >= '0' && ch <= '9')
|
|
|
|
ch = ch - '0';
|
|
|
|
else if (ch >= 'a' && ch <= 'f')
|
|
|
|
ch = ch - 'a' + 10;
|
|
|
|
else if (ch >= 'A' && ch <= 'F')
|
|
|
|
ch = ch - 'A' + 10;
|
|
|
|
else
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (ch2 >= '0' && ch2 <= '9')
|
|
|
|
ch2 = ch2 - '0';
|
|
|
|
else if (ch2 >= 'a' && ch2 <= 'f')
|
|
|
|
ch2 = ch2 - 'a' + 10;
|
|
|
|
else if (ch2 >= 'A' && ch2 <= 'F')
|
|
|
|
ch2 = ch2 - 'A' + 10;
|
|
|
|
else
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
byte = ch << 4 | ch2;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
2004-05-31 19:33:59 +00:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2011-09-18 22:15:37 +00:00
|
|
|
/* For Big Endian machines, we store the data such that the
|
|
|
|
* dword/word members can be read as DWORDS and WORDS correctly. */
|
|
|
|
/* Dword */
|
|
|
|
case 1:
|
|
|
|
lpOut[3] = byte;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
lpOut[2] = byte;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
lpOut[1] = byte;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
lpOut[0] = byte;
|
|
|
|
lpOut += 4;
|
|
|
|
break;
|
|
|
|
/* Word */
|
|
|
|
case 10:
|
|
|
|
case 15:
|
|
|
|
lpOut[1] = byte;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
case 17:
|
|
|
|
lpOut[0] = byte;
|
|
|
|
lpOut += 2;
|
|
|
|
break;
|
2004-05-31 19:33:59 +00:00
|
|
|
#endif
|
2011-09-18 22:15:37 +00:00
|
|
|
/* Byte */
|
|
|
|
default:
|
|
|
|
lpOut[0] = byte;
|
|
|
|
lpOut++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpszCLSID++; /* Skip 2nd character of byte */
|
|
|
|
i++;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lpszCLSID++;
|
|
|
|
i++;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlEraseUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PUNICODE_STRING String)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
if (String->Buffer && String->MaximumLength)
|
|
|
|
{
|
|
|
|
RtlZeroMemory(String->Buffer, String->MaximumLength);
|
|
|
|
String->Length = 0;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2004-08-05 18:17:37 +00:00
|
|
|
/*
|
2005-06-22 21:01:13 +00:00
|
|
|
* @implemented
|
2004-08-05 18:17:37 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-08-05 18:17:37 +00:00
|
|
|
RtlHashUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN CONST UNICODE_STRING *String,
|
|
|
|
IN BOOLEAN CaseInSensitive,
|
|
|
|
IN ULONG HashAlgorithm,
|
|
|
|
OUT PULONG HashValue)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2005-06-22 21:01:13 +00:00
|
|
|
if (String != NULL && HashValue != NULL)
|
|
|
|
{
|
|
|
|
switch (HashAlgorithm)
|
|
|
|
{
|
|
|
|
case HASH_STRING_ALGORITHM_DEFAULT:
|
|
|
|
case HASH_STRING_ALGORITHM_X65599:
|
|
|
|
{
|
|
|
|
WCHAR *c, *end;
|
|
|
|
|
|
|
|
*HashValue = 0;
|
|
|
|
end = String->Buffer + (String->Length / sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (CaseInSensitive)
|
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
for (c = String->Buffer; c != end; c++)
|
2005-06-22 21:01:13 +00:00
|
|
|
{
|
|
|
|
/* only uppercase characters if they are 'a' ... 'z'! */
|
|
|
|
*HashValue = ((65599 * (*HashValue)) +
|
|
|
|
(ULONG)(((*c) >= L'a' && (*c) <= L'z') ?
|
|
|
|
(*c) - L'a' + L'A' : (*c)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
for (c = String->Buffer; c != end; c++)
|
2005-06-22 21:01:13 +00:00
|
|
|
{
|
|
|
|
*HashValue = ((65599 * (*HashValue)) + (ULONG)(*c));
|
|
|
|
}
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-06-22 21:01:13 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Same as RtlUnicodeStringToOemString but doesn't write terminating null
|
|
|
|
* Does a partial copy if the dest buffer is too small
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUnicodeStringToCountedOemString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT POEM_STRING OemDest,
|
|
|
|
IN PUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* Calculate size of the string */
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlUnicodeStringToCountedOemSize(UniSource);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* If it's 0 then zero out dest string and return */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!Length)
|
|
|
|
{
|
2007-07-05 11:10:08 +00:00
|
|
|
RtlZeroMemory(OemDest, sizeof(OEM_STRING));
|
2009-01-17 07:44:28 +00:00
|
|
|
return STATUS_SUCCESS;
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* Check if length is a sane value */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* Store it in dest string */
|
2005-09-23 06:37:14 +00:00
|
|
|
OemDest->Length = (USHORT)Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* If we're asked to alloc the string - do so */
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
OemDest->MaximumLength = (USHORT)Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
2009-01-17 07:44:28 +00:00
|
|
|
else if (OemDest->Length > OemDest->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-01-17 07:44:28 +00:00
|
|
|
/* Do the conversion */
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlUnicodeToOemN(OemDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
OemDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
|
|
|
|
2009-10-10 13:22:41 +00:00
|
|
|
/* Check for unmapped character */
|
|
|
|
if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
|
|
|
|
Status = STATUS_UNMAPPABLE_CHARACTER;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
2009-01-17 07:44:28 +00:00
|
|
|
/* Conversion failed, free dest string and return status code */
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
|
|
|
|
OemDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlLargeIntegerToChar(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PLARGE_INTEGER Value,
|
|
|
|
IN ULONG Base,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN OUT PCHAR String)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2009-02-16 12:07:27 +00:00
|
|
|
ULONGLONG Val = Value->QuadPart;
|
|
|
|
CHAR Buffer[65];
|
|
|
|
CHAR Digit;
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Len;
|
2009-02-16 12:07:27 +00:00
|
|
|
PCHAR Pos;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
if (Base == 0) Base = 10;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if ((Base != 2) && (Base != 8) && (Base != 10) && (Base != 16))
|
2009-02-16 12:07:27 +00:00
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
Pos = &Buffer[64];
|
|
|
|
*Pos = '\0';
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Pos--;
|
2011-09-19 11:09:09 +00:00
|
|
|
Digit = (CHAR)(Val % Base);
|
2009-02-16 12:07:27 +00:00
|
|
|
Val = Val / Base;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
if (Digit < 10)
|
|
|
|
*Pos = '0' + Digit;
|
|
|
|
else
|
|
|
|
*Pos = 'A' + Digit - 10;
|
|
|
|
}
|
|
|
|
while (Val != 0L);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
Len = &Buffer[64] - Pos;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-02-16 12:07:27 +00:00
|
|
|
if (Len > Length)
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
2012-09-14 09:56:23 +00:00
|
|
|
/* If possible, add the 0 termination */
|
|
|
|
if (Len < Length)
|
|
|
|
Len += 1;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2012-09-14 09:56:23 +00:00
|
|
|
/* Copy the string to the target using SEH */
|
|
|
|
return RtlpSafeCopyMemory(String, Pos, Len);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* dest is never '\0' terminated because it may be equal to src, and src
|
|
|
|
* might not be '\0' terminated. dest->Length is only set upon success.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUpcaseUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ULONG i, j;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString == TRUE)
|
|
|
|
{
|
|
|
|
UniDest->MaximumLength = UniSource->Length;
|
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory(UniDest->MaximumLength, TAG_USTR);
|
|
|
|
if (UniDest->Buffer == NULL) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (UniSource->Length > UniDest->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
j = UniSource->Length / sizeof(WCHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
for (i = 0; i < j; i++)
|
|
|
|
{
|
|
|
|
UniDest->Buffer[i] = RtlUpcaseUnicodeChar(UniSource->Buffer[i]);
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
UniDest->Length = UniSource->Length;
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function always writes a terminating '\0'.
|
|
|
|
* It performs a partial copy if ansi is too small.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUpcaseUnicodeStringToAnsiString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PANSI_STRING AnsiDest,
|
|
|
|
IN PUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlUnicodeStringToAnsiSize(UniSource);
|
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
AnsiDest->Length = (USHORT)Length - sizeof(CHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
AnsiDest->Buffer = RtlpAllocateStringMemory(Length, TAG_ASTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
AnsiDest->MaximumLength = (USHORT)Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!AnsiDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (AnsiDest->Length >= AnsiDest->MaximumLength)
|
|
|
|
{
|
|
|
|
if (!AnsiDest->MaximumLength) return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlUpcaseUnicodeToMultiByteN(AnsiDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
AnsiDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(AnsiDest->Buffer, TAG_ASTR);
|
|
|
|
AnsiDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
AnsiDest->Buffer[Index] = ANSI_NULL;
|
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
2005-07-20 23:35:59 +00:00
|
|
|
* This function always writes a terminating '\0'.
|
|
|
|
* It performs a partial copy if ansi is too small.
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUpcaseUnicodeStringToCountedOemString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT POEM_STRING OemDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlUnicodeStringToCountedOemSize(UniSource);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!Length)
|
|
|
|
{
|
2007-07-05 11:10:08 +00:00
|
|
|
RtlZeroMemory(OemDest, sizeof(OEM_STRING));
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
OemDest->Length = (USHORT)Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
OemDest->MaximumLength = (USHORT)Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
2007-07-14 10:59:18 +00:00
|
|
|
else if (OemDest->Length > OemDest->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlUpcaseUnicodeToOemN(OemDest->Buffer,
|
|
|
|
OemDest->Length,
|
|
|
|
&Index,
|
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2009-10-10 13:22:41 +00:00
|
|
|
/* Check for unmapped characters */
|
|
|
|
if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
|
|
|
|
Status = STATUS_UNMAPPABLE_CHARACTER;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
|
|
|
|
OemDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
* NOTES
|
2013-01-15 23:26:45 +00:00
|
|
|
* OEM string is always nullterminated
|
2004-05-31 19:33:59 +00:00
|
|
|
* It performs a partial copy if oem is too small.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlUpcaseUnicodeStringToOemString (
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT POEM_STRING OemDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG Index;
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = RtlUnicodeStringToOemSize(UniSource);
|
|
|
|
if (Length > MAXUSHORT) return STATUS_INVALID_PARAMETER_2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
OemDest->Length = (USHORT)Length - sizeof(CHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
OemDest->Buffer = RtlpAllocateStringMemory(Length, TAG_OSTR);
|
2011-09-19 11:09:09 +00:00
|
|
|
OemDest->MaximumLength = (USHORT)Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!OemDest->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (OemDest->Length >= OemDest->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlUpcaseUnicodeToOemN(OemDest->Buffer,
|
2004-05-31 19:33:59 +00:00
|
|
|
OemDest->Length,
|
2005-09-23 06:37:14 +00:00
|
|
|
&Index,
|
2004-05-31 19:33:59 +00:00
|
|
|
UniSource->Buffer,
|
|
|
|
UniSource->Length);
|
|
|
|
|
2009-10-10 13:22:41 +00:00
|
|
|
/* Check for unmapped characters */
|
|
|
|
if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
|
|
|
|
Status = STATUS_UNMAPPABLE_CHARACTER;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (!NT_SUCCESS(Status) && AllocateDestinationString)
|
|
|
|
{
|
|
|
|
RtlpFreeStringMemory(OemDest->Buffer, TAG_OSTR);
|
|
|
|
OemDest->Buffer = NULL;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
OemDest->Buffer[Index] = ANSI_NULL;
|
|
|
|
return Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Bytes calculated including nullterm
|
|
|
|
*/
|
|
|
|
ULONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-06 17:33:56 +00:00
|
|
|
RtlxOemStringToUnicodeSize(IN PCOEM_STRING OemString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-06 19:47:06 +00:00
|
|
|
ULONG Size;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Convert the Mb String to Unicode Size */
|
|
|
|
RtlMultiByteToUnicodeSize(&Size,
|
|
|
|
OemString->Buffer,
|
|
|
|
OemString->Length);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Return the size + null-char */
|
|
|
|
return (Size + sizeof(WCHAR));
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlStringFromGUID (IN REFGUID Guid,
|
|
|
|
OUT PUNICODE_STRING GuidString)
|
|
|
|
{
|
2006-06-27 04:09:03 +00:00
|
|
|
/* Setup the string */
|
|
|
|
GuidString->Length = 38 * sizeof(WCHAR);
|
|
|
|
GuidString->MaximumLength = GuidString->Length + sizeof(UNICODE_NULL);
|
|
|
|
GuidString->Buffer = RtlpAllocateStringMemory(GuidString->MaximumLength,
|
|
|
|
TAG_USTR);
|
|
|
|
if (!GuidString->Buffer) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
/* Now format the GUID */
|
|
|
|
swprintf(GuidString->Buffer,
|
|
|
|
L"{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
|
2004-05-31 19:33:59 +00:00
|
|
|
Guid->Data1,
|
|
|
|
Guid->Data2,
|
|
|
|
Guid->Data3,
|
|
|
|
Guid->Data4[0],
|
2006-06-27 04:09:03 +00:00
|
|
|
Guid->Data4[1],
|
|
|
|
Guid->Data4[2],
|
|
|
|
Guid->Data4[3],
|
|
|
|
Guid->Data4[4],
|
|
|
|
Guid->Data4[5],
|
|
|
|
Guid->Data4[6],
|
|
|
|
Guid->Data4[7]);
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Bytes calculated including nullterm
|
|
|
|
*/
|
|
|
|
ULONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-06 19:47:06 +00:00
|
|
|
RtlxUnicodeStringToAnsiSize(IN PCUNICODE_STRING UnicodeString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-06 19:47:06 +00:00
|
|
|
ULONG Size;
|
2011-02-07 23:23:33 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
|
|
|
ASSERT(!(UnicodeString->Length & 1));
|
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Convert the Unicode String to Mb Size */
|
|
|
|
RtlUnicodeToMultiByteSize(&Size,
|
2004-05-31 19:33:59 +00:00
|
|
|
UnicodeString->Buffer,
|
|
|
|
UnicodeString->Length);
|
|
|
|
|
2005-09-06 19:47:06 +00:00
|
|
|
/* Return the size + null-char */
|
|
|
|
return (Size + sizeof(CHAR));
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LONG
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCompareUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PCUNICODE_STRING s1,
|
|
|
|
IN PCUNICODE_STRING s2,
|
|
|
|
IN BOOLEAN CaseInsensitive)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
unsigned int len;
|
|
|
|
LONG ret = 0;
|
|
|
|
LPCWSTR p1, p2;
|
|
|
|
|
|
|
|
len = min(s1->Length, s2->Length) / sizeof(WCHAR);
|
|
|
|
p1 = s1->Buffer;
|
|
|
|
p2 = s2->Buffer;
|
|
|
|
|
|
|
|
if (CaseInsensitive)
|
|
|
|
{
|
|
|
|
while (!ret && len--) ret = RtlUpcaseUnicodeChar(*p1++) - RtlUpcaseUnicodeChar(*p2++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (!ret && len--) ret = *p1++ - *p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) ret = s1->Length - s2->Length;
|
|
|
|
|
|
|
|
return ret;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCopyString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PSTRING DestinationString,
|
2013-11-05 20:40:01 +00:00
|
|
|
IN const STRING *SourceString OPTIONAL)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ULONG SourceLength;
|
|
|
|
PCHAR p1, p2;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* Check if there was no source given */
|
|
|
|
if(!SourceString)
|
|
|
|
{
|
|
|
|
/* Simply return an empty string */
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Choose the smallest length */
|
|
|
|
SourceLength = min(DestinationString->MaximumLength,
|
|
|
|
SourceString->Length);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* Set it */
|
|
|
|
DestinationString->Length = (USHORT)SourceLength;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* Save the pointers to each buffer */
|
|
|
|
p1 = DestinationString->Buffer;
|
|
|
|
p2 = SourceString->Buffer;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* Loop the buffer */
|
|
|
|
while (SourceLength)
|
|
|
|
{
|
|
|
|
/* Copy the character and move on */
|
|
|
|
*p1++ = * p2++;
|
|
|
|
SourceLength--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCopyUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING DestinationString,
|
|
|
|
IN PCUNICODE_STRING SourceString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ULONG SourceLength;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if(SourceString == NULL)
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SourceLength = min(DestinationString->MaximumLength,
|
|
|
|
SourceString->Length);
|
|
|
|
DestinationString->Length = (USHORT)SourceLength;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlCopyMemory(DestinationString->Buffer,
|
|
|
|
SourceString->Buffer,
|
|
|
|
SourceLength);
|
|
|
|
|
|
|
|
if (DestinationString->Length < DestinationString->MaximumLength)
|
|
|
|
{
|
|
|
|
DestinationString->Buffer[SourceLength / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2005-04-01 00:04:15 +00:00
|
|
|
*
|
2005-07-20 23:35:59 +00:00
|
|
|
* NOTES
|
2005-04-01 00:04:15 +00:00
|
|
|
* Creates a nullterminated UNICODE_STRING
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlCreateUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PCWSTR Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = (wcslen(Source) + 1) * sizeof(WCHAR);
|
|
|
|
if (Size > MAXUSHORT) return FALSE;
|
2005-11-01 23:54:39 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory((ULONG)Size, TAG_USTR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (UniDest->Buffer == NULL) return FALSE;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
RtlCopyMemory(UniDest->Buffer, Source, Size);
|
|
|
|
UniDest->MaximumLength = (USHORT)Size;
|
|
|
|
UniDest->Length = (USHORT)Size - sizeof (WCHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return TRUE;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(
|
2011-09-18 22:15:37 +00:00
|
|
|
OUT PUNICODE_STRING Destination,
|
|
|
|
IN PCSZ Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ANSI_STRING AnsiString;
|
|
|
|
NTSTATUS Status;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlInitAnsiString(&AnsiString, Source);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Status = RtlAnsiStringToUnicodeString(Destination,
|
2004-05-31 19:33:59 +00:00
|
|
|
&AnsiString,
|
|
|
|
TRUE);
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return NT_SUCCESS(Status);
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-07-20 23:35:59 +00:00
|
|
|
* @implemented
|
2004-05-31 19:33:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Dest is never '\0' terminated because it may be equal to src, and src
|
2005-05-09 01:41:02 +00:00
|
|
|
* might not be '\0' terminated.
|
2004-05-31 19:33:59 +00:00
|
|
|
* Dest->Length is only set upon success.
|
|
|
|
*/
|
2005-09-23 06:37:14 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlDowncaseUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PUNICODE_STRING UniDest,
|
|
|
|
IN PCUNICODE_STRING UniSource,
|
|
|
|
IN BOOLEAN AllocateDestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
ULONG i;
|
|
|
|
ULONG StopGap;
|
2005-11-01 22:45:35 +00:00
|
|
|
PAGED_CODE_RTL();
|
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (AllocateDestinationString)
|
|
|
|
{
|
|
|
|
UniDest->MaximumLength = UniSource->Length;
|
|
|
|
UniDest->Buffer = RtlpAllocateStringMemory(UniSource->Length, TAG_USTR);
|
|
|
|
if (UniDest->Buffer == NULL) return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
else if (UniSource->Length > UniDest->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_OVERFLOW;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
UniDest->Length = UniSource->Length;
|
|
|
|
StopGap = UniSource->Length / sizeof(WCHAR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
for (i = 0 ; i < StopGap; i++)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
if (UniSource->Buffer[i] < L'A')
|
|
|
|
{
|
|
|
|
UniDest->Buffer[i] = UniSource->Buffer[i];
|
|
|
|
}
|
|
|
|
else if (UniSource->Buffer[i] <= L'Z')
|
|
|
|
{
|
|
|
|
UniDest->Buffer[i] = (UniSource->Buffer[i] + (L'a' - L'A'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UniDest->Buffer[i] = RtlDowncaseUnicodeChar(UniSource->Buffer[i]);
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* if src is NULL dest is unchanged.
|
|
|
|
* dest is '\0' terminated when the MaximumLength allowes it.
|
|
|
|
* When dest fits exactly in MaximumLength characters the '\0' is ommitted.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
|
|
|
|
IN PCWSTR Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2005-09-23 06:37:14 +00:00
|
|
|
USHORT Length;
|
|
|
|
PWCHAR DestBuffer;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Source)
|
|
|
|
{
|
|
|
|
UNICODE_STRING UnicodeSource;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
RtlInitUnicodeString(&UnicodeSource, Source);
|
|
|
|
Length = UnicodeSource.Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Destination->Length + Length > Destination->MaximumLength)
|
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
DestBuffer = &Destination->Buffer[Destination->Length / sizeof(WCHAR)];
|
|
|
|
RtlMoveMemory(DestBuffer, Source, Length);
|
|
|
|
Destination->Length += Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
/* append terminating '\0' if enough space */
|
|
|
|
if(Destination->MaximumLength > Destination->Length)
|
|
|
|
{
|
|
|
|
DestBuffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* if src is NULL dest is unchanged.
|
|
|
|
* dest is never '\0' terminated.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlAppendAsciizToString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN OUT PSTRING Destination,
|
|
|
|
IN PCSZ Source)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
SIZE_T Size;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
if (Source)
|
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
Size = strlen(Source);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
if (Destination->Length + Size > Destination->MaximumLength)
|
2005-09-23 06:37:14 +00:00
|
|
|
{
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-19 11:09:09 +00:00
|
|
|
RtlMoveMemory(&Destination->Buffer[Destination->Length], Source, Size);
|
|
|
|
Destination->Length += (USHORT)Size;
|
2005-09-23 06:37:14 +00:00
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-09-23 06:37:14 +00:00
|
|
|
VOID
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2004-05-31 19:33:59 +00:00
|
|
|
RtlUpperString(PSTRING DestinationString,
|
2013-11-05 20:40:01 +00:00
|
|
|
const STRING *SourceString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-19 11:09:09 +00:00
|
|
|
USHORT Length;
|
2005-09-23 06:37:14 +00:00
|
|
|
PCHAR Src, Dest;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Length = min(SourceString->Length,
|
2006-06-27 04:09:03 +00:00
|
|
|
DestinationString->MaximumLength);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
Src = SourceString->Buffer;
|
|
|
|
Dest = DestinationString->Buffer;
|
|
|
|
DestinationString->Length = Length;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2005-09-23 06:37:14 +00:00
|
|
|
while (Length)
|
|
|
|
{
|
|
|
|
*Dest++ = RtlUpperChar(*Src++);
|
|
|
|
Length--;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2004-06-20 23:35:14 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
2005-07-20 23:35:59 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See RtlpDuplicateUnicodeString
|
2004-06-20 23:35:14 +00:00
|
|
|
*/
|
2005-09-05 18:06:20 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2005-07-20 23:35:59 +00:00
|
|
|
RtlDuplicateUnicodeString(
|
2011-09-18 22:15:37 +00:00
|
|
|
IN ULONG Flags,
|
|
|
|
IN PCUNICODE_STRING SourceString,
|
|
|
|
OUT PUNICODE_STRING DestinationString)
|
2004-05-31 19:33:59 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
PAGED_CODE_RTL();
|
2005-11-01 22:45:35 +00:00
|
|
|
|
2006-06-27 04:09:03 +00:00
|
|
|
if (SourceString == NULL || DestinationString == NULL ||
|
|
|
|
SourceString->Length > SourceString->MaximumLength ||
|
|
|
|
(SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) ||
|
2011-09-18 22:15:37 +00:00
|
|
|
Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4)
|
|
|
|
{
|
2006-06-27 04:09:03 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if ((SourceString->Length == 0) &&
|
|
|
|
(Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE |
|
|
|
|
RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING)))
|
|
|
|
{
|
|
|
|
DestinationString->Length = 0;
|
|
|
|
DestinationString->MaximumLength = 0;
|
|
|
|
DestinationString->Buffer = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT DestMaxLength = SourceString->Length;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
|
|
|
|
DestMaxLength += sizeof(UNICODE_NULL);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
DestinationString->Buffer = RtlpAllocateStringMemory(DestMaxLength, TAG_USTR);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if (DestinationString->Buffer == NULL)
|
|
|
|
return STATUS_NO_MEMORY;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length);
|
|
|
|
DestinationString->Length = SourceString->Length;
|
|
|
|
DestinationString->MaximumLength = DestMaxLength;
|
2004-05-31 19:33:59 +00:00
|
|
|
|
2011-09-18 22:15:37 +00:00
|
|
|
if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE)
|
|
|
|
DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2004-05-31 19:33:59 +00:00
|
|
|
}
|
|
|
|
|
2005-03-29 02:09:42 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-09-18 22:15:37 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2005-03-29 02:09:42 +00:00
|
|
|
RtlValidateUnicodeString(IN ULONG Flags,
|
2006-05-10 17:47:44 +00:00
|
|
|
IN PCUNICODE_STRING UnicodeString)
|
2005-03-29 02:09:42 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
/* currently no flags are supported! */
|
|
|
|
ASSERT(Flags == 0);
|
|
|
|
|
|
|
|
if ((Flags == 0) &&
|
|
|
|
((UnicodeString == NULL) ||
|
|
|
|
((UnicodeString->Length != 0) &&
|
|
|
|
(UnicodeString->Buffer != NULL) &&
|
|
|
|
((UnicodeString->Length % sizeof(WCHAR)) == 0) &&
|
|
|
|
((UnicodeString->MaximumLength % sizeof(WCHAR)) == 0) &&
|
|
|
|
(UnicodeString->MaximumLength >= UnicodeString->Length))))
|
|
|
|
{
|
|
|
|
/* a NULL pointer as a unicode string is considered to be a valid unicode
|
|
|
|
string! */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2005-03-29 02:09:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 19:03:50 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2011-09-18 22:15:37 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2011-07-16 19:03:50 +00:00
|
|
|
RtlpEnsureBufferSize(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3)
|
|
|
|
{
|
|
|
|
DPRINT1("RtlpEnsureBufferSize: stub\n");
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
RtlpIsCharInUnicodeString(
|
|
|
|
IN WCHAR Char,
|
|
|
|
IN PCUNICODE_STRING MatchString,
|
|
|
|
IN BOOLEAN CaseInSensitive)
|
|
|
|
{
|
|
|
|
USHORT i;
|
|
|
|
|
|
|
|
if (CaseInSensitive)
|
|
|
|
Char = RtlUpcaseUnicodeChar(Char);
|
|
|
|
|
|
|
|
for (i = 0; i < MatchString->Length / sizeof(WCHAR); i++)
|
|
|
|
{
|
|
|
|
WCHAR OtherChar = MatchString->Buffer[i];
|
|
|
|
if (CaseInSensitive)
|
|
|
|
OtherChar = RtlUpcaseUnicodeChar(OtherChar);
|
|
|
|
|
|
|
|
if (Char == OtherChar)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-16 19:03:50 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2008-09-12 15:09:17 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2011-09-18 22:15:37 +00:00
|
|
|
RtlFindCharInUnicodeString(
|
|
|
|
IN ULONG Flags,
|
2011-10-12 11:36:52 +00:00
|
|
|
IN PCUNICODE_STRING SearchString,
|
2011-09-18 22:15:37 +00:00
|
|
|
IN PCUNICODE_STRING MatchString,
|
|
|
|
OUT PUSHORT Position)
|
2008-09-12 15:09:17 +00:00
|
|
|
{
|
2011-10-12 11:36:52 +00:00
|
|
|
BOOLEAN Found;
|
|
|
|
const BOOLEAN WantToFind = (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET) == 0;
|
|
|
|
const BOOLEAN CaseInSensitive = (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE) != 0;
|
2012-02-10 17:36:11 +00:00
|
|
|
USHORT i, Length;
|
2008-10-25 07:12:41 +00:00
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
DPRINT("RtlFindCharInUnicodeString(%u, '%wZ', '%wZ', %p)\n",
|
|
|
|
Flags, SearchString, MatchString, Position);
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
/* Parameter checks */
|
|
|
|
if (Position == NULL)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2008-10-25 07:12:41 +00:00
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
*Position = 0;
|
2011-09-18 22:15:37 +00:00
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
if (Flags & ~(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END |
|
|
|
|
RTL_FIND_CHAR_IN_UNICODE_STRING_COMPLEMENT_CHAR_SET |
|
|
|
|
RTL_FIND_CHAR_IN_UNICODE_STRING_CASE_INSENSITIVE))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2008-10-25 07:12:41 +00:00
|
|
|
|
2011-10-12 11:36:52 +00:00
|
|
|
/* Search */
|
|
|
|
Length = SearchString->Length / sizeof(WCHAR);
|
|
|
|
if (Flags & RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END)
|
|
|
|
{
|
2012-02-16 14:37:53 +00:00
|
|
|
for (i = Length - 1; (SHORT)i >= 0; i--)
|
2008-10-25 07:12:41 +00:00
|
|
|
{
|
2011-10-12 11:36:52 +00:00
|
|
|
Found = RtlpIsCharInUnicodeString(SearchString->Buffer[i], MatchString, CaseInSensitive);
|
|
|
|
if (Found == WantToFind)
|
2008-10-25 07:12:41 +00:00
|
|
|
{
|
2011-10-12 11:36:52 +00:00
|
|
|
*Position = i * sizeof(WCHAR);
|
|
|
|
return STATUS_SUCCESS;
|
2008-10-25 07:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 11:36:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < Length; i++)
|
2008-10-25 07:12:41 +00:00
|
|
|
{
|
2011-10-12 11:36:52 +00:00
|
|
|
Found = RtlpIsCharInUnicodeString(SearchString->Buffer[i], MatchString, CaseInSensitive);
|
|
|
|
if (Found == WantToFind)
|
2008-10-25 07:12:41 +00:00
|
|
|
{
|
2011-10-12 11:36:52 +00:00
|
|
|
*Position = (i + 1) * sizeof(WCHAR);
|
|
|
|
return STATUS_SUCCESS;
|
2008-10-25 07:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-18 22:15:37 +00:00
|
|
|
}
|
2008-10-25 07:12:41 +00:00
|
|
|
|
|
|
|
return STATUS_NOT_FOUND;
|
2008-09-12 15:09:17 +00:00
|
|
|
}
|
2010-01-05 16:37:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Get the maximum of MAX_COMPUTERNAME_LENGTH characters from the dns.host name until the dot is found.
|
|
|
|
* Convert is to an uppercase oem string and check for unmapped characters.
|
|
|
|
* Then convert the oem string back to an unicode string.
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2011-09-18 22:15:37 +00:00
|
|
|
RtlDnsHostNameToComputerName(PUNICODE_STRING ComputerName, PUNICODE_STRING DnsHostName, BOOLEAN AllocateComputerNameString)
|
2010-01-05 16:37:32 +00:00
|
|
|
{
|
2011-09-18 22:15:37 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Length;
|
|
|
|
ULONG ComputerNameLength;
|
|
|
|
ULONG ComputerNameOemNLength;
|
|
|
|
OEM_STRING ComputerNameOem;
|
|
|
|
CHAR ComputerNameOemN[MAX_COMPUTERNAME_LENGTH + 1];
|
|
|
|
|
|
|
|
Status = STATUS_INVALID_COMPUTER_NAME;
|
|
|
|
ComputerNameLength = DnsHostName->Length;
|
|
|
|
|
|
|
|
/* find the first dot in the dns host name */
|
|
|
|
for (Length = 0; Length < DnsHostName->Length / sizeof(WCHAR); Length++)
|
|
|
|
{
|
|
|
|
if (DnsHostName->Buffer[Length] == L'.')
|
|
|
|
{
|
|
|
|
/* dot found, so set the length for the oem translation */
|
|
|
|
ComputerNameLength = Length * sizeof(WCHAR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the computername must have one character */
|
|
|
|
if (ComputerNameLength > 0)
|
|
|
|
{
|
|
|
|
ComputerNameOemNLength = 0;
|
|
|
|
/* convert to oem string and use uppercase letters */
|
|
|
|
Status = RtlUpcaseUnicodeToOemN(ComputerNameOemN,
|
|
|
|
MAX_COMPUTERNAME_LENGTH,
|
|
|
|
&ComputerNameOemNLength,
|
|
|
|
DnsHostName->Buffer,
|
|
|
|
ComputerNameLength);
|
|
|
|
|
|
|
|
/* status STATUS_BUFFER_OVERFLOW is not a problem since the computername shoud only
|
|
|
|
have MAX_COMPUTERNAME_LENGTH characters */
|
|
|
|
if ((Status == STATUS_SUCCESS) ||
|
|
|
|
(Status == STATUS_BUFFER_OVERFLOW))
|
|
|
|
{
|
|
|
|
/* set the termination for the oem string */
|
|
|
|
ComputerNameOemN[MAX_COMPUTERNAME_LENGTH] = 0;
|
|
|
|
/* set status for the case the next function failed */
|
|
|
|
Status = STATUS_INVALID_COMPUTER_NAME;
|
|
|
|
/* fillup the oem string structure with the converted computername
|
|
|
|
and check it for unmapped characters */
|
|
|
|
ComputerNameOem.Buffer = ComputerNameOemN;
|
|
|
|
ComputerNameOem.Length = (USHORT)ComputerNameOemNLength;
|
|
|
|
ComputerNameOem.MaximumLength = (USHORT)(MAX_COMPUTERNAME_LENGTH + 1);
|
|
|
|
|
|
|
|
if (RtlpDidUnicodeToOemWork(DnsHostName, &ComputerNameOem) == TRUE)
|
|
|
|
{
|
|
|
|
/* no unmapped character so convert it back to an unicode string */
|
|
|
|
Status = RtlOemStringToUnicodeString(ComputerName,
|
|
|
|
&ComputerNameOem,
|
|
|
|
AllocateComputerNameString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2010-01-05 16:37:32 +00:00
|
|
|
}
|
|
|
|
|