OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/policy/core/common/preg_parser_win.h" | 5 #include "components/policy/core/common/preg_parser_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 std::string DecodePRegStringValue(const std::vector<uint8>& data) { | 101 std::string DecodePRegStringValue(const std::vector<uint8>& data) { |
102 size_t len = data.size() / sizeof(char16); | 102 size_t len = data.size() / sizeof(char16); |
103 if (len <= 0) | 103 if (len <= 0) |
104 return std::string(); | 104 return std::string(); |
105 | 105 |
106 const char16* chars = reinterpret_cast<const char16*>(vector_as_array(&data)); | 106 const char16* chars = reinterpret_cast<const char16*>(vector_as_array(&data)); |
107 base::string16 result; | 107 base::string16 result; |
108 std::transform(chars, chars + len - 1, std::back_inserter(result), | 108 std::transform(chars, chars + len - 1, std::back_inserter(result), |
109 std::ptr_fun(base::ByteSwapToLE16)); | 109 std::ptr_fun(base::ByteSwapToLE16)); |
110 return UTF16ToUTF8(result); | 110 return base::UTF16ToUTF8(result); |
111 } | 111 } |
112 | 112 |
113 // Decodes a value from a PReg file given as a uint8 vector. | 113 // Decodes a value from a PReg file given as a uint8 vector. |
114 bool DecodePRegValue(uint32 type, | 114 bool DecodePRegValue(uint32 type, |
115 const std::vector<uint8>& data, | 115 const std::vector<uint8>& data, |
116 scoped_ptr<base::Value>* value) { | 116 scoped_ptr<base::Value>* value) { |
117 switch (type) { | 117 switch (type) { |
118 case REG_SZ: | 118 case REG_SZ: |
119 case REG_EXPAND_SZ: | 119 case REG_EXPAND_SZ: |
120 value->reset(base::Value::CreateStringValue(DecodePRegStringValue(data))); | 120 value->reset(base::Value::CreateStringValue(DecodePRegStringValue(data))); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 const std::vector<uint8>& data, | 155 const std::vector<uint8>& data, |
156 RegistryDict* dict) { | 156 RegistryDict* dict) { |
157 // Locate/create the dictionary to place the value in. | 157 // Locate/create the dictionary to place the value in. |
158 std::vector<base::string16> path; | 158 std::vector<base::string16> path; |
159 | 159 |
160 Tokenize(key_name, kRegistryPathSeparator, &path); | 160 Tokenize(key_name, kRegistryPathSeparator, &path); |
161 for (std::vector<base::string16>::const_iterator entry(path.begin()); | 161 for (std::vector<base::string16>::const_iterator entry(path.begin()); |
162 entry != path.end(); ++entry) { | 162 entry != path.end(); ++entry) { |
163 if (entry->empty()) | 163 if (entry->empty()) |
164 continue; | 164 continue; |
165 const std::string name = UTF16ToUTF8(*entry); | 165 const std::string name = base::UTF16ToUTF8(*entry); |
166 RegistryDict* subdict = dict->GetKey(name); | 166 RegistryDict* subdict = dict->GetKey(name); |
167 if (!subdict) { | 167 if (!subdict) { |
168 subdict = new RegistryDict(); | 168 subdict = new RegistryDict(); |
169 dict->SetKey(name, make_scoped_ptr(subdict)); | 169 dict->SetKey(name, make_scoped_ptr(subdict)); |
170 } | 170 } |
171 dict = subdict; | 171 dict = subdict; |
172 } | 172 } |
173 | 173 |
174 if (value.empty()) | 174 if (value.empty()) |
175 return; | 175 return; |
176 | 176 |
177 std::string value_name(UTF16ToUTF8(value)); | 177 std::string value_name(base::UTF16ToUTF8(value)); |
178 if (!StartsWithASCII(value_name, kActionTriggerPrefix, true)) { | 178 if (!StartsWithASCII(value_name, kActionTriggerPrefix, true)) { |
179 scoped_ptr<base::Value> value; | 179 scoped_ptr<base::Value> value; |
180 if (DecodePRegValue(type, data, &value)) | 180 if (DecodePRegValue(type, data, &value)) |
181 dict->SetValue(value_name, value.Pass()); | 181 dict->SetValue(value_name, value.Pass()); |
182 return; | 182 return; |
183 } | 183 } |
184 | 184 |
185 std::string action_trigger(StringToLowerASCII(value_name.substr( | 185 std::string action_trigger(StringToLowerASCII(value_name.substr( |
186 arraysize(kActionTriggerPrefix) - 1))); | 186 arraysize(kActionTriggerPrefix) - 1))); |
187 if (action_trigger == kActionTriggerDeleteValues) { | 187 if (action_trigger == kActionTriggerDeleteValues) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 299 } |
300 | 300 |
301 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " | 301 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " |
302 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); | 302 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); |
303 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 303 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
304 return false; | 304 return false; |
305 } | 305 } |
306 | 306 |
307 } // namespace preg_parser | 307 } // namespace preg_parser |
308 } // namespace policy | 308 } // namespace policy |
OLD | NEW |