Chromium Code Reviews| OLD | NEW |
|---|---|
| (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. | |
|
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
| |
| 4 | |
| 5 #ifndef CHROME_ELF_CHROME_ELF_REG_H_ | |
| 6 #define CHROME_ELF_CHROME_ELF_REG_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/strings/string16.h" | |
| 11 #include "sandbox/win/src/nt_internals.h" // NTSTATUS | |
| 12 | |
| 13 namespace nt { | |
| 14 | |
| 15 extern base::string16 HKLM_override; | |
| 16 extern base::string16 HKCU_override; | |
| 17 | |
| 18 // AUTO will choose depending on system install or not. | |
| 19 // Use HKLM or HKCU to override. | |
| 20 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.
| |
| 21 | |
| 22 // If you don't need the new handle left open, pass in nullptr. | |
| 23 // Also, will happily succeed if key already exists. | |
| 24 bool CreateRegKey(ROOT_KEY root, | |
| 25 const wchar_t* key_path, | |
| 26 ACCESS_MASK access, | |
| 27 HANDLE* out_handle OPTIONAL); | |
| 28 | |
| 29 // If key handle is passed in, caller must still call CloseRegKey | |
| 30 // after the delete. | |
| 31 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.
| |
| 32 bool DeleteRegKey(ROOT_KEY root, const wchar_t* key_path); | |
| 33 | |
| 34 // Caller must call CloseRegKey on returned handle (on success). | |
| 35 bool OpenRegKey(ROOT_KEY root, | |
| 36 const wchar_t* key_path, | |
| 37 ACCESS_MASK access, | |
| 38 HANDLE* out_handle, | |
| 39 NTSTATUS* error_code OPTIONAL); | |
| 40 | |
| 41 void CloseRegKey(HANDLE key); | |
| 42 | |
| 43 //------------------------------------------------------------------------------ | |
| 44 // Getter functions | |
| 45 //------------------------------------------------------------------------------ | |
| 46 | |
| 47 // Caller responsible for calling "delete[] *out_buffer". | |
| 48 // Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ. | |
| 49 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.
| |
| 50 const wchar_t* value_name, | |
| 51 ULONG* out_type, | |
| 52 BYTE** out_buffer, | |
| 53 DWORD* out_size); | |
| 54 | |
| 55 // If key handle is passed in, it will be left open. Otherwise, | |
| 56 // 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
| |
| 57 bool GetRegValue_DWORD(HANDLE key, const wchar_t* value_name, DWORD* out_dword); | |
| 58 bool GetRegValue_DWORD(ROOT_KEY root, | |
| 59 const wchar_t* key_path, | |
| 60 const wchar_t* value_name, | |
| 61 DWORD* out_dword); | |
| 62 | |
| 63 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.
| |
| 64 const wchar_t* value_name, | |
| 65 base::string16* out_sz); | |
| 66 bool GetRegValue_SZ(ROOT_KEY root, | |
| 67 const wchar_t* key_path, | |
| 68 const wchar_t* value_name, | |
| 69 base::string16* out_sz); | |
| 70 | |
| 71 bool GetRegValue_MULTI_SZ(HANDLE key, | |
| 72 const wchar_t* value_name, | |
| 73 std::vector<base::string16>* out_multi_sz); | |
| 74 bool GetRegValue_MULTI_SZ(ROOT_KEY root, | |
| 75 const wchar_t* key_path, | |
| 76 const wchar_t* value_name, | |
| 77 std::vector<base::string16>* out_multi_sz); | |
| 78 | |
| 79 //------------------------------------------------------------------------------ | |
| 80 // Setter functions | |
| 81 //------------------------------------------------------------------------------ | |
| 82 | |
| 83 // Types defined in winnt.h. E.g.: REG_DWORD, REG_SZ. | |
| 84 bool SetRegKeyValue(HANDLE key, | |
| 85 const wchar_t* value_name, | |
| 86 ULONG type, | |
| 87 BYTE* data, | |
| 88 DWORD data_size); | |
| 89 | |
| 90 // If key handle is passed in, it will be left open. Otherwise, | |
| 91 // the registry key will be opened, set, then closed. | |
| 92 bool SetRegValue_DWORD(HANDLE key, const wchar_t* value_name, DWORD value); | |
| 93 bool SetRegValue_DWORD(ROOT_KEY root, | |
| 94 const wchar_t* key_path, | |
| 95 const wchar_t* value_name, | |
| 96 DWORD value); | |
| 97 | |
| 98 // 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
| |
| 99 bool SetRegValue_SZ(HANDLE key, | |
| 100 const wchar_t* value_name, | |
| 101 base::string16* value); | |
| 102 bool SetRegValue_SZ(ROOT_KEY root, | |
| 103 const wchar_t* key_path, | |
| 104 const wchar_t* value_name, | |
| 105 base::string16* value); | |
| 106 | |
| 107 // Passing in pointer to vector for efficiency. | |
| 108 bool SetRegValue_MULTI_SZ(HANDLE key, | |
| 109 const wchar_t* value_name, | |
| 110 std::vector<base::string16>* values); | |
| 111 bool SetRegValue_MULTI_SZ(ROOT_KEY root, | |
| 112 const wchar_t* key_path, | |
| 113 const wchar_t* value_name, | |
| 114 std::vector<base::string16>* values); | |
| 115 | |
| 116 //------------------------------------------------------------------------------ | |
| 117 // Utils | |
| 118 //------------------------------------------------------------------------------ | |
| 119 | |
| 120 // Handy function to get the current user sid in string form. | |
| 121 // 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.
| |
| 122 base::string16 GetCurrentUserSidString(); | |
| 123 | |
| 124 }; // namespace nt | |
| 125 | |
| 126 #endif // CHROME_ELF_CHROME_ELF_REG_H_ | |
| OLD | NEW |