manage_metadata.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2011-2018 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 STRCMP strcmp
  39. #define STRNCMP strncmp
  40. #define SSA_NUM 2
  41. #define SSA_FRAME_SIZE 1
  42. typedef enum _para_type_t
  43. {
  44. PRODID = 0,
  45. ISVSVN,
  46. RELEASETYPE,
  47. INTELSIGNED,
  48. PROVISIONKEY,
  49. LAUNCHKEY,
  50. DISABLEDEBUG,
  51. HW,
  52. TCSNUM,
  53. TCSMAXNUM,
  54. TCSMINPOOL,
  55. TCSPOLICY,
  56. STACKMAXSIZE,
  57. STACKMINSIZE,
  58. HEAPMAXSIZE,
  59. HEAPMINSIZE,
  60. HEAPINITSIZE,
  61. MISCSELECT,
  62. MISCMASK
  63. } para_type_t;
  64. typedef struct _xml_parameter_t
  65. {
  66. const char* name; //the element name
  67. uint64_t max_value;
  68. uint64_t min_value;
  69. uint64_t value; //parameter value. Initialized with the default value.
  70. uint32_t flag; //Show whether it has been matched
  71. } xml_parameter_t;
  72. bool parse_metadata_file(const char *xmlpath, xml_parameter_t *parameter, int parameter_count);
  73. bool update_metadata(const char *path, const metadata_t *metadata, uint64_t meta_offset);
  74. bool print_metadata(const char *path, const metadata_t *metadata);
  75. class CMetadata: private Uncopyable
  76. {
  77. public:
  78. CMetadata(metadata_t *metadata, BinParser *parser);
  79. ~CMetadata();
  80. bool build_metadata(const xml_parameter_t *parameter);
  81. private:
  82. bool get_time(uint32_t *date);
  83. bool modify_metadata(const xml_parameter_t *parameter);
  84. bool check_xml_parameter(const xml_parameter_t *parameter);
  85. bool fill_enclave_css(const xml_parameter_t *parameter);
  86. void *alloc_buffer_from_metadata(uint32_t size);
  87. bool get_xsave_size(uint64_t xfrm, uint32_t *xsave_size);
  88. bool build_layout_table();
  89. bool build_patch_table();
  90. bool update_layout_entries();
  91. bool build_layout_entries();
  92. bool build_patch_entries(vector<patch_entry_t> &patches);
  93. layout_entry_t *get_entry_by_id(uint16_t id);
  94. bool build_tcs_template(tcs_t *tcs);
  95. bool build_gd_template(uint8_t *data, uint32_t *data_size);
  96. uint64_t calculate_sections_size();
  97. uint64_t calculate_enclave_size(uint64_t size);
  98. void* get_rawdata_by_rva(uint64_t rva);
  99. metadata_t *m_metadata;
  100. BinParser *m_parser;
  101. create_param_t m_create_param;
  102. vector <layout_t> m_layouts;
  103. uint64_t m_rva;
  104. uint32_t m_gd_size;
  105. uint8_t *m_gd_template;
  106. };
  107. #endif