zoukankan      html  css  js  c++  java
  • [Windows驱动开发] 驱动中的字符串操作

    UINCODE_STRING

    初始化:

    // UNICODE_STRING u_src;		// 此时的 UNICODE_STRING 里面的 Buffer 指针是指向全局常量区, 操作它(比如拷贝)时很可能会出现蓝屏
    UNICODE_STRING u_src = {0};		// 这样初始化的方式.是将UNICODE_STRING的 Buffer指针指向栈内存
    RtlInitUnicodeString(&src,"hello");
    
    
    
    /   在堆上初始化
    UNICODE_STRING ustr = {0};
    ULONG length = (wcslen(L"HelloWorld") + ) * sizeof(WCHAR);
    ustr.Buffer = ExAllocatePoolWithTag(PagedPool,MAX_PATH 8 sizeof(WCHAR),"niBI");
    
    if (ustr.Buffer == NULL)
        return ;
    
    清空缓存
    RtlZeroMemory(ustr.Buffer,MAX_PATH *sizeof(WCHAR));
    
    wcscpy(ustr.Buffer,L"HelloWorld");
    ustr.length = length;
    ustr.Maximumlength = MAX_PATH * sizeof(WCHAR);
    
    DbgPrint("%wZ",&ustr);
    ExFreePool(ustr.Buffer); 
    

    UNICODE_STRING 转 PWCHAR:

    NTSTRSAFEDDI RtlStringCbCopyUnicodeString(
      NTSTRSAFE_PWSTR  pszDest,
      size_t           cbDest,
      PCUNICODE_STRING SourceString
    );
    

    拼接两个 UNICODE_STRING:

    NTSTRSAFEDDI RtlUnicodeStringCat(
      PUNICODE_STRING  DestinationString,
      PCUNICODE_STRING SourceString
    );
    
    // 按字节数拼接(不完整拼接)
    NTSTRSAFEDDI RtlUnicodeStringCbCatN(
      PUNICODE_STRING  DestinationString,
      PCUNICODE_STRING SourceString,
      size_t           cbToAppend
    );
    

    使用 pwchar 拼接 UNICODE_STRING:

    NTSTRSAFEDDI RtlUnicodeStringCatString(
      PUNICODE_STRING  DestinationString,
      NTSTRSAFE_PCWSTR pszSrc
    );
    

    其他 pchar、pwchar 操作

    RtlStringcbCatA() 		字符串拼接
    RtlStringcbCopy()		字符串拷贝
    RtlStringcbLength()		求长度
    RtlStringcbPrnt()		字符串打印
    
  • 相关阅读:
    Response.Status http协议状态代码
    ASP.NET MVC 如何实现头压缩
    Google PR值原理和详细解说
    NodeJS 深入浅出
    C#: ToString格式
    HttpHandler实现媒体文件和图像文件的盗链(防盗链设计)
    ASP.NET MVC 使用Areas功能的常见错误
    VC中利用多线程技术实现线程之间的通信
    基于Visual C++的Winsock API研究
    键盘钩子程序
  • 原文地址:https://www.cnblogs.com/csnd/p/15613343.html
Copyright © 2011-2022 走看看