znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
阅读:2837回复:0

KdPrint/DbgPrint and UNICODE_STRING/ANSI_STRING

楼主#
更多 发布于:2008-03-30 16:06
KdPrint/DbgPrint and UNICODE_STRING/ANSI_STRING
Just to remember:
NT likes string of the following form:

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, _vsnprintf, KdPrint/DbgPrint). For example:

PUNICODE_STRING pUStr;
PANSI_STRING    pAStr;
...
KdPrint(("Unicode string: %wZ\n", pUStr));
KdPrint(("ANSI    string: %Z\n",  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\n",pUStr->Length/sizeof(WCHAR),
    pUStr->Length/sizeof(WCHAR), pUStr));
KdPrint(("Unicode string: %*.*S\n",pUStr->Length/sizeof(WCHAR),
    pUStr->Length/sizeof(WCHAR), pUStr));
KdPrint(("ANSI    string: %*.*s\n", 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\n",
    pUStr->Length/sizeof(WCHAR), pUStr));
KdPrint(("Unicode string: %.*S\n",
    pUStr->Length/sizeof(WCHAR), pUStr));
KdPrint(("ANSI    string: %.*s\n",
    pAStr->Length/sizeof(CHAR),  pAStr));

http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
游客

返回顶部