none
Formatting UNICODE strings in driver level RRS feed

  • Question

  • I am trying to format a unicode string with some data values using RtlUnicodeStringPrintf() function. The string is actually a hardware id which I am stuffing with the values I need to fill like vid, pid etc. Since hardware ids are null terminated, I am having issues with nulls in the string. Once the function returns, the hardware id string gets cut off at the first null. I am not getting the full string. My string is two hardware id strings each terminated by NULL as below.
    #define HWID L"USB\\Vid_%04x&Pid_%04x&Rev_%04x\0USB\\Vid_%04x&Pid_%04x\0" \\ I am embedding NULLs in the string itself
    DECLARE_UNICODE_STRING_SIZE(myhwID, (sizeof(HWID));
    
    status = RtlUnicodeStringPrintf(&myhwID, HWID, vid,pid, ver,vendor,pid);
    

    The function returns success. The result is "USB\\Vid_%04x&Pid_%04x&Rev_%04x\0" with the values of vid, pid etc stuffed. But the section of the string after the first embeded NULL is gone.  How can I get the full string stuffed with the values including the terminating NULL?
    Tuesday, May 6, 2014 6:20 PM

Answers

  • one way is to change change the middle NULL(s) to character insertion

    #define HWID L"USB\\Vid_%04x&Pid_%04x&Rev_%04x%cUSB\\Vid_%04x&Pid_%04x%c" \\ I am embedding NULLs in the string itself
    DECLARE_UNICODE_STRING_SIZE
    (myhwID, (sizeof(HWID));

    status
    = RtlUnicodeStringPrintf(&myhwID, HWID, vid,pid, ver, L'\0', vendor,pid, L'\0');


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, May 6, 2014 9:42 PM

All replies

  • one way is to change change the middle NULL(s) to character insertion

    #define HWID L"USB\\Vid_%04x&Pid_%04x&Rev_%04x%cUSB\\Vid_%04x&Pid_%04x%c" \\ I am embedding NULLs in the string itself
    DECLARE_UNICODE_STRING_SIZE
    (myhwID, (sizeof(HWID));

    status
    = RtlUnicodeStringPrintf(&myhwID, HWID, vid,pid, ver, L'\0', vendor,pid, L'\0');


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, May 6, 2014 9:42 PM
  • Thanks Doron. I tried this. The substituition is OK. The string now looks like USB\\Vid_%04x&Pid_%04x&Rev_%04x%\0USB\\Vid_%04x&Pid_%04x%\0"( values of Vids Pids etc not shown in the sample). ie. the NULL character is also displayed in the string when we inspect it. Is it OK? Is there anyway to format this string such that the NULL character is implicitly taken by the system and also the string is also not cut off?
    Thursday, May 8, 2014 12:44 PM
  • not sure what you mean by the string being cut off. do you mean in a printf statement?

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, May 8, 2014 4:42 PM
  • In KdPrint(), the string is cut off..

    KdPrint((" Value =%wZ \r\n", hardwid));

    Friday, May 9, 2014 3:48 AM