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 RtlInitUnicodeString(&NameString
, KeyName
);
26 InitializeObjectAttributes(
40 if(!NT_SUCCESS(status
)) {
41 //KdPrint((" status %x\n", status));
46 } // end RegTGetKeyHandle()
54 } // end RegTCloseKeyHandle()
68 hRootKey
= HKEY_LOCAL_MACHINE
;
70 status
= RegOpenKeyExW(
78 if(status
!= ERROR_SUCCESS
) {
83 } // end RegTGetKeyHandle()
94 } // end RegTCloseKeyHandle()
101 IN PCWSTR RegistryPath
,
107 UNICODE_STRING NameString
;
108 PKEY_VALUE_PARTIAL_INFORMATION ValInfo
;
113 BOOLEAN retval
= FALSE
;
114 BOOLEAN free_h
= FALSE
;
118 hRootKey
= HKEY_LOCAL_MACHINE
;
121 if(RegistryPath
&& RegistryPath
[0]) {
122 status
= RegTGetKeyHandle(hRootKey
, RegistryPath
, &hKey
);
124 if(status
!= ERROR_SUCCESS
)
126 if(!NT_SUCCESS(status
))
138 KdPrint(("h=%x|%S, %S (%x)\n",
139 hRootKey, RegistryPath, Name, *pUlong));
141 len
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(ULONG
) + 0x20;
142 ValInfo
= (PKEY_VALUE_PARTIAL_INFORMATION
)
143 MyAllocatePool__(NonPagedPool
, len
);
146 RegTCloseKeyHandle(hKey
);
151 RtlInitUnicodeString(&NameString
, Name
);
153 status
= ZwQueryValueKey(hKey
,
155 KeyValuePartialInformation
,
159 if(NT_SUCCESS(status
) &&
160 ValInfo
->DataLength
== sizeof(ULONG
)) {
161 RtlCopyMemory(pUlong
, ValInfo
->Data
, sizeof(ULONG
));
163 //KdPrint((" -> %x\n",*pUlong));
165 //KdPrint((" err %x\n",status));
168 MyFreePool__(ValInfo
);
171 if (ERROR_SUCCESS
== RegQueryValueExW(
172 hKey
, // handle of key to query
173 Name
, // address of name of value to query
175 NULL
, // address of buffer for value type
176 (BYTE
*)pUlong
, // address of data buffer
177 &len
// address of data buffer size
178 ) && len
== sizeof(ULONG
)) {
183 RegTCloseKeyHandle(hKey
);
186 } // end RegTGetDwordValue()
191 IN PCWSTR RegistryPath
,
198 UNICODE_STRING NameString
;
199 PKEY_VALUE_PARTIAL_INFORMATION ValInfo
;
204 BOOLEAN retval
= FALSE
;
205 BOOLEAN free_h
= FALSE
;
209 hRootKey
= HKEY_LOCAL_MACHINE
;
212 if(RegistryPath
&& RegistryPath
[0]) {
213 status
= RegTGetKeyHandle(hRootKey
, RegistryPath
, &hKey
);
215 if(status
!= ERROR_SUCCESS
)
217 if(!NT_SUCCESS(status
))
229 len
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + MaxLen
+ 0x20;
230 ValInfo
= (PKEY_VALUE_PARTIAL_INFORMATION
)
231 MyAllocatePool__(NonPagedPool
, len
);
234 RegTCloseKeyHandle(hKey
);
239 RtlInitUnicodeString(&NameString
, Name
);
241 status
= ZwQueryValueKey(hKey
,
243 KeyValuePartialInformation
,
247 if(NT_SUCCESS(status
) &&
248 ValInfo
->DataLength
) {
249 RtlCopyMemory(pStr
, ValInfo
->Data
, min(ValInfo
->DataLength
, MaxLen
) );
250 if(pStr
[(ValInfo
->DataLength
)/sizeof(WCHAR
)-1]) {
251 pStr
[(ValInfo
->DataLength
)/sizeof(WCHAR
)-1] = 0;
256 MyFreePool__(ValInfo
);
259 if (ERROR_SUCCESS
== RegQueryValueExW(
260 hKey
, // handle of key to query
261 Name
, // address of name of value to query
263 NULL
, // address of buffer for value type
264 (BYTE
*)pStr
, // address of data buffer
265 &len
// address of data buffer size
275 RegTCloseKeyHandle(hKey
);
278 } // end RegTGetStringValue()