zoukankan      html  css  js  c++  java
  • KdPrint/DbgPrint and UNICODE_STRING/ANSI_STRING

    typedef struct _UNICODE_STRING {
        USHORT Length;
        USHORT MaximumLength;
        PWSTR  Buffer;
    } UNICODE_STRING;
    typedef UNICODE_STRING *PUNICODE_STRING;
    
    
    typedef struct _STRING {
        USHORT Length;
        USHORT MaximumLength;
        PCHAR Buffer;
    } STRING;
    typedef STRING *PSTRING;
    
    typedef STRING ANSI_STRING;
    typedef PSTRING PANSI_STRING;

    To make life easier MS have extended kernel CRTL output() function with Z format specifier. This works for all kernel functions those understand formatted strings (e.g. sprintf_vsnprintfKdPrint/DbgPrint). For example:

    PUNICODE_STRING pUStr;
    PANSI_STRING    pAStr;
    ...
    KdPrint(("Unicode string: %wZ
    ", pUStr));
    KdPrint(("ANSI    string: %Z
    ",  pAStr));
    

    Though, you can use a little more complicated documented way. Btw, this form is suitable for printing byte array of strictly defined length.

    KdPrint(("Unicode string: %*.*ws
    ",pUStr->Length/sizeof(WCHAR),
        pUStr->Length/sizeof(WCHAR), pUStr));
    KdPrint(("Unicode string: %*.*S
    ",pUStr->Length/sizeof(WCHAR),
        pUStr->Length/sizeof(WCHAR), pUStr));
    KdPrint(("ANSI    string: %*.*s
    ", pAStr->Length/sizeof(CHAR),
        pAStr->Length/sizeof(CHAR),  pAStr));
    

    Or, if you want to take into account NULL-terminator, but limit output length to specified number of characters:

    KdPrint(("Unicode string: %.*ws
    ",
        pUStr->Length/sizeof(WCHAR), pUStr));
    KdPrint(("Unicode string: %.*S
    ",
        pUStr->Length/sizeof(WCHAR), pUStr));
    KdPrint(("ANSI    string: %.*s
    ",
        pAStr->Length/sizeof(CHAR),  pAStr));

  • 相关阅读:
    [mysql练习]多行结果合并问题练习
    【Python】Python多进程练习
    【mysql练习】转置,总计,分组
    【Mysql】HDFS文件上传流程
    [Jmeter][基础]Jmeter连接IMPALA
    【Linux】 -bash-4.2#问题和Cannot allocate memory
    微服务学习之路
    好的东西一定要收藏-持续更新
    Python日期的加减等操作
    NGINX动态增加模块,平滑升级
  • 原文地址:https://www.cnblogs.com/vcerror/p/4289061.html
Copyright © 2011-2022 走看看