manage_metadata.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _MANAGE_METADATA_H_
  32. #define _MANAGE_METADATA_H_
  33. #include "metadata.h"
  34. #include "uncopyable.h"
  35. #include "loader.h"
  36. #include "binparser.h"
  37. #define MAX_BUFFER_SIZE 4096
  38. #define TCS_TEMPLATE_SIZE 72
  39. #define STRCMP strcmp
  40. #define STRNCMP strncmp
  41. #define SSA_NUM 2
  42. #define SSA_FRAME_SIZE 1
  43. typedef enum _para_type_t
  44. {
  45. PRODID = 0,
  46. ISVSVN,
  47. RELEASETYPE,
  48. INTELSIGNED,
  49. PROVISIONKEY,
  50. LAUNCHKEY,
  51. DISABLEDEBUG,
  52. HW,
  53. TCSNUM,
  54. TCSPOLICY,
  55. STACKMAXSIZE,
  56. HEAPMAXSIZE,
  57. MISCSELECT,
  58. MISCMASK
  59. } para_type_t;
  60. typedef struct _xml_parameter_t
  61. {
  62. const char* name; //the element name
  63. uint64_t max_value;
  64. uint64_t min_value;
  65. uint64_t value; //parameter value. Initialized with the default value.
  66. uint32_t flag; //Show whether it has been matched
  67. } xml_parameter_t;
  68. bool parse_metadata_file(const char *xmlpath, xml_parameter_t *parameter, int parameter_count);
  69. bool update_metadata(const char *path, const metadata_t *metadata, uint64_t meta_offset);
  70. class CMetadata: private Uncopyable
  71. {
  72. public:
  73. CMetadata(metadata_t *metadata, BinParser *parser);
  74. ~CMetadata();
  75. bool build_metadata(const xml_parameter_t *parameter);
  76. private:
  77. bool modify_metadata(const xml_parameter_t *parameter);
  78. void *alloc_buffer_from_metadata(uint32_t size);
  79. bool build_layout_table();
  80. bool build_patch_table();
  81. bool build_layout_entries(vector<layout_t> &layouts);
  82. bool build_patch_entries(vector<patch_entry_t> &patches);
  83. layout_entry_t *get_entry_by_id(uint16_t id);
  84. bool build_tcs_template(tcs_t *tcs);
  85. bool build_gd_template(uint8_t *data, uint32_t *data_size);
  86. uint64_t calculate_sections_size();
  87. uint64_t calculate_enclave_size(uint64_t size);
  88. void* get_rawdata_by_rva(uint64_t rva);
  89. metadata_t *m_metadata;
  90. BinParser *m_parser;
  91. create_param_t m_create_param;
  92. };
  93. #endif