Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Side by Side Diff: chrome_elf/nt_registry/nt_registry.h

Issue 1841573002: [Chrome ELF] New NT registry API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: PRESUBMIT to allow chrome_elf directory files to use wstring. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome_elf/nt_registry/DEPS ('k') | chrome_elf/nt_registry/nt_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This API is a usability layer for direct registry access via NTDLL.
6 // It allows for "advapi32-free" registry access, which is especially
7 // useful for accessing registy from DllMain (holding loader lock),
8 // or if a dependency on/linkage of ADVAPI32.dll is not desired.
9
10 // The implementation of this API should only use ntdll and kernel32 system
11 // DLLs.
12
13 // Note that this API is currently lazy initialized. Any function that is
14 // NOT merely a wrapper function (i.e. any function that directly interacts with
15 // NTDLL) will immediately check:
16 // if (!g_initialized)
17 // InitNativeRegApi();
18 // There is currently no multi-threading lock around the lazy initialization,
19 // as the main client for this API (chrome_elf) does not introduce
20 // a multi-threading concern. This can easily be changed if needed.
21
22 #ifndef CHROME_ELF_NT_REGISTRY_NT_REGISTRY_H_
23 #define CHROME_ELF_NT_REGISTRY_NT_REGISTRY_H_
24
25 #include <vector>
26
27 #include "sandbox/win/src/nt_internals.h" // NTSTATUS
28
29 namespace nt {
30
31 // These globals are only used in test suites that use reg redirection
32 // of HKLM and/or HKCU.
33 extern const size_t g_kRegMaxPathLen;
34 extern wchar_t HKLM_override[];
35 extern wchar_t HKCU_override[];
36
37 // AUTO will choose depending on system install or not.
38 // Use HKLM or HKCU to override.
39 typedef enum _ROOT_KEY { AUTO = 0, HKLM, HKCU } ROOT_KEY;
40
41 // Create and/or open a registry key.
42 // - This function will recursively create multiple sub-keys if required for
43 // |key_path|.
44 // - If the key doesn't need to be left open, pass in nullptr for |out_handle|.
45 // - This function will happily succeed if the key already exists.
46 // - Optional |out_handle|. If nullptr, function will close handle when done.
47 // Otherwise, will hold the open handle to the deepest subkey.
48 // - Caller must call CloseRegKey on returned handle (on success).
49 bool CreateRegKey(ROOT_KEY root,
50 const wchar_t* key_path,
51 ACCESS_MASK access,
52 HANDLE* out_handle OPTIONAL);
53
54 // Open existing registry key.
55 // - Caller must call CloseRegKey on returned handle (on success).
56 // - Optional error code can be returned on failure for extra detail.
57 bool OpenRegKey(ROOT_KEY root,
58 const wchar_t* key_path,
59 ACCESS_MASK access,
60 HANDLE* out_handle,
61 NTSTATUS* error_code OPTIONAL);
62
63 // Delete a registry key.
64 // - Caller must still call CloseRegKey after the delete.
65 bool DeleteRegKey(HANDLE key);
66
67 // Delete a registry key.
68 // - WRAPPER: Function opens and closes the target key for caller.
69 bool DeleteRegKey(ROOT_KEY root, const wchar_t* key_path);
70
71 // Close a registry key handle that was opened with CreateRegKey or OpenRegKey.
72 void CloseRegKey(HANDLE key);
73
74 //------------------------------------------------------------------------------
75 // Getter functions
76 //------------------------------------------------------------------------------
77
78 // Main function to query a registry value.
79 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
80 // - Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ.
81 // - Caller is responsible for calling "delete[] *out_buffer" (on success).
82 bool QueryRegKeyValue(HANDLE key,
83 const wchar_t* value_name,
84 ULONG* out_type,
85 BYTE** out_buffer,
86 DWORD* out_size);
87
88 // Query DWORD value.
89 // - WRAPPER: Function works with DWORD data type.
90 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
91 // - Handle will be left open. Caller must still call CloseRegKey when done.
92 bool QueryRegValueDWORD(HANDLE key,
93 const wchar_t* value_name,
94 DWORD* out_dword);
95
96 // Query DWORD value.
97 // - WRAPPER: Function opens and closes the target key for caller, and works
98 // with DWORD data type.
99 bool QueryRegValueDWORD(ROOT_KEY root,
100 const wchar_t* key_path,
101 const wchar_t* value_name,
102 DWORD* out_dword);
103
104 // Query SZ (string) value.
105 // - WRAPPER: Function works with SZ data type.
106 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
107 // - Handle will be left open. Caller must still call CloseRegKey when done.
108 bool QueryRegValueSZ(HANDLE key,
109 const wchar_t* value_name,
110 std::wstring* out_sz);
111
112 // Query SZ (string) value.
113 // - WRAPPER: Function opens and closes the target key for caller, and works
114 // with SZ data type.
115 bool QueryRegValueSZ(ROOT_KEY root,
116 const wchar_t* key_path,
117 const wchar_t* value_name,
118 std::wstring* out_sz);
119
120 // Query MULTI_SZ (multiple strings) value.
121 // - WRAPPER: Function works with MULTI_SZ data type.
122 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
123 // - Handle will be left open. Caller must still call CloseRegKey when done.
124 bool QueryRegValueMULTISZ(HANDLE key,
125 const wchar_t* value_name,
126 std::vector<std::wstring>* out_multi_sz);
127
128 // Query MULTI_SZ (multiple strings) value.
129 // - WRAPPER: Function opens and closes the target key for caller, and works
130 // with MULTI_SZ data type.
131 bool QueryRegValueMULTISZ(ROOT_KEY root,
132 const wchar_t* key_path,
133 const wchar_t* value_name,
134 std::vector<std::wstring>* out_multi_sz);
135
136 //------------------------------------------------------------------------------
137 // Setter functions
138 //------------------------------------------------------------------------------
139
140 // Main function to set a registry value.
141 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
142 // - Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ.
143 bool SetRegKeyValue(HANDLE key,
144 const wchar_t* value_name,
145 ULONG type,
146 const BYTE* data,
147 DWORD data_size);
148
149 // Set DWORD value.
150 // - WRAPPER: Function works with DWORD data type.
151 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
152 // - Handle will be left open. Caller must still call CloseRegKey when done.
153 bool SetRegValueDWORD(HANDLE key, const wchar_t* value_name, DWORD value);
154
155 // Set DWORD value.
156 // - WRAPPER: Function opens and closes the target key for caller, and works
157 // with DWORD data type.
158 bool SetRegValueDWORD(ROOT_KEY root,
159 const wchar_t* key_path,
160 const wchar_t* value_name,
161 DWORD value);
162
163 // Set SZ (string) value.
164 // - WRAPPER: Function works with SZ data type.
165 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
166 // - Handle will be left open. Caller must still call CloseRegKey when done.
167 bool SetRegValueSZ(HANDLE key,
168 const wchar_t* value_name,
169 const std::wstring& value);
170
171 // Set SZ (string) value.
172 // - WRAPPER: Function opens and closes the target key for caller, and works
173 // with SZ data type.
174 bool SetRegValueSZ(ROOT_KEY root,
175 const wchar_t* key_path,
176 const wchar_t* value_name,
177 const std::wstring& value);
178
179 // Set MULTI_SZ (multiple strings) value.
180 // - WRAPPER: Function works with MULTI_SZ data type.
181 // - Key handle should have been opened with CreateRegKey or OpenRegKey.
182 // - Handle will be left open. Caller must still call CloseRegKey when done.
183 bool SetRegValueMULTISZ(HANDLE key,
184 const wchar_t* value_name,
185 const std::vector<std::wstring>& values);
186
187 // Set MULTI_SZ (multiple strings) value.
188 // - WRAPPER: Function opens and closes the target key for caller, and works
189 // with MULTI_SZ data type.
190 bool SetRegValueMULTISZ(ROOT_KEY root,
191 const wchar_t* key_path,
192 const wchar_t* value_name,
193 const std::vector<std::wstring>& values);
194
195 //------------------------------------------------------------------------------
196 // Utils
197 //------------------------------------------------------------------------------
198
199 // Returns the current user SID in string form.
200 const wchar_t* GetCurrentUserSidString();
201
202 }; // namespace nt
203
204 #endif // CHROME_ELF_NT_REGISTRY_NT_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome_elf/nt_registry/DEPS ('k') | chrome_elf/nt_registry/nt_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698