printing HardwareIDs;

How can I print HardwareIDs? I understand they are MULTI_REG_SZ - multiple strings each terminating with \0. Is there some function for that.

Currently I wrote my own function as follows:

VOID DebugPrintStr (ULONG DebugPrintLevel,
PCWCHAR Buffer,
ULONG Length)
{
NTSTATUS status;
ULONG i; // index into the Buffer pointing to the begining of the next string
ULONG j; // length of the current string

for (i = 0, j = 0; i < Length; i += (j + 1)) {
DbgPrintEx (DPFLTR_IHVDRIVER_ID, DebugPrintLevel, “%ws\n”, &Buffer[i]);
/* get the end of this string
*/
status = RtlStringCchLengthW (
&Buffer[i],
Length + 1 - i, /* remaining MAX including the next ‘\0’ */
&j); /* length of upto (but not including) next ‘\0’ */
}

}

And this is what I get? I’m not sure why I’m getting so many ‘?’.
Help. Thanks.

Intel-2920
???DisIntel-2920
Internal_IDE_Channel

??? ??

??DisIntel-2920
J??? ???l-29???†??
?DisIntel-2920
??? ???l-29???†??
DisIntel-2920
??? ???l-29???†??
isIntel-2920
??? ???l-29???†??
sIntel-2920
??? ???l-29???†??
Intel-2920
??? ???l-29???†??
ntel-2920
??? ???l-29???†??
tel-2920
??? ???l-29???†??
el-2920
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??

No, there is no kernel function that I know of that will do this for you.

Good luck,

mm

xxxxx@yahoo.com wrote:

How can I print HardwareIDs? I understand they are MULTI_REG_SZ - multiple strings each terminating with \0. Is there some function for that.

Currently I wrote my own function as follows:

VOID DebugPrintStr (ULONG DebugPrintLevel,
PCWCHAR Buffer,
ULONG Length)
{
NTSTATUS status;
ULONG i; // index into the Buffer pointing to the begining of the next string
ULONG j; // length of the current string

for (i = 0, j = 0; i < Length; i += (j + 1)) {
DbgPrintEx (DPFLTR_IHVDRIVER_ID, DebugPrintLevel, “%ws\n”, &Buffer[i]);
/* get the end of this string
*/
status = RtlStringCchLengthW (
&Buffer[i],
Length + 1 - i, /* remaining MAX including the next ‘\0’ */
&j); /* length of upto (but not including) next ‘\0’ */
}

}

And this is what I get? I’m not sure why I’m getting so many ‘?’.
Help. Thanks.

Intel-2920
???DisIntel-2920
Internal_IDE_Channel

??? ??

??DisIntel-2920
J??? ???l-29???†??
?DisIntel-2920
??? ???l-29???†??
DisIntel-2920
??? ???l-29???†??
isIntel-2920
??? ???l-29???†??
sIntel-2920
??? ???l-29???†??
Intel-2920
??? ???l-29???†??
ntel-2920
??? ???l-29???†??
tel-2920
??? ???l-29???†??
el-2920
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
??? ???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??
???
???l-29???†??

that is a bit complicated for me b/c of all the indexing ;). I usually just use this loop.

PWCHAR pCur;

for (pCur = Buffer; *pCur != L’\0’; pCur += wcslen(pCur) + 1) {
DbgPrint(“%ws”, pCur);
}

Note that this trusts that Buffer is a well formed multi sz, it does not validate that the buffer is double null terminated nor if Length is an even number.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Monday, June 23, 2008 8:09 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] printing HardwareIDs;

How can I print HardwareIDs? I understand they are MULTI_REG_SZ - multiple strings each terminating with \0. Is there some function for that.

Currently I wrote my own function as follows:

VOID DebugPrintStr (ULONG DebugPrintLevel,
PCWCHAR Buffer,
ULONG Length)
{
NTSTATUS status;
ULONG i; // index into the Buffer pointing to the begining of the next string
ULONG j; // length of the current string

for (i = 0, j = 0; i < Length; i += (j + 1)) {
DbgPrintEx (DPFLTR_IHVDRIVER_ID, DebugPrintLevel, “%ws\n”, &Buffer[i]);
/* get the end of this string
*/
status = RtlStringCchLengthW (
&Buffer[i],
Length + 1 - i, /* remaining MAX including the next ‘\0’ */
&j); /* length of upto (but not including) next ‘\0’ */
}

}

And this is what I get? I’m not sure why I’m getting so many ‘?’.
Help. Thanks.

Intel-2920
???DisIntel-2920
Internal_IDE_Channel

??? ??

??DisIntel-2920
J??? ???l-29???
?DisIntel-2920
??? ???l-29???
DisIntel-2920
??? ???l-29???
isIntel-2920
??? ???l-29???
sIntel-2920
??? ???l-29???
Intel-2920
??? ???l-29???
ntel-2920
??? ???l-29???
tel-2920
??? ???l-29???
el-2920
??? ???l-29???
??? ???l-29???
??? ???l-29???
??? ???l-29???
??? ???l-29???
??? ???l-29???
??? ???l-29???
???
???l-29???
???
???l-29???
???
???l-29???
???
???l-29???
???
???l-29???


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Doron. I obtained the hardwared id value using
IoGetDeviceProperty (DeviceObject,
DevicePropertyHardwareID
length,
buffer, /* PWCHAR type */
ResultLength);

so can I assume that it is good to be printed using your code?

Typically these are written by the kernel so they will be well formed, but any admin can overwrite them to be malformed. Once argume is that since this requires an admin in the first place, there is nothing more the driver should do, but IMHO the driver can easily validate the format of the data b/c it has the buffer length to know where it should end. The same should apply to REG_SZ values read out of the registry, it is not always safe to assume there is a null terminating the end of the string.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Monday, June 23, 2008 10:50 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] printing HardwareIDs;

Thanks Doron. I obtained the hardwared id value using
IoGetDeviceProperty (DeviceObject,
DevicePropertyHardwareID
length,
buffer, /* PWCHAR type */
ResultLength);

so can I assume that it is good to be printed using your code?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Some comments, solely about the code you quoted, without further research.

xxxxx@yahoo.com wrote:

VOID DebugPrintStr (ULONG DebugPrintLevel,
PCWCHAR Buffer,
ULONG Length)
{
NTSTATUS status;
ULONG i; // index into the Buffer pointing to the begining of the next string
ULONG j; // length of the current string

Not ULONG, but size_t - please check the prototype of the function you
use. What if the datatype is a 64bit type?

for (i = 0, j = 0; i < Length; i += (j + 1)) {
DbgPrintEx (DPFLTR_IHVDRIVER_ID, DebugPrintLevel, “%ws\n”, &Buffer[i]);

With wide characters, any invalid values explain the amount of “?” you
get. A lot of them are just not ASCII-printable.

/* get the end of this string
*/
status = RtlStringCchLengthW (
&Buffer[i],
Length + 1 - i, /* remaining MAX including the next ‘\0’ */
&j); /* length of upto (but not including) next ‘\0’ */

Always check the return status - your parameters may be wrong.

if (j==0) break; /* add this to avoid infinite loop */

}

}

Looks to me like your “j” is never properly updated. Together with the i
+= (j+1), always the same string is printed with a one-character offset.

So far my two minutes…
HTH -H