15#ifndef LIEF_COFF_BINARY_H
16#define LIEF_COFF_BINARY_H
26#include <unordered_map>
50 using sections_t = std::vector<std::unique_ptr<Section>>;
78 using symbols_t = std::vector<std::unique_ptr<Symbol>>;
133 return strings_table_;
137 return strings_table_;
145 auto it = std::find_if(strings_table_.begin(), strings_table_.end(),
146 [offset](
const String& item) {
147 return offset == item.offset();
149 return it == strings_table_.end() ? nullptr : &*it;
153 return const_cast<Binary*
>(
this)->
find_string(offset);
165 return const_cast<Symbol*
>(
166 static_cast<const Binary*
>(
this)->find_function(name)
175 return const_cast<Symbol*
>(
176 static_cast<const Binary*
>(
this)->find_demangled_function(name)
223 return disassemble(buffer.data(), buffer.size(), address);
228 return disassemble(buffer.data(), buffer.size(), address);
233 return disassemble(buffer.data(), buffer.size(), address);
253 static_cast<const Binary*
>(
this)->get_section(name)
270 std::unique_ptr<Header> header_;
276 mutable std::unordered_map<uint32_t, std::unique_ptr<assembly::Engine>> engines_;
280 template<u
int32_t Key,
class F>
std::vector< std::unique_ptr< Symbol > > symbols_t
Internal container used to store COFF's symbols.
Definition COFF/Binary.hpp:78
ref_iterator< relocations_t &, Relocation * > it_relocations
Iterator that outputs Relocation& object.
Definition COFF/Binary.hpp:62
const Header & header() const
The COFF header.
Definition COFF/Binary.hpp:96
it_symbols symbols()
Iterator over the COFF's symbols.
Definition COFF/Binary.hpp:123
const Symbol * find_demangled_function(std::string_view name) const
Try to find the function (symbol) with the given demangled name.
const_ref_iterator< const relocations_t &, const Relocation * > it_const_relocations
Iterator that outputs const Relocation& object.
Definition COFF/Binary.hpp:65
const String * find_string(uint32_t offset) const
Definition COFF/Binary.hpp:152
iterator_range< assembly::Instruction::Iterator > instructions_it
Instruction iterator.
Definition COFF/Binary.hpp:87
instructions_it disassemble(LIEF::span< uint8_t > buffer, uint64_t address=0) const
Definition COFF/Binary.hpp:231
instructions_it disassemble(LIEF::span< const uint8_t > buffer, uint64_t address=0) const
Definition COFF/Binary.hpp:226
const_ref_iterator< const strings_table_t & > it_const_strings_table
Iterator that outputs const String& object.
Definition COFF/Binary.hpp:75
it_sections sections()
Iterator over the different sections located in this COFF binary.
Definition COFF/Binary.hpp:105
it_const_symbols symbols() const
Definition COFF/Binary.hpp:127
it_const_strings_table string_table() const
Iterator over the COFF's strings.
Definition COFF/Binary.hpp:132
ref_iterator< strings_table_t & > it_strings_table
Iterator that outputs String& object.
Definition COFF/Binary.hpp:72
filter_iterator< symbols_t &, Symbol * > it_functions
Iterator which outputs COFF symbols representing functions.
Definition COFF/Binary.hpp:90
const_filter_iterator< const symbols_t &, const Symbol * > it_const_function
Iterator which outputs COFF symbols representing functions.
Definition COFF/Binary.hpp:93
ref_iterator< symbols_t &, Symbol * > it_symbols
Iterator that outputs Symbol& object.
Definition COFF/Binary.hpp:81
const_ref_iterator< const sections_t &, const Section * > it_const_sections
Iterator that outputs const Section& object.
Definition COFF/Binary.hpp:56
instructions_it disassemble(const uint8_t *buffer, size_t size, uint64_t address=0) const
Disassemble code provided by the given buffer at the specified address parameter.
const_ref_iterator< const symbols_t &, const Symbol * > it_const_symbols
Iterator that outputs Symbol& object.
Definition COFF/Binary.hpp:84
const Section * get_section(std::string_view name) const
it_strings_table string_table()
Definition COFF/Binary.hpp:136
it_const_relocations relocations() const
Definition COFF/Binary.hpp:118
Symbol * find_demangled_function(std::string_view name)
Definition COFF/Binary.hpp:174
it_const_function functions() const
Iterator over the functions implemented in this COFF.
const Symbol * find_function(std::string_view name) const
Try to find the function (symbol) with the given name.
friend class Parser
Definition COFF/Binary.hpp:47
instructions_it disassemble(std::string_view symbol) const
Disassemble code for the given symbol name.
std::string to_string() const
it_const_sections sections() const
Definition COFF/Binary.hpp:109
Section * get_section(std::string_view name)
Return the section matching the given name or a nullptr if it can't be found.
Definition COFF/Binary.hpp:251
Header & header()
Definition COFF/Binary.hpp:100
ref_iterator< sections_t &, Section * > it_sections
Iterator that outputs Section& object.
Definition COFF/Binary.hpp:53
String * find_string(uint32_t offset)
Try to find the COFF string at the given offset in the COFF string table.
Definition COFF/Binary.hpp:144
instructions_it disassemble(const Symbol &symbol) const
Disassemble code for the given symbol.
std::vector< String > strings_table_t
Internal container used to store COFF's strings.
Definition COFF/Binary.hpp:69
std::vector< std::unique_ptr< Relocation > > relocations_t
Internal container used to store COFF's relocations.
Definition COFF/Binary.hpp:59
friend std::ostream & operator<<(std::ostream &os, const Binary &bin)
Definition COFF/Binary.hpp:261
std::vector< std::unique_ptr< Section > > sections_t
Internal container used to store COFF's section.
Definition COFF/Binary.hpp:50
it_relocations relocations()
Iterator over all the relocations used by this COFF binary.
Definition COFF/Binary.hpp:114
Definition COFF/Parser.hpp:36
This class represents a COFF relocation.
Definition COFF/Relocation.hpp:33
This class represents a COFF section.
Definition COFF/Section.hpp:40
This class represents a string located in the COFF string table.
Definition String.hpp:34
This class represents a COFF symbol.
Definition COFF/Symbol.hpp:36
This class interfaces the assembler/disassembler support.
Definition Engine.hpp:38
Iterator which returns a ref on container's values given predicates.
Definition iterators.hpp:392
Definition iterators.hpp:680
Iterator which returns reference on container's values.
Definition iterators.hpp:120
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition AuxiliarySymbol.hpp:29
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:41
filter_iterator< CT, U, typename decay_t< CT >::const_iterator > const_filter_iterator
Iterator which returns a const ref on container's values given predicates.
Definition iterators.hpp:672
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:385
#define LIEF_API
Definition visibility.h:44
#define LIEF_LOCAL
Definition visibility.h:45