Re: Reading GUID from registry

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



No,

You have multiple problems here, the UNICODE_STRING is a length, max
length and pointer to the string. Also RtlStringFromGUID allocates the
buffer for the string without space for the NULL. So you need something
like (I have not tested or compiled this):

UNICODE_STRING DiskId;
PWCHAR Buffer;

status = RtlStringFromGUID(&Partition.disk_id,&DiskId);
if ( NT_SUCCESS( status ) )
{
KdPrint(( "Got String %wZ\n", &DiskId );
Buffer = ExAllocatePoolWithTag( PagedPool, DiskId.Length +
sizeof( WCHAR), TAG );
if ( Buffer != NULL )
{
RtlZeroMemory( Buffer, DiskId.Length + sizeof( WCHAR) );
RtlCopyMemory( Buffer, DiskId.Buffer, DiskId.Length );
status = ZwSetValueKey( ... )
ExFreePool( Buffer );
RtlFreeUnicodeString( &DiskId );
}
}


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ADCD644F-DD86-4C0E-B305-943E609AC904@xxxxxxxxxxxxxxxx
I use ZwSetValueKey to set the ID in registry.
I takes PVOID as the input paramater.
I just pass addresss of UNICODE_STRING to it like &DiskID
and the length parameter as sizeof(WCHAR) + DiskID.Length
Is it correct???


"Don Burn" wrote:

No, UNICODE_STRINGS have a pointer, but the registry calls take a
pointer
to the wide character strings. The print is probably messed up the same
way, as is the write.


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E3ED71C1-E295-453E-B44D-4C37B6CC6288@xxxxxxxxxxxxxxxx
I tried using RtlGUIDfromString

UNICODE_STRING DiskID;
status = RtlStringFromGUID(&Partition.disk_id,&DiskID);

I checked the return value also.It is success but however when I try to
print the DiskID unicode I see some junk.
Now I am setting this value in Registry.

when I query from registry I use

status = ZwQueryValueKey(MemberKeyHandle,
&RegistryValueName,
KeyValuePartialInformation,
pKeyValuePartialInformation,
KeyInformationLength,
&ResultLength);
if(NT_SUCCESS(status))
{
RtlGUIDFromString((UNICODE_STRING
*)pKeyValuePartialInformation->Data,
&disk_id.DiskId);
}
After this I am blue screening.Is my usage of the above 2 functions
correct????



"Don Burn" wrote:

No you cannot use strtok. You can depending on how you wrote it use
RtlGUIDfromString. Why did you write the GUID as a string, a binary
registry entry is easier.


--
Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply




"qwert" <qwert@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B8176D31-2307-485B-89B3-D9E6D507768F@xxxxxxxxxxxxxxxx
I have a case were I need to read the GUID which I have written in
registry.
I actually created a wchar array and used swprintf to format the
GUID
structure and I did set the GUID in the registry,
Now I wanted read back that string and assign the values to the
structure.
Normally when I write the GUID in registry I enclose it with
brackets
and
use hyphens inbetween to print it in correct format.
I have strtok in application where I can use hyphens as delimiters.
In kernel side can I use strtok???
How do normally people do this in kernel side???
Thanks in advance









.



Relevant Pages

  • Re: Reading GUID from registry
    ... Don Burn (MVP, Windows DDK) ... Now I am setting this value in Registry. ... I actually created a wchar array and used swprintf to format the GUID ... Now I wanted read back that string and assign the values to the ...
    (microsoft.public.development.device.drivers)
  • Re: help debugging KMODE_EXCEPTION_NOT_HANDLED
    ... Well since ObjectName is a UNICODE_STRING and its buffer is commonly not ... I would assume you just ran off the end of the string into ... Don Burn (MVP, Windows DDK) ...
    (microsoft.public.development.device.drivers)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Secure C library
    ... I read much of the new "security TR", and gee, I don't know. ... the buffer from the buffer size. ... It is not hard to design a better form of buffer and string handling. ... but this is just one example of how thoughtful interface design can ...
    (comp.std.c)
  • Re: Secure C library
    ... >> string functions don't make much sense once you add bounds-checking ... >> designing an interface just for the purpose of reducing the frequency ... > make buffer size decisions more visible, ... Bstrlib is also very interoperable with char *'s, ...
    (comp.std.c)