ReactOS 0.4.15-dev-5667-ged97270
regtools.cpp
Go to the documentation of this file.
1
2// Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3// All rights reserved
4// This file was released under the GPLv2 on June 2015.
6
7#include "regtools.h"
8
9#ifndef WIN_32_MODE
10
13 IN HKEY hRootKey,
16 )
17{
19 UNICODE_STRING NameString;
21
22 //UDFPrint(("RegTGetKeyHandle: h=%x, %S\n", hRootKey, KeyName));
23
24 RtlInitUnicodeString(&NameString, KeyName);
25
28 &NameString,
30 hRootKey,
31 NULL
32 );
33
34 status = ZwOpenKey(
35 hKey,
38 );
39
40 if(!NT_SUCCESS(status)) {
41 //UDFPrint((" status %x\n", status));
42 *hKey = NULL;
43 }
44
45 return status;
46} // end RegTGetKeyHandle()
47
48VOID
51)
52{
54} // end RegTCloseKeyHandle()
55
56#else //WIN_32_MODE
57
60 IN HKEY hRootKey,
63 )
64{
66
67 if(!hRootKey)
68 hRootKey = HKEY_LOCAL_MACHINE;
69
71 hRootKey,
72 KeyName,
73 0,
75 hKey
76 );
77
78 if(status != ERROR_SUCCESS) {
79 *hKey = NULL;
80 }
81
82 return status;
83} // end RegTGetKeyHandle()
84
85VOID
88)
89{
90 if(!hKey) {
91 return;
92 }
94} // end RegTCloseKeyHandle()
95
96#endif //WIN_32_MODE
97
100 IN HKEY hRootKey,
102 IN PCWSTR Name,
103 IN PULONG pUlong
104 )
105{
106#ifndef WIN_32_MODE
107 UNICODE_STRING NameString;
109#endif //WIN_32_MODE
110 ULONG len;
112 HKEY hKey;
113 BOOLEAN retval = FALSE;
114 BOOLEAN free_h = FALSE;
115
116#ifdef WIN_32_MODE
117 if(!hRootKey)
118 hRootKey = HKEY_LOCAL_MACHINE;
119#endif //WIN_32_MODE
120
121 if(RegistryPath && RegistryPath[0]) {
123#ifdef WIN_32_MODE
124 if(status != ERROR_SUCCESS)
125#else //WIN_32_MODE
126 if(!NT_SUCCESS(status))
127#endif //WIN_32_MODE
128 return FALSE;
129 free_h = TRUE;
130 } else {
131 hKey = hRootKey;
132 }
133 if(!hKey)
134 return FALSE;
135
136#ifndef WIN_32_MODE
137/*
138 UDFPrint(("h=%x|%S, %S (%x)\n",
139 hRootKey, RegistryPath, Name, *pUlong));
140*/
141 len = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG) + 0x20;
144 if(!ValInfo) {
145 if(free_h) {
147 }
148 return FALSE;
149 }
150
151 RtlInitUnicodeString(&NameString, Name);
152
153 status = ZwQueryValueKey(hKey,
154 &NameString,
156 ValInfo,
157 len,
158 &len);
159 if(NT_SUCCESS(status) &&
160 ValInfo->DataLength == sizeof(ULONG)) {
161 RtlCopyMemory(pUlong, ValInfo->Data, sizeof(ULONG));
162 retval = TRUE;
163 //UDFPrint((" -> %x\n",*pUlong));
164 } else {
165 //UDFPrint((" err %x\n",status));
166 }
167
168 MyFreePool__(ValInfo);
169#else //WIN_32_MODE
170 len = sizeof(ULONG);
172 hKey, // handle of key to query
173 Name, // address of name of value to query
174 0, // reserved
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)) {
179 retval = TRUE;
180 }
181#endif //WIN_32_MODE
182 if(free_h) {
184 }
185 return retval;
186} // end RegTGetDwordValue()
187
190 IN HKEY hRootKey,
192 IN PCWSTR Name,
193 IN PWCHAR pStr,
194 IN ULONG MaxLen
195 )
196{
197#ifndef WIN_32_MODE
198 UNICODE_STRING NameString;
200#endif //USER_MODE
201 ULONG len;
203 HKEY hKey;
204 BOOLEAN retval = FALSE;
205 BOOLEAN free_h = FALSE;
206
207#ifdef WIN_32_MODE
208 if(!hRootKey)
209 hRootKey = HKEY_LOCAL_MACHINE;
210#endif //WIN_32_MODE
211
212 if(RegistryPath && RegistryPath[0]) {
214#ifdef WIN_32_MODE
215 if(status != ERROR_SUCCESS)
216#else //WIN_32_MODE
217 if(!NT_SUCCESS(status))
218#endif //WIN_32_MODE
219 return FALSE;
220 free_h = TRUE;
221 } else {
222 hKey = hRootKey;
223 }
224 if(!hKey)
225 return FALSE;
226
227 pStr[0] = 0;
228#ifndef WIN_32_MODE
229 len = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + MaxLen + 0x20;
232 if(!ValInfo) {
233 if(free_h) {
235 }
236 return FALSE;
237 }
238
239 RtlInitUnicodeString(&NameString, Name);
240
241 status = ZwQueryValueKey(hKey,
242 &NameString,
244 ValInfo,
245 len,
246 &len);
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;
252 }
253 retval = TRUE;
254 }
255
256 MyFreePool__(ValInfo);
257#else //WIN_32_MODE
258 len = MaxLen;
260 hKey, // handle of key to query
261 Name, // address of name of value to query
262 0, // reserved
263 NULL, // address of buffer for value type
264 (BYTE *)pStr, // address of data buffer
265 &len // address of data buffer size
266 ) && len) {
267 if(pStr[len-1]) {
268 pStr[len-1] = 0;
269 }
270 retval = TRUE;
271 }
272#endif //WIN_32_MODE
273
274 if(free_h) {
276 }
277 return retval;
278} // end RegTGetStringValue()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define RegCloseKey(hKey)
Definition: registry.h:47
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
#define NonPagedPool
Definition: env_spec_w32.h:307
FxAutoRegKey hKey
GLenum GLsizei len
Definition: glext.h:6722
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define MyFreePool__(addr)
Definition: mem_tools.h:152
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define KEY_WRITE
Definition: nt_native.h:1031
long LONG
Definition: pedump.c:60
BOOLEAN RegTGetDwordValue(IN HKEY hRootKey, IN PCWSTR RegistryPath, IN PCWSTR Name, IN PULONG pUlong)
Definition: regtools.cpp:99
VOID RegTCloseKeyHandle(IN HKEY hKey)
Definition: regtools.cpp:86
NTSTATUS RegTGetKeyHandle(IN HKEY hRootKey, IN PWCHAR KeyName, OUT HKEY *hKey)
Definition: regtools.cpp:59
BOOLEAN RegTGetStringValue(IN HKEY hRootKey, IN PCWSTR RegistryPath, IN PCWSTR Name, IN PWCHAR pStr, IN ULONG MaxLen)
Definition: regtools.cpp:189
Definition: ps.c:97
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193