16#ifndef LIEF_ELF_PARSER_H
17#define LIEF_ELF_PARSER_H
18#include <unordered_map>
46 friend class OAT::Parser;
48 static constexpr uint32_t NB_MAX_SYMBOLS = 1000000;
49 static constexpr uint32_t DELTA_NB_SYMBOLS = 3000;
50 static constexpr uint32_t NB_MAX_BUCKETS = NB_MAX_SYMBOLS;
51 static constexpr uint32_t NB_MAX_CHAINS = 1000000;
52 static constexpr uint32_t NB_MAX_SEGMENTS = 10000;
53 static constexpr uint32_t NB_MAX_RELOCATIONS = 3000000;
54 static constexpr uint32_t NB_MAX_DYNAMIC_ENTRIES = 1000;
55 static constexpr uint32_t NB_MAX_MASKWORD = 512;
56 static constexpr uint32_t MAX_SEGMENT_SIZE = 3_GB;
62 static std::unique_ptr<Binary>
parse(
const std::string& file,
72 const ParserConfig& conf = ParserConfig::all());
73 static std::unique_ptr<Binary>
parse(
const std::vector<uint8_t>& data,
83 const ParserConfig& conf = ParserConfig::all());
84 static std::unique_ptr<Binary>
parse(std::unique_ptr<BinaryStream> stream,
94 const ParserConfig& conf = ParserConfig::all());
103 LIEF_LOCAL Parser(std::unique_ptr<BinaryStream> stream, ParserConfig config);
104 LIEF_LOCAL Parser(
const std::string& file, ParserConfig config);
105 LIEF_LOCAL Parser(
const std::vector<uint8_t>& data, ParserConfig config);
117 template<
typename ELF_T>
120 template<
typename ELF_T>
123 template<
typename ELF_T>
126 template<
typename ELF_T>
129 LIEF_LOCAL uint64_t get_dynamic_string_table()
const;
131 LIEF_LOCAL result<uint64_t> get_dynamic_string_table_from_segments()
const;
133 LIEF_LOCAL uint64_t get_dynamic_string_table_from_sections()
const;
134 template<
typename ELF_T>
138 get_numberof_dynamic_symbols(ParserConfig::DYNSYM_COUNT mtd)
const;
139 template<
typename ELF_T>
142 LIEF_LOCAL result<uint32_t> nb_dynsym_hash()
const;
143 template<
typename ELF_T>
146 LIEF_LOCAL result<uint32_t> nb_dynsym_sysv_hash()
const;
147 template<
typename ELF_T>
150 LIEF_LOCAL result<uint32_t> nb_dynsym_gnu_hash()
const;
151 template<
typename ELF_T>
154 LIEF_LOCAL result<uint32_t> nb_dynsym_section()
const;
155 template<
typename ELF_T>
158 LIEF_LOCAL result<uint32_t> nb_dynsym_relocations()
const;
160 template<
typename ELF_T>
163 template<
typename ELF_T>
165 template<
typename ELF_T>
176 parse_symtab_symbols(uint64_t offset, uint32_t nb_symbols,
177 const Section& string_section);
178 template<
typename ELF_T,
typename REL_T>
184 parse_dynamic_relocations(uint64_t relocations_offset, uint64_t size);
185 template<
typename ELF_T,
typename REL_T>
194 template<
typename ELF_T>
198 template<
typename ELF_T>
203 template<
typename ELF_T>
205 template<
typename ELF_T,
typename REL_T>
210 parse_section_relocations(
const Section& section);
211 template<
typename ELF_T>
219 parse_symbol_version_requirement(uint64_t offset, uint32_t nb_entries);
221 template<
typename ELF_T>
229 parse_symbol_version_definition(uint64_t offset, uint32_t nb_entries);
239 template<
typename ELF_T>
250 get_note(uint32_t type, std::string name, std::vector<uint8_t> desc_bytes);
257 template<
typename ELF_T,
typename REL_T>
258 LIEF_LOCAL uint32_t max_relocation_index(uint64_t relocations_offset, uint64_t size)
const;
259 LIEF_LOCAL static bool check_section_in_segment(
const Section& section,
const Segment& segment);
264 LIEF_LOCAL Relocation& insert_relocation(std::unique_ptr<Relocation> R);
266 std::unique_ptr<BinaryStream> stream_;
267 std::unique_ptr<Binary> binary_;
268 ParserConfig config_;
276 std::unordered_map<size_t, Section*> sections_idx_;