windwos kernel字符串
作者:互联网
创建
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
UNICODE_STRING s2;
RtlInitUnicodeString(&s2, L"string 2");
DbgPrintEx(0, 0, "%wZ %wZ", &s1, &s2);
拷贝
WCHAR buf[60] = { 0 };
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
UNICODE_STRING s2;
s2.Buffer = buf;
s2.Length = s2.MaximumLength = 60;
RtlCopyUnicodeString(&s2, &s1);
DbgPrintEx(0, 0, "%wZ %wZ", &s1, &s2);
uppercase
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
UNICODE_STRING s2;
RtlUpcaseUnicodeString(&s2, &s1, TRUE);
DbgPrintEx(0, 0, "%wZ %wZ", &s1, &s2);
RtlFreeUnicodeString(&s2); // 释放
unicode to ansi
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
ANSI_STRING s2 = { 0 };
if ( NT_SUCCESS(RtlUnicodeStringToAnsiString(&s2, &s1, TRUE)) )
{
DbgPrintEx(0, 0, "%wZ %Z", &s1, &s2);
RtlFreeAnsiString(&s2); // 释放
}
比较是否相等
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
UNICODE_STRING s2 = RTL_CONSTANT_STRING(L"string 1");
if (RtlEqualUnicodeString(&s1, &s2, TRUE))
{
DbgPrintEx(0, 0, "1");
}
else
{
DbgPrintEx(0, 0, "0");
}
wcsncpy_s 拷贝字符串
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
WCHAR s2[50] = { 0 };
wcsncpy_s(s2, 50, s1.Buffer, s1.Length);
DbgPrintEx(0, 0, "%wZ %ws", s1, s2);
字符串长度
UNICODE_STRING s1 = RTL_CONSTANT_STRING(L"string 1");
size_t len = wcsnlen(s1.Buffer, 100);
if (len == 100)
{
// 超出预期
}
DbgPrintEx(0, 0, "len: %d", len);
标签:kernel,DbgPrintEx,STRING,s2,s1,字符串,UNICODE,windwos,string 来源: https://www.cnblogs.com/ajanuw/p/13762342.html