Index: chrome_elf/chrome_elf_reg.h |
diff --git a/chrome_elf/chrome_elf_reg.h b/chrome_elf/chrome_elf_reg.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e51818f71bf42f7b564ccf5f099a81c689a42c25 |
--- /dev/null |
+++ b/chrome_elf/chrome_elf_reg.h |
@@ -0,0 +1,126 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
robertshield
2016/04/20 16:55:53
Suggest having at the top of this file some explan
penny
2016/05/28 01:34:23
Done. Comments about HANDLEs have been added to t
|
+ |
+#ifndef CHROME_ELF_CHROME_ELF_REG_H_ |
+#define CHROME_ELF_CHROME_ELF_REG_H_ |
+ |
+#include <vector> |
+ |
+#include "base/strings/string16.h" |
+#include "sandbox/win/src/nt_internals.h" // NTSTATUS |
+ |
+namespace nt { |
+ |
+extern base::string16 HKLM_override; |
+extern base::string16 HKCU_override; |
+ |
+// AUTO will choose depending on system install or not. |
+// Use HKLM or HKCU to override. |
+typedef enum _ROOT_KEY { AUTO = 0, HKLM, HKCU } ROOT_KEY, *PROOT_KEY; |
robertshield
2016/04/20 16:55:53
We don't usually explicitly typedef for a pointer-
penny
2016/05/28 01:34:23
Done. I just always do that as an old habit.
|
+ |
+// If you don't need the new handle left open, pass in nullptr. |
+// Also, will happily succeed if key already exists. |
+bool CreateRegKey(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ ACCESS_MASK access, |
+ HANDLE* out_handle OPTIONAL); |
+ |
+// If key handle is passed in, caller must still call CloseRegKey |
+// after the delete. |
+bool DeleteRegKey(HANDLE key); |
robertshield
2016/04/20 16:55:53
please add separate comments for each function.
penny
2016/05/28 01:34:23
Done.
|
+bool DeleteRegKey(ROOT_KEY root, const wchar_t* key_path); |
+ |
+// Caller must call CloseRegKey on returned handle (on success). |
+bool OpenRegKey(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ ACCESS_MASK access, |
+ HANDLE* out_handle, |
+ NTSTATUS* error_code OPTIONAL); |
+ |
+void CloseRegKey(HANDLE key); |
+ |
+//------------------------------------------------------------------------------ |
+// Getter functions |
+//------------------------------------------------------------------------------ |
+ |
+// Caller responsible for calling "delete[] *out_buffer". |
+// Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ. |
+bool QueryRegKeyValue(HANDLE key, |
robertshield
2016/04/20 16:55:53
For all of the functions in this file that take a
robertshield
2016/04/20 16:55:53
Why is this function called QueryXXX when the othe
penny
2016/05/28 01:34:23
Done.
penny
2016/05/28 01:34:23
Done. I've changed to always use "Query". This m
penny
2016/05/28 01:34:23
Done.
|
+ const wchar_t* value_name, |
+ ULONG* out_type, |
+ BYTE** out_buffer, |
+ DWORD* out_size); |
+ |
+// If key handle is passed in, it will be left open. Otherwise, |
+// the registry key will be opened, queried, then closed. |
robertshield
2016/04/20 16:55:53
Please attach comments to the individual functions
penny
2016/05/28 01:34:23
Done. I always use "git cl format" before uploadi
|
+bool GetRegValue_DWORD(HANDLE key, const wchar_t* value_name, DWORD* out_dword); |
+bool GetRegValue_DWORD(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ DWORD* out_dword); |
+ |
+bool GetRegValue_SZ(HANDLE key, |
robertshield
2016/04/20 15:45:47
Minor style nit: base's registry functions are nam
penny
2016/05/28 01:34:23
Done.
|
+ const wchar_t* value_name, |
+ base::string16* out_sz); |
+bool GetRegValue_SZ(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ base::string16* out_sz); |
+ |
+bool GetRegValue_MULTI_SZ(HANDLE key, |
+ const wchar_t* value_name, |
+ std::vector<base::string16>* out_multi_sz); |
+bool GetRegValue_MULTI_SZ(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ std::vector<base::string16>* out_multi_sz); |
+ |
+//------------------------------------------------------------------------------ |
+// Setter functions |
+//------------------------------------------------------------------------------ |
+ |
+// Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ. |
+bool SetRegKeyValue(HANDLE key, |
+ const wchar_t* value_name, |
+ ULONG type, |
+ BYTE* data, |
+ DWORD data_size); |
+ |
+// If key handle is passed in, it will be left open. Otherwise, |
+// the registry key will be opened, set, then closed. |
+bool SetRegValue_DWORD(HANDLE key, const wchar_t* value_name, DWORD value); |
+bool SetRegValue_DWORD(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ DWORD value); |
+ |
+// Passing in pointer to string for efficiency. |
robertshield
2016/04/20 16:55:53
Use const ref instead of pointer here and everywhe
penny
2016/05/28 01:34:23
Done. I think done. I'm new to the strange '&' r
|
+bool SetRegValue_SZ(HANDLE key, |
+ const wchar_t* value_name, |
+ base::string16* value); |
+bool SetRegValue_SZ(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ base::string16* value); |
+ |
+// Passing in pointer to vector for efficiency. |
+bool SetRegValue_MULTI_SZ(HANDLE key, |
+ const wchar_t* value_name, |
+ std::vector<base::string16>* values); |
+bool SetRegValue_MULTI_SZ(ROOT_KEY root, |
+ const wchar_t* key_path, |
+ const wchar_t* value_name, |
+ std::vector<base::string16>* values); |
+ |
+//------------------------------------------------------------------------------ |
+// Utils |
+//------------------------------------------------------------------------------ |
+ |
+// Handy function to get the current user sid in string form. |
+// Does NOT use advapi32, only ntdll. |
robertshield
2016/04/20 16:55:53
Suggest:
Returns the current user SID in string f
penny
2016/05/28 01:34:23
Done.
|
+base::string16 GetCurrentUserSidString(); |
+ |
+}; // namespace nt |
+ |
+#endif // CHROME_ELF_CHROME_ELF_REG_H_ |