| 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 15 matching lines...) Expand all Loading... |
| 26 namespace policy { | 26 namespace policy { |
| 27 namespace preg_parser { | 27 namespace preg_parser { |
| 28 | 28 |
| 29 const char kPRegFileHeader[8] = | 29 const char kPRegFileHeader[8] = |
| 30 { 'P', 'R', 'e', 'g', '\x01', '\x00', '\x00', '\x00' }; | 30 { 'P', 'R', 'e', 'g', '\x01', '\x00', '\x00', '\x00' }; |
| 31 | 31 |
| 32 // Maximum PReg file size we're willing to accept. | 32 // Maximum PReg file size we're willing to accept. |
| 33 const int64 kMaxPRegFileSize = 1024 * 1024 * 16; | 33 const int64 kMaxPRegFileSize = 1024 * 1024 * 16; |
| 34 | 34 |
| 35 // Constants for PReg file delimiters. | 35 // Constants for PReg file delimiters. |
| 36 const char16 kDelimBracketOpen = L'['; | 36 const base::char16 kDelimBracketOpen = L'['; |
| 37 const char16 kDelimBracketClose = L']'; | 37 const base::char16 kDelimBracketClose = L']'; |
| 38 const char16 kDelimSemicolon = L';'; | 38 const base::char16 kDelimSemicolon = L';'; |
| 39 | 39 |
| 40 // Registry path separator. | 40 // Registry path separator. |
| 41 const char16 kRegistryPathSeparator[] = L"\\"; | 41 const base::char16 kRegistryPathSeparator[] = L"\\"; |
| 42 | 42 |
| 43 // Magic strings for the PReg value field to trigger special actions. | 43 // Magic strings for the PReg value field to trigger special actions. |
| 44 const char kActionTriggerPrefix[] = "**"; | 44 const char kActionTriggerPrefix[] = "**"; |
| 45 const char kActionTriggerDeleteValues[] = "deletevalues"; | 45 const char kActionTriggerDeleteValues[] = "deletevalues"; |
| 46 const char kActionTriggerDel[] = "del."; | 46 const char kActionTriggerDel[] = "del."; |
| 47 const char kActionTriggerDelVals[] = "delvals"; | 47 const char kActionTriggerDelVals[] = "delvals"; |
| 48 const char kActionTriggerDeleteKeys[] = "deletekeys"; | 48 const char kActionTriggerDeleteKeys[] = "deletekeys"; |
| 49 const char kActionTriggerSecureKey[] = "securekey"; | 49 const char kActionTriggerSecureKey[] = "securekey"; |
| 50 const char kActionTriggerSoft[] = "soft"; | 50 const char kActionTriggerSoft[] = "soft"; |
| 51 | 51 |
| 52 // Returns the character at |cursor| and increments it, unless the end is here | 52 // Returns the character at |cursor| and increments it, unless the end is here |
| 53 // in which case -1 is returned. | 53 // in which case -1 is returned. |
| 54 int NextChar(const uint8** cursor, const uint8* end) { | 54 int NextChar(const uint8** cursor, const uint8* end) { |
| 55 // Only read the character if a full char16 is available. | 55 // Only read the character if a full base::char16 is available. |
| 56 if (*cursor + sizeof(char16) > end) | 56 if (*cursor + sizeof(base::char16) > end) |
| 57 return -1; | 57 return -1; |
| 58 | 58 |
| 59 int result = **cursor | (*(*cursor + 1) << 8); | 59 int result = **cursor | (*(*cursor + 1) << 8); |
| 60 *cursor += sizeof(char16); | 60 *cursor += sizeof(base::char16); |
| 61 return result; | 61 return result; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Reads a fixed-size field from a PReg file. | 64 // Reads a fixed-size field from a PReg file. |
| 65 bool ReadFieldBinary(const uint8** cursor, | 65 bool ReadFieldBinary(const uint8** cursor, |
| 66 const uint8* end, | 66 const uint8* end, |
| 67 uint32 size, | 67 uint32 size, |
| 68 uint8* data) { | 68 uint8* data) { |
| 69 if (size == 0) | 69 if (size == 0) |
| 70 return true; | 70 return true; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 const uint8* end, | 92 const uint8* end, |
| 93 base::string16* str) { | 93 base::string16* str) { |
| 94 int current = -1; | 94 int current = -1; |
| 95 while ((current = NextChar(cursor, end)) > 0x0000) | 95 while ((current = NextChar(cursor, end)) > 0x0000) |
| 96 *str += current; | 96 *str += current; |
| 97 | 97 |
| 98 return current == L'\0'; | 98 return current == L'\0'; |
| 99 } | 99 } |
| 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(base::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 base::char16* chars = |
| 107 reinterpret_cast<const base::char16*>(vector_as_array(&data)); |
| 107 base::string16 result; | 108 base::string16 result; |
| 108 std::transform(chars, chars + len - 1, std::back_inserter(result), | 109 std::transform(chars, chars + len - 1, std::back_inserter(result), |
| 109 std::ptr_fun(base::ByteSwapToLE16)); | 110 std::ptr_fun(base::ByteSwapToLE16)); |
| 110 return base::UTF16ToUTF8(result); | 111 return base::UTF16ToUTF8(result); |
| 111 } | 112 } |
| 112 | 113 |
| 113 // Decodes a value from a PReg file given as a uint8 vector. | 114 // Decodes a value from a PReg file given as a uint8 vector. |
| 114 bool DecodePRegValue(uint32 type, | 115 bool DecodePRegValue(uint32 type, |
| 115 const std::vector<uint8>& data, | 116 const std::vector<uint8>& data, |
| 116 scoped_ptr<base::Value>* value) { | 117 scoped_ptr<base::Value>* value) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 300 } |
| 300 | 301 |
| 301 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " | 302 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " |
| 302 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); | 303 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); |
| 303 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 304 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 304 return false; | 305 return false; |
| 305 } | 306 } |
| 306 | 307 |
| 307 } // namespace preg_parser | 308 } // namespace preg_parser |
| 308 } // namespace policy | 309 } // namespace policy |
| OLD | NEW |