1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
18 OBJECT_ATTRIBUTES ObjectAttributes
;
19 UNICODE_STRING NameString
;
22 //KdPrint(("RegTGetKeyHandle: h=%x, %S\n", hRootKey, KeyName));
24 NameString
.Buffer
= KeyName
;
25 NameString
.Length
= wcslen(KeyName
)*sizeof(WCHAR
);
26 NameString
.MaximumLength
= NameString
.Length
+ sizeof(WCHAR
);
28 InitializeObjectAttributes(
42 if(!NT_SUCCESS(status
)) {
43 //KdPrint((" status %x\n", status));
48 } // end RegTGetKeyHandle()
56 } // end RegTCloseKeyHandle()
70 hRootKey
= HKEY_LOCAL_MACHINE
;
72 status
= RegOpenKeyExW(
80 if(status
!= ERROR_SUCCESS
) {
85 } // end RegTGetKeyHandle()
96 } // end RegTCloseKeyHandle()
103 IN PWSTR RegistryPath
,
109 UNICODE_STRING NameString
;
110 PKEY_VALUE_PARTIAL_INFORMATION ValInfo
;
115 BOOLEAN retval
= FALSE
;
116 BOOLEAN free_h
= FALSE
;
120 hRootKey
= HKEY_LOCAL_MACHINE
;
123 if(RegistryPath
&& RegistryPath
[0]) {
124 status
= RegTGetKeyHandle(hRootKey
, RegistryPath
, &hKey
);
126 if(status
!= ERROR_SUCCESS
)
128 if(!NT_SUCCESS(status
))
140 KdPrint(("h=%x|%S, %S (%x)\n",
141 hRootKey, RegistryPath, Name, *pUlong));
143 len
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(ULONG
) + 0x20;
144 ValInfo
= (PKEY_VALUE_PARTIAL_INFORMATION
)
145 MyAllocatePool__(NonPagedPool
, len
);
148 RegTCloseKeyHandle(hKey
);
153 NameString
.Buffer
= Name
;
154 NameString
.Length
= wcslen(Name
)*sizeof(WCHAR
);
155 NameString
.MaximumLength
= NameString
.Length
+ sizeof(WCHAR
);
157 status
= ZwQueryValueKey(hKey
,
159 KeyValuePartialInformation
,
163 if(NT_SUCCESS(status
) &&
164 ValInfo
->DataLength
== sizeof(ULONG
)) {
165 RtlCopyMemory(pUlong
, ValInfo
->Data
, sizeof(ULONG
));
167 //KdPrint((" -> %x\n",*pUlong));
169 //KdPrint((" err %x\n",status));
172 MyFreePool__(ValInfo
);
175 if (ERROR_SUCCESS
== RegQueryValueExW(
176 hKey
, // handle of key to query
177 Name
, // address of name of value to query
179 NULL
, // address of buffer for value type
180 (BYTE
*)pUlong
, // address of data buffer
181 &len
// address of data buffer size
182 ) && len
== sizeof(ULONG
)) {
187 RegTCloseKeyHandle(hKey
);
190 } // end RegTGetDwordValue()
195 IN PWSTR RegistryPath
,
202 UNICODE_STRING NameString
;
203 PKEY_VALUE_PARTIAL_INFORMATION ValInfo
;
208 BOOLEAN retval
= FALSE
;
209 BOOLEAN free_h
= FALSE
;
213 hRootKey
= HKEY_LOCAL_MACHINE
;
216 if(RegistryPath
&& RegistryPath
[0]) {
217 status
= RegTGetKeyHandle(hRootKey
, RegistryPath
, &hKey
);
219 if(status
!= ERROR_SUCCESS
)
221 if(!NT_SUCCESS(status
))
233 len
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + MaxLen
+ 0x20;
234 ValInfo
= (PKEY_VALUE_PARTIAL_INFORMATION
)
235 MyAllocatePool__(NonPagedPool
, len
);
238 RegTCloseKeyHandle(hKey
);
243 NameString
.Buffer
= Name
;
244 NameString
.Length
= wcslen(Name
)*sizeof(WCHAR
);
245 NameString
.MaximumLength
= NameString
.Length
+ sizeof(WCHAR
);
247 status
= ZwQueryValueKey(hKey
,
249 KeyValuePartialInformation
,
253 if(NT_SUCCESS(status
) &&
254 ValInfo
->DataLength
) {
255 RtlCopyMemory(pStr
, ValInfo
->Data
, min(ValInfo
->DataLength
, MaxLen
) );
256 if(pStr
[(ValInfo
->DataLength
)/sizeof(WCHAR
)-1]) {
257 pStr
[(ValInfo
->DataLength
)/sizeof(WCHAR
)-1] = 0;
262 MyFreePool__(ValInfo
);
265 if (ERROR_SUCCESS
== RegQueryValueExW(
266 hKey
, // handle of key to query
267 Name
, // address of name of value to query
269 NULL
, // address of buffer for value type
270 (BYTE
*)pStr
, // address of data buffer
271 &len
// address of data buffer size
281 RegTCloseKeyHandle(hKey
);
284 } // end RegTGetStringValue()