OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 | 5 |
6 #ifndef VBOOT_REFERENCE_GBB_UTILITY_H_ | 6 #ifndef VBOOT_REFERENCE_GBB_UTILITY_H_ |
7 #define VBOOT_REFERENCE_GBB_UTILITY_H_ | 7 #define VBOOT_REFERENCE_GBB_UTILITY_H_ |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include "gbb_header.h" | 10 #include "gbb_header.h" |
11 | 11 |
12 namespace vboot_reference { | 12 namespace vboot_reference { |
13 | 13 |
14 class GoogleBinaryBlockUtil { | 14 class GoogleBinaryBlockUtil { |
15 public: | 15 public: |
| 16 // enumerate of available data fields |
| 17 enum PROPINDEX { |
| 18 PROP_HWID, // hardware id |
| 19 PROP_ROOTKEY, // root key |
| 20 PROP_BMPFV, // bitmap FV |
| 21 PROP_RANGE, // indicator of valid property range |
| 22 }; |
| 23 |
16 GoogleBinaryBlockUtil(); | 24 GoogleBinaryBlockUtil(); |
17 ~GoogleBinaryBlockUtil(); | 25 ~GoogleBinaryBlockUtil(); |
18 | 26 |
19 // load GBB from a BIOS image file. | 27 // load GBB from a BIOS image file. |
20 // return true if a valid GBB was retrieved. | 28 // return true if a valid GBB was retrieved. |
21 bool load_from_file(const char *filename); | 29 bool load_from_file(const char *filename); |
22 | 30 |
23 // save loaded (and modified) GBB with BIOS image to new file | 31 // save loaded (and modified) GBB with BIOS image to new file |
24 // return true on success. | 32 // return true on success. |
25 bool save_to_file(const char *filename); | 33 bool save_to_file(const char *filename); |
26 | 34 |
27 // getters and setters of properties in GBB | 35 // retrieve the value of a property from GBB data. |
28 bool set_hwid(const char *hwid); // hwid is NUL-terminated. | 36 // return the property value. |
| 37 std::string get_property(PROPINDEX i) const; |
| 38 |
| 39 // overwrite a property in GBB data. |
| 40 // return true on success. |
| 41 bool set_property(PROPINDEX i, const std::string &value); |
| 42 |
| 43 // get a readable name by a property index. |
| 44 // return the name for valid properties, otherwise unexpected empty string. |
| 45 std::string get_property_name(PROPINDEX i) const; |
| 46 |
| 47 // quick getters and setters of known properties in GBB |
| 48 bool set_hwid(const char *hwid); // NOTE: hwid is NUL-terminated. |
29 bool set_rootkey(const std::string &value); | 49 bool set_rootkey(const std::string &value); |
30 bool set_bmpfv(const std::string &value); | 50 bool set_bmpfv(const std::string &value); |
31 std::string get_hwid() const { return get_property(PROP_HWID); } | 51 std::string get_hwid() const { return get_property(PROP_HWID); } |
32 std::string get_rootkey() const { return get_property(PROP_ROOTKEY); } | 52 std::string get_rootkey() const { return get_property(PROP_ROOTKEY); } |
33 std::string get_bmpfv() const { return get_property(PROP_BMPFV); } | 53 std::string get_bmpfv() const { return get_property(PROP_BMPFV); } |
34 | 54 |
35 private: | 55 private: |
36 // enumerate of available data fields | |
37 enum PROPINDEX { | |
38 PROP_HWID, // hardware id | |
39 PROP_ROOTKEY, // root key | |
40 PROP_BMPFV, // bitmap FV | |
41 }; | |
42 | |
43 // clear all cached data and initialize to original state | 56 // clear all cached data and initialize to original state |
44 void initialize(); | 57 void initialize(); |
45 | 58 |
46 // search and count for GBB signatures in loaded image. | 59 // search and count for GBB signatures in loaded image. |
47 // return the number of signatures found. | 60 // return the number of signatures found. |
48 int search_header_signatures(const std::string &image, long *poffset) const; | 61 int search_header_signatures(const std::string &image, long *poffset) const; |
49 | 62 |
50 // load and check header structure from image by given offset. | 63 // load and check header structure from image by given offset. |
51 // return true if a valid GBB header is loaded into *phdr. | 64 // return true if a valid GBB header is loaded into *phdr. |
52 bool load_gbb_header(const std::string &image, long offset, | 65 bool load_gbb_header(const std::string &image, long offset, |
53 GoogleBinaryBlockHeader *phdr) const; | 66 GoogleBinaryBlockHeader *phdr) const; |
54 | 67 |
55 // retrieve a property from GBB data. | 68 // find the size, offset, and name information for given property. |
56 // return the property value. | 69 // return true if the offset and size are assign to *poffset and *psize; |
57 std::string get_property(PROPINDEX i) const; | 70 // if pname is not NULL, *pname will hold a pointer to a readable name. |
58 | 71 // return false if the property index is invalid. |
59 // overwrite a property in GBB data. | 72 bool find_property(PROPINDEX i, uint32_t *poffset, uint32_t *psize, |
60 // return true on success. | 73 const char **pname) const; |
61 bool set_property(PROPINDEX i, const std::string &value); | |
62 | |
63 // find the size and offset information for given property | |
64 // return true if the offset and size are assign to *poffset and *psize. | |
65 bool find_property(PROPINDEX i, uint32_t *poffset, uint32_t *psize) const; | |
66 | 74 |
67 GoogleBinaryBlockHeader header_; // copy of GBB header from image | 75 GoogleBinaryBlockHeader header_; // copy of GBB header from image |
68 std::string file_content_; // complete image file content | 76 std::string file_content_; // complete image file content |
69 long header_offset_; // offset to GBB header in file_content_ | 77 long header_offset_; // offset to GBB header in file_content_ |
70 bool is_valid_gbb; // if we are holding a valid GBB | 78 bool is_valid_gbb; // if we are holding a valid GBB |
71 | 79 |
72 bool verbose; // provide verbose messages | 80 bool verbose; // provide verbose messages |
73 }; | 81 }; |
74 | 82 |
75 } // namespace vboot_reference | 83 } // namespace vboot_reference |
76 | 84 |
77 #endif // VBOOT_REFERENCE_GBB_UTILITY_H_ | 85 #endif // VBOOT_REFERENCE_GBB_UTILITY_H_ |
78 | 86 |
OLD | NEW |