#ifndef _NTSTRSAFE_H_INCLUDED_
#ifndef NTSTRSAFE_LIB_IMPL
#ifndef NTSTRSAFE_NO_UNICODE_STRING_FUNCTIONS
#ifndef NTSTRSAFE_NO_CCH_FUNCTIONS
NTSTRSAFEDDI
RtlUnicodeStringCchCopyN(
_Inout_ PUNICODE_STRING DestinationString,
_In_ PCUNICODE_STRING SourceString,
_In_ size_t cchToCopy)
{
NTSTATUS status;
wchar_t* pszDest;
size_t cchDest;
status = RtlUnicodeStringValidateDestWorker(DestinationString,
&pszDest,
&cchDest,
NULL,
NTSTRSAFE_UNICODE_STRING_MAX_CCH,
0);
if (NT_SUCCESS(status))
{
wchar_t* pszSrc;
size_t cchSrcLength;
size_t cchNewDestLength = 0;
status = RtlUnicodeStringValidateSrcWorker(SourceString,
&pszSrc,
&cchSrcLength,
NTSTRSAFE_UNICODE_STRING_MAX_CCH,
0);
if (NT_SUCCESS(status))
{
if (cchToCopy > NTSTRSAFE_UNICODE_STRING_MAX_CCH)
{
status = STATUS_INVALID_PARAMETER;
}
else
{
if (cchSrcLength < cchToCopy)
{
cchToCopy = cchSrcLength;
}
status = RtlWideCharArrayCopyWorker(pszDest,
cchDest,
&cchNewDestLength,
pszSrc,
cchToCopy);
}
}
// safe to multiply cchNewDestLength * sizeof(wchar_t) since cchDest < NTSTRSAFE_UNICODE_STRING_MAX_CCH and sizeof(wchar_t) is 2
DestinationString->Length = (USHORT)(cchNewDestLength * sizeof(wchar_t));
}
return status;
}
View code on GitHub
No description available.