binparser.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2011-2016 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 _BINPARSER_H_
  32. #define _BINPARSER_H_
  33. #include "section.h"
  34. #include "util.h"
  35. #include "se_memcpy.h"
  36. #include "create_param.h"
  37. #include "sgx_error.h"
  38. #include <stdint.h>
  39. #include <vector>
  40. #include <string>
  41. using std::vector;
  42. using std::string;
  43. #define ENCLAVE_MAX_SIZE_32 0xffffffff
  44. #define ENCLAVE_MAX_SIZE_64 0x1fffffffff
  45. typedef enum _bin_fmt_t
  46. {
  47. BF_UNKNOWN = 0,
  48. BF_PE32,
  49. BF_PE64,
  50. BF_ELF32,
  51. BF_ELF64
  52. } bin_fmt_t;
  53. typedef struct _enclave_diff_info_t
  54. {
  55. } enclave_diff_info_t;
  56. class BinParser {
  57. public:
  58. virtual ~BinParser() {}
  59. virtual sgx_status_t run_parser() = 0;
  60. virtual bin_fmt_t get_bin_format() const = 0;
  61. virtual uint64_t get_enclave_max_size() const = 0;
  62. virtual uint64_t get_metadata_offset() const = 0;
  63. virtual uint64_t get_metadata_block_size() const = 0;
  64. virtual const uint8_t* get_start_addr() const = 0;
  65. // Get a vector of sections to be loaded
  66. virtual const vector<Section *>& get_sections() const = 0;
  67. // Get the TLS section
  68. virtual const Section* get_tls_section() const = 0;
  69. virtual uint64_t get_symbol_rva(const char* name) const = 0;
  70. virtual bool get_reloc_bitmap(vector<uint8_t> &bitmap) = 0;
  71. virtual void get_reloc_entry_offset(const char* sec_name,
  72. vector<uint64_t>& offsets) = 0;
  73. // We need to put this method into BinParser class since
  74. // the `global_data_t' is platform-dependent as the parser.
  75. // c.f. global_data.h for more information.
  76. //
  77. // Unfortunately, although the implementation is the same,
  78. // we can't put them here but into the subclasses -
  79. // ElfParsr and PEParser, since the `global_data_t' for
  80. // them are different in terms of size and layout.
  81. virtual bool update_global_data(const create_param_t* const create_param,
  82. uint8_t *data,
  83. uint32_t *data_size) = 0;
  84. virtual sgx_status_t modify_info(enclave_diff_info_t *enclave_diff_info) = 0;
  85. virtual sgx_status_t get_info(enclave_diff_info_t *enclave_diff_info) = 0;
  86. };
  87. #endif