LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_ELF_BINARY_H
17#define LIEF_ELF_BINARY_H
45class ObjectFileLayout;
62 friend class ExeLayout;
64 friend class ObjectFileLayout;
67 using string_list_t = std::vector<std::string>;
68 using notes_t = std::vector<std::unique_ptr<Note>>;
71 using it_notes = ref_iterator<notes_t&, Note*>;
74 using it_const_notes = const_ref_iterator<const notes_t&, const Note*>;
77 using symbols_version_requirement_t = std::vector<std::unique_ptr<SymbolVersionRequirement>>;
80 using it_symbols_version_requirement = ref_iterator<symbols_version_requirement_t&, SymbolVersionRequirement*>;
83 using it_const_symbols_version_requirement = const_ref_iterator<const symbols_version_requirement_t&, const SymbolVersionRequirement*>;
86 using symbols_version_definition_t = std::vector<std::unique_ptr<SymbolVersionDefinition>>;
89 using it_symbols_version_definition = ref_iterator<symbols_version_definition_t&, SymbolVersionDefinition*>;
92 using it_const_symbols_version_definition = const_ref_iterator<const symbols_version_definition_t&, const SymbolVersionDefinition*>;
95 using segments_t = std::vector<std::unique_ptr<Segment>>;
98 using it_segments = ref_iterator<segments_t&, Segment*>;
101 using it_const_segments = const_ref_iterator<const segments_t&, const Segment*>;
104 using dynamic_entries_t = std::vector<std::unique_ptr<DynamicEntry>>;
107 using it_dynamic_entries = ref_iterator<dynamic_entries_t&, DynamicEntry*>;
110 using it_const_dynamic_entries = const_ref_iterator<const dynamic_entries_t&, const DynamicEntry*>;
113 using symbols_version_t = std::vector<std::unique_ptr<SymbolVersion>>;
116 using it_symbols_version = ref_iterator<symbols_version_t&, SymbolVersion*>;
119 using it_const_symbols_version = const_ref_iterator<const symbols_version_t&, const SymbolVersion*>;
122 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
125 using it_pltgot_relocations = filter_iterator<relocations_t&, Relocation*>;
128 using it_const_pltgot_relocations = const_filter_iterator<const relocations_t&, const Relocation*>;
131 using it_dynamic_relocations = filter_iterator<relocations_t&, Relocation*>;
134 using it_const_dynamic_relocations = const_filter_iterator<const relocations_t&, const Relocation*>;
137 using it_object_relocations = filter_iterator<relocations_t&, Relocation*>;
140 using it_const_object_relocations = const_filter_iterator<const relocations_t&, const Relocation*>;
143 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
146 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
149 using symbols_t = std::vector<std::unique_ptr<Symbol>>;
152 using it_dynamic_symbols = ref_iterator<symbols_t&, Symbol*>;
155 using it_const_dynamic_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
158 using it_symtab_symbols = ref_iterator<symbols_t&, Symbol*>;
161 using it_const_symtab_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
164 using it_symbols = ref_iterator<std::vector<Symbol*>>;
167 using it_const_symbols = const_ref_iterator<std::vector<Symbol*>>;
170 using it_exported_symbols = filter_iterator<std::vector<Symbol*>>;
173 using it_const_exported_symbols = const_filter_iterator<std::vector<Symbol*>>;
176 using it_imported_symbols = filter_iterator<std::vector<Symbol*>>;
179 using it_const_imported_symbols = const_filter_iterator<std::vector<Symbol*>>;
182 using sections_t = std::vector<std::unique_ptr<Section>>;
185 using it_sections = ref_iterator<sections_t&, Section*>;
188 using it_const_sections = const_ref_iterator<const sections_t&, const Section*>;
229 Header::CLASS
type()
const {
266 return header_.entrypoint();
280 return dynamic_entries_;
284 return dynamic_entries_;
286 DynamicEntry&
add(
const DynamicEntry& entry);
289 Note&
add(
const Note& note);
292 void remove(
const DynamicEntry& entry);
295 void remove(DynamicEntry::TAG tag);
298 void remove(
const Section& section,
bool clear =
false);
305 void remove(
const Note& note);
308 void remove(Note::TYPE type);
311 void remove(
const Segment& seg);
318 return dynamic_symbols_;
322 return dynamic_symbols_;
335 return symtab_symbols_;
339 return symtab_symbols_;
344 return symbol_version_table_;
347 return symbol_version_table_;
352 return symbol_version_definition_;
356 return symbol_version_definition_;
361 return symbol_version_requirements_;
365 return symbol_version_requirements_;
415 return const_cast<Relocation*
>(
static_cast<const Binary*
>(
this)->get_relocation(address));
422 return const_cast<Relocation*
>(
static_cast<const Binary*
>(
this)->get_relocation(symbol));
424 const Relocation*
get_relocation(
const std::string& symbol_name)
const;
429 return const_cast<Relocation*
>(
static_cast<const Binary*
>(
this)->get_relocation(symbol_name));
436 return gnu_hash_ !=
nullptr && has(DynamicEntry::TAG::GNU_HASH);
442 return use_gnu_hash() ? gnu_hash_.get() :
nullptr;
449 return sysv_hash_ !=
nullptr && has(DynamicEntry::TAG::HASH);
455 return use_sysv_hash() ? sysv_hash_.get() :
nullptr;
460 return get_section(name) !=
nullptr;
472 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->get_section(name));
479 return get_section(
".text");
517 interpreter_ = interpreter;
522 return symtab_dyn_symbols();
526 return symtab_dyn_symbols();
531 Symbol&
export_symbol(
const std::string& symbol_name, uint64_t value = 0);
537 return get_dynamic_symbol(name) !=
nullptr;
545 return const_cast<Symbol*
>(
static_cast<const Binary*
>(
this)->get_dynamic_symbol(name));
550 return get_symtab_symbol(name) !=
nullptr;
558 return const_cast<Symbol*
>(
static_cast<const Binary*
>(
this)->get_symtab_symbol(name));
560 string_list_t
strings(
size_t min_size = 5)
const;
595 Section*
add(
const Section& section,
bool loaded =
true);
607 Section*
extend(
const Section& section, uint64_t size);
611 Symbol&
add_dynamic_symbol(
const Symbol& symbol,
const SymbolVersion* version =
nullptr);
617 DynamicEntryLibrary&
add_library(
const std::string& library_name);
623 DynamicEntryLibrary*
get_library(
const std::string& library_name) {
627 return const_cast<DynamicEntryLibrary*
>(
static_cast<const Binary*
>(
this)->get_library(library_name));
629 const DynamicEntryLibrary*
get_library(
const std::string& library_name)
const;
636 return get_library(name) !=
nullptr;
638 Segment*
add(
const Segment& segment, uint64_t base = 0);
647 Segment*
replace(
const Segment& new_segment,
const Segment& original_segment, uint64_t base = 0);
653 Segment*
extend(
const Segment& segment, uint64_t size);
655 void patch_address(uint64_t address,
const std::vector<uint8_t>& patch_value,
672 size_t size =
sizeof(uint64_t),
674 void patch_pltgot(
const Symbol& symbol, uint64_t address);
681 void patch_pltgot(
const std::string& symbol_name, uint64_t address);
690 void remove_section(
const std::string& name,
bool clear =
false)
override;
696 void write(
const std::string& filename)
override;
704 void write(
const std::string& filename, Builder::config_t config);
713 void write(std::ostream& os)
override;
721 void write(std::ostream& os, Builder::config_t config);
727 std::vector<uint8_t>
raw();
739 bool is_pie()
const override;
745 bool has_nx()
const override;
748 int64_t
dynsym_idx(
const std::string& name)
const;
754 int64_t
symtab_idx(
const std::string& name)
const;
767 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->section_from_offset(offset, skip_nobits));
777 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->section_from_virtual_address(address, skip_nobits));
784 return const_cast<Segment*
>(
static_cast<const Binary*
>(
this)->segment_from_virtual_address(address));
790 return const_cast<Segment*
>(
static_cast<const Binary*
>(
this)->segment_from_virtual_address(type, address));
797 return const_cast<Segment*
>(
static_cast<const Binary*
>(
this)->segment_from_offset(offset));
799 const DynamicEntry*
get(DynamicEntry::TAG tag)
const;
803 DynamicEntry*
get(DynamicEntry::TAG tag) {
804 return const_cast<DynamicEntry*
>(
static_cast<const Binary*
>(
this)->get(tag));
806 const Segment*
get(Segment::TYPE type)
const;
810 Segment*
get(Segment::TYPE type) {
811 return const_cast<Segment*
>(
static_cast<const Binary*
>(
this)->get(type));
813 const Note*
get(Note::TYPE type)
const;
817 Note*
get(Note::TYPE type) {
818 return const_cast<Note*
>(
static_cast<const Binary*
>(
this)->get(type));
820 const Section*
get(Section::TYPE type)
const;
824 Section*
get(Section::TYPE type) {
825 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->get(type));
827 bool has(DynamicEntry::TAG tag)
const {
830 return get(tag) !=
nullptr;
832 bool has(Segment::TYPE type)
const {
835 return get(type) !=
nullptr;
837 bool has(Note::TYPE type)
const {
840 return get(type) !=
nullptr;
842 bool has(Section::TYPE type)
const {
845 return get(type) !=
nullptr;
850 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO)
const override;
851 void accept(LIEF::Visitor& visitor)
const override;
869 it_const_notes
notes()
const {
887 return !overlay_.empty();
889 span<const uint8_t>
overlay()
const {
894 void overlay(std::vector<uint8_t> overlay) {
897 overlay_ = std::move(overlay);
919 auto it = std::find_if(sections_.begin(), sections_.end(),
920 [§ion] (
const std::unique_ptr<Section>& S) {
921 return S.get() == §ion;
924 if (it == sections_.end()) {
927 return std::distance(sections_.begin(), it);
932 auto it = std::find_if(sections_.begin(), sections_.end(),
933 [name] (
const std::unique_ptr<Section>& S) {
934 return S->name() == name;
937 if (it == sections_.end()) {
940 return std::distance(sections_.begin(), it);
943 static bool classof(
const LIEF::Binary* bin) {
944 return bin->
format() == Binary::FORMATS::ELF ||
945 bin->
format() == Binary::FORMATS::OAT;
948 size_t hash(
const std::string& name);
952 std::ostream&
print(std::ostream& os)
const override;
1026 struct phdr_relocation_info_t {
1027 uint64_t new_offset = 0;
1028 size_t nb_segments = 0;
1039 LIEF_LOCAL LIEF::Header get_abstract_header()
const override {
1045 LIEF_LOCAL std::vector<std::string> get_abstract_imported_libraries()
const override;
1049 template<ELF::ARCH ARCH>
1050 LIEF_LOCAL void patch_relocations(uint64_t from, uint64_t shift);
1053 LIEF_LOCAL void patch_addend(Relocation& relocatio, uint64_t from, uint64_t shift);
1055 LIEF_LOCAL void shift_sections(uint64_t from, uint64_t shift);
1056 LIEF_LOCAL void shift_segments(uint64_t from, uint64_t shift);
1057 LIEF_LOCAL void shift_dynamic_entries(uint64_t from, uint64_t shift);
1058 LIEF_LOCAL void shift_symbols(uint64_t from, uint64_t shift);
1059 LIEF_LOCAL void shift_relocations(uint64_t from, uint64_t shift);
1061 template<
class ELF_T>
1062 LIEF_LOCAL void fix_got_entries(uint64_t from, uint64_t shift);
1067 template<Header::FILE_TYPE OBJECT_TYPE,
bool note = false>
1068 LIEF_LOCAL Segment* add_segment(
const Segment& segment, uint64_t base);
1070 LIEF_LOCAL uint64_t relocate_phdr_table_auto();
1071 LIEF_LOCAL uint64_t relocate_phdr_table_pie();
1072 LIEF_LOCAL uint64_t relocate_phdr_table_v1();
1073 LIEF_LOCAL uint64_t relocate_phdr_table_v2();
1074 LIEF_LOCAL uint64_t relocate_phdr_table_v3();
1076 template<Segment::TYPE PT>
1077 LIEF_LOCAL Segment* extend_segment(
const Segment& segment, uint64_t size);
1079 template<
bool LOADED>
1080 LIEF_LOCAL Section* add_section(
const Section& section);
1082 std::vector<Symbol*> symtab_dyn_symbols()
const;
1084 LIEF_LOCAL std::string shstrtab_name()
const;
1085 LIEF_LOCAL Section* add_frame_section(
const Section& sec);
1089 Header::CLASS type_ = Header::CLASS::NONE;
1091 sections_t sections_;
1092 segments_t segments_;
1093 dynamic_entries_t dynamic_entries_;
1094 symbols_t dynamic_symbols_;
1095 symbols_t symtab_symbols_;
1096 relocations_t relocations_;
1097 symbols_version_t symbol_version_table_;
1098 symbols_version_requirement_t symbol_version_requirements_;
1099 symbols_version_definition_t symbol_version_definition_;
1101 std::unique_ptr<GnuHash> gnu_hash_;
1102 std::unique_ptr<SysvHash> sysv_hash_;
1103 std::unique_ptr<DataHandler::Handler> datahandler_;
1104 phdr_relocation_info_t phdr_reloc_info_;
1106 std::string interpreter_;
1107 std::vector<uint8_t> overlay_;
1108 std::unique_ptr<sizing_info_t> sizing_info_;
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:67
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:109
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:79
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:53
@ AUTO
Try to guess if it's relative or not.
Definition Abstract/Binary.hpp:54
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:70
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:88
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
Segment * add(const Segment &segment, uint64_t base=0)
Add a new segment in the binary.
bool use_gnu_hash() const
true if GNU hash is used
Definition ELF/Binary.hpp:435
const DynamicEntry * get(DynamicEntry::TAG tag) const
Return the first ELF::DynamicEntry associated with the given tag If the tag can't be found,...
Header::CLASS type() const
Return binary's class (ELF32 or ELF64)
Definition ELF/Binary.hpp:231
void write(const std::string &filename) override
Reconstruct the binary object and write it in filename
result< uint64_t > virtual_address_to_offset(uint64_t virtual_address) const
Convert a virtual address to a file offset.
it_const_symbols symbols() const
Definition ELF/Binary.hpp:525
uint64_t last_offset_section() const
Return the last offset used in binary according to sections table.
span< const uint8_t > get_content_from_virtual_address(uint64_t virtual_address, uint64_t size, Binary::VA_TYPES addr_type=Binary::VA_TYPES::AUTO) const override
Return the content located at virtual address.
Header & header()
Return Elf header .
Definition ELF/Binary.hpp:236
const Section * section_from_offset(uint64_t offset, bool skip_nobits=true) const
Return the ELF::Section from the given offset. Return a nullptr if a section can't be found.
it_dynamic_entries dynamic_entries()
Return binary's dynamic entries.
Definition ELF/Binary.hpp:279
it_symbols_version_requirement symbols_version_requirement()
Return Symbol version requirement.
Definition ELF/Binary.hpp:360
size_t hash(const std::string &name)
it_const_dynamic_relocations dynamic_relocations() const
it_pltgot_relocations pltgot_relocations()
Return plt.got relocations.
void strip()
Strip the binary by removing symtab symbols.
Note & add(const Note ¬e)
Add the given note and return the created entry.
Symbol & export_symbol(const std::string &symbol_name, uint64_t value=0)
Export the symbol with the given name and create it if it doesn't exist.
void remove_symtab_symbol(Symbol *symbol)
Binary & operator+=(const DynamicEntry &entry)
Definition ELF/Binary.hpp:954
void remove(const Note ¬e)
Remove the given note.
const Note * operator[](Note::TYPE type) const
Definition ELF/Binary.hpp:1013
bool has_notes() const
true if the binary embeds notes
int64_t dynsym_idx(const std::string &name) const
Symbol index in the dynamic symbol table or -1 if the symbol does not exist.
Segment * segment_from_virtual_address(uint64_t address)
Definition ELF/Binary.hpp:783
const Relocation * get_relocation(const Symbol &symbol) const
Return relocation associated with the given Symbol It returns a nullptr if it is not found.
void remove_dynamic_symbol(const std::string &name)
Remove dynamic symbols with the given name.
Binary & operator-=(const Note ¬e)
Definition ELF/Binary.hpp:983
const Section * section_from_virtual_address(uint64_t address, bool skip_nobits=true) const
Return the ELF::Section from the given address. Return a nullptr if a section can't be found.
const Relocation * get_relocation(const std::string &symbol_name) const
Return relocation associated with the given Symbol name It returns a nullptr if it is not found.
it_symtab_symbols symtab_symbols()
Return the debug symbols from the .symtab section.
Definition ELF/Binary.hpp:334
LIEF::Binary::functions_t ctor_functions() const override
List of binary constructors (typically, the functions located in the .init_array)
uint64_t imagebase() const override
Return program image base. For instance 0x40000
LIEF::Binary::functions_t functions() const
List of the functions found the in the binary.
bool has_library(const std::string &name) const
Check if the given library name exists in the current binary.
Definition ELF/Binary.hpp:635
int64_t dynsym_idx(const Symbol &sym) const
LIEF::Binary::functions_t dtor_functions() const
List of the binary destructors (typically, the functions located in the .fini_array)
Segment * operator[](Segment::TYPE type)
Definition ELF/Binary.hpp:993
const Symbol * get_dynamic_symbol(const std::string &name) const
Get the dynamic symbol from the given name. Return a nullptr if it can't be found.
Relocation * get_relocation(uint64_t address)
Definition ELF/Binary.hpp:414
const Segment * segment_from_virtual_address(Segment::TYPE type, uint64_t address) const
DynamicEntryLibrary * get_library(const std::string &library_name)
Get the library object (DynamicEntryLibrary) from the given name If the library can't be found,...
Definition ELF/Binary.hpp:626
bool is_pie() const override
Check if the binary has been compiled with -fpie -pie flags.
Symbol * get_symtab_symbol(const std::string &name)
Definition ELF/Binary.hpp:557
it_symbols_version symbols_version()
Return the symbol versions.
Definition ELF/Binary.hpp:343
DynamicEntryLibrary & add_library(const std::string &library_name)
Add a library as dependency.
Section * text_section()
Return the .text section. If the section can't be found, it returns a nullptr.
Definition ELF/Binary.hpp:478
it_object_relocations object_relocations()
Return relocations used in an object file (*.o)
Section * get_section(const std::string &name)
Return Section with the given name. If the section can't be found, it returns a nullptr.
Definition ELF/Binary.hpp:471
it_imported_symbols imported_symbols()
Return symbols which are imported by the binary.
it_sections sections()
Return an iterator over the binary's sections.
Definition ELF/Binary.hpp:256
it_const_notes notes() const
Return an iterator over the ELF's LIEF::ELF::Note.
Definition ELF/Binary.hpp:873
void patch_address(uint64_t address, uint64_t patch_value, size_t size=sizeof(uint64_t), LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override
Patch the address with the given value.
it_symbols_version_definition symbols_version_definition()
Return symbols version definition.
Definition ELF/Binary.hpp:351
it_const_object_relocations object_relocations() const
const Symbol * get_symtab_symbol(const std::string &name) const
Get the symtab symbol from the given name Return a nullptr if it can't be found.
it_dynamic_relocations dynamic_relocations()
Return dynamic relocations.
void overlay(std::vector< uint8_t > overlay)
Function to set the overlay.
Definition ELF/Binary.hpp:896
Note * get(Note::TYPE type)
Definition ELF/Binary.hpp:817
void remove_dynamic_symbol(Symbol *symbol)
Remove the given symbol from the dynamic symbols table.
span< const uint8_t > overlay() const
Overlay data (if any)
Definition ELF/Binary.hpp:891
bool has_overlay() const
True if data are present at the end of the binary.
Definition ELF/Binary.hpp:886
bool has(Section::TYPE type) const
Check if a ELF::Section associated with the given type exists.
Definition ELF/Binary.hpp:844
std::ostream & print(std::ostream &os) const override
Relocation * get_relocation(const std::string &symbol_name)
Definition ELF/Binary.hpp:428
Symbol & add_dynamic_symbol(const Symbol &symbol, const SymbolVersion *version=nullptr)
Add a dynamic symbol with the associated SymbolVersion.
Symbol & add_symtab_symbol(const Symbol &symbol)
Add a symtab symbol.
Binary & operator+=(const Section §ion)
Definition ELF/Binary.hpp:958
const Section * get_section(const std::string &name) const
void interpreter(const std::string &interpreter)
Change the interpreter.
Definition ELF/Binary.hpp:516
Binary(const Binary ©)=delete
int64_t symtab_idx(const Symbol &sym) const
const Segment * operator[](Segment::TYPE type) const
Definition ELF/Binary.hpp:997
it_const_sections sections() const
Definition ELF/Binary.hpp:260
result< size_t > get_section_idx(const std::string &name) const
Find the index of the section with the name given in the first parameter.
Definition ELF/Binary.hpp:931
Relocation * add_object_relocation(const Relocation &relocation, const Section §ion)
Add relocation for object file (.o)
uint64_t virtual_size() const
Return the size of the mapped binary.
it_exported_symbols exported_symbols()
Return symbols which are exported by the binary.
const Header & header() const
Definition ELF/Binary.hpp:240
it_const_symtab_symbols symtab_symbols() const
Definition ELF/Binary.hpp:338
result< size_t > get_section_idx(const Section §ion) const
Find the index of the section given in the first parameter.
Definition ELF/Binary.hpp:918
Section * extend(const Section §ion, uint64_t size)
const Segment * get(Segment::TYPE type) const
Return the first ELF::Segment associated with the given type. If a segment can't be found,...
uint64_t entrypoint() const override
Return the binary's entrypoint.
Definition ELF/Binary.hpp:265
bool has(Note::TYPE type) const
Check if a ELF::Note associated with the given type exists.
Definition ELF/Binary.hpp:839
Segment * segment_from_offset(uint64_t offset)
Definition ELF/Binary.hpp:796
bool has_symtab_symbol(const std::string &name) const
Check if the symbol with the given name exists in the symtab symbol table.
Definition ELF/Binary.hpp:549
bool has_dynamic_symbol(const std::string &name) const
Check if the symbol with the given name exists in the dynamic symbols table.
Definition ELF/Binary.hpp:536
DynamicEntry * operator[](DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:1001
result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const override
Convert the given offset into a virtual address.
it_const_symbols_version_definition symbols_version_definition() const
Definition ELF/Binary.hpp:355
const Section * get(Section::TYPE type) const
Return the first ELF::Section associated with the given type If a section can't be found,...
Section * hash_section()
Return the hash section. If the section can't be found, it returns a nullptr.
uint64_t next_virtual_address() const
Return the next virtual address available.
it_const_exported_symbols exported_symbols() const
const Segment * segment_from_virtual_address(uint64_t address) const
Return the ELF::Segment from the given address. Return a nullptr if a segment can't be found.
Binary & operator-=(const DynamicEntry &entry)
Definition ELF/Binary.hpp:973
uint64_t eof_offset() const
Return the last offset used by the ELF binary according to both: the sections table and the segments ...
void remove(DynamicEntry::TAG tag)
Remove all dynamic entries with the given tag.
it_segments segments()
Return binary's segments.
Definition ELF/Binary.hpp:270
void remove_library(const std::string &library_name)
Remove the given library from the dependencies.
result< uint64_t > get_function_address(const std::string &func_name, bool demangled) const
Return the address of the given function name.
it_dynamic_symbols dynamic_symbols()
Return an iterator over the binary's dynamic symbols The dynamic symbols are those located in the ....
Definition ELF/Binary.hpp:317
Section * add(const Section §ion, bool loaded=true)
Add a new section in the binary.
it_const_dynamic_entries dynamic_entries() const
Definition ELF/Binary.hpp:283
void remove_symtab_symbol(const std::string &name)
Remove symtabl symbols with the given name.
Binary & operator-=(DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:978
it_relocations relocations()
Return all relocations present in the binary.
Definition ELF/Binary.hpp:403
Section * dynamic_section()
Return the .dynamic section. If the section can't be found, it returns a nullptr.
Segment * get(Segment::TYPE type)
Definition ELF/Binary.hpp:810
const DynamicEntryLibrary * get_library(const std::string &library_name) const
Get the library object (DynamicEntryLibrary) from the given name If the library can't be found,...
const DynamicEntry * operator[](DynamicEntry::TAG tag) const
Definition ELF/Binary.hpp:1005
it_symbols symbols()
Return an iterator on both static and dynamic symbols.
Definition ELF/Binary.hpp:521
uint64_t relocate_phdr_table(PHDR_RELOC type)
Force relocating the segments table in a specific way.
Segment * replace(const Segment &new_segment, const Segment &original_segment, uint64_t base=0)
Replace the segment given in 2nd parameter with the segment given in the first one and return the upd...
void remove(const Section §ion, bool clear=false)
Remove the given section. The clear parameter can be used to zeroize the original content beforehand.
Symbol * get_dynamic_symbol(const std::string &name)
Definition ELF/Binary.hpp:544
Section * operator[](Section::TYPE type)
Definition ELF/Binary.hpp:1017
it_const_dynamic_symbols dynamic_symbols() const
Definition ELF/Binary.hpp:321
bool has_section_with_offset(uint64_t offset) const
Check if a section that handles the given offset exists.
string_list_t strings(size_t min_size=5) const
Return list of the strings used by the ELF binary.
void remove_section(const std::string &name, bool clear=false) override
Remove a binary's section.
std::vector< uint8_t > raw()
Reconstruct the binary object and return its content as a byte vector.
const SysvHash * sysv_hash() const
Return the SysvHash object as a read-only object If the ELF binary does not use the legacy sysv hash ...
Definition ELF/Binary.hpp:454
bool has_section(const std::string &name) const
Check if a section with the given name exists in the binary.
Definition ELF/Binary.hpp:459
Relocation * get_relocation(const Symbol &symbol)
Definition ELF/Binary.hpp:421
Section * section_from_offset(uint64_t offset, bool skip_nobits=true)
Definition ELF/Binary.hpp:766
Section * get(Section::TYPE type)
Definition ELF/Binary.hpp:824
static bool classof(const LIEF::Binary *bin)
Definition ELF/Binary.hpp:943
it_const_relocations relocations() const
Definition ELF/Binary.hpp:407
Binary & operator-=(Note::TYPE type)
Definition ELF/Binary.hpp:988
Symbol & add_exported_function(uint64_t address, const std::string &name="")
Create a symbol for the function at the given address and export it.
bool is_targeting_android() const
True if the current ELF is targeting Android.
it_const_segments segments() const
Definition ELF/Binary.hpp:274
DynamicEntry * get(DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:803
Section * symtab_symbols_section()
Return section which holds the symtab symbols. If the section can't be found, it returns a nullptr.
uint64_t last_offset_segment() const
Return the last offset used in binary according to segments table.
bool use_sysv_hash() const
true if SYSV hash is used
Definition ELF/Binary.hpp:448
void patch_pltgot(const Symbol &symbol, uint64_t address)
Patch the imported symbol with the address
void write(std::ostream &os, Builder::config_t config)
Reconstruct the binary object with the given config and write it in os stream.
bool has_interpreter() const
Check if the binary uses a loader (also named linker or interpreter)
const Relocation * get_relocation(uint64_t address) const
Return relocation associated with the given address. It returns a nullptr if it is not found.
void remove_symbol(const std::string &name)
Remove symbols with the given name in both:
const Section * operator[](Section::TYPE type) const
Definition ELF/Binary.hpp:1021
const Segment * segment_from_offset(uint64_t offset) const
Return the ELF::Segment from the offset. Return a nullptr if a segment can't be found.
Section * section_from_virtual_address(uint64_t address, bool skip_nobits=true)
Definition ELF/Binary.hpp:776
void write(std::ostream &os) override
Reconstruct the binary object and write it in os stream.
void remove(Note::TYPE type)
Remove all notes with the given type.
Relocation & add_dynamic_relocation(const Relocation &relocation)
Add a new dynamic relocation.
const std::string & interpreter() const
Return the ELF interpreter if any. (e.g. /lib64/ld-linux-x86-64.so.2) If the binary does not have an ...
Definition ELF/Binary.hpp:511
int64_t symtab_idx(const std::string &name) const
Symbol index from the .symtab section or -1 if the symbol is not present.
Segment * extend(const Segment &segment, uint64_t size)
std::vector< uint64_t > get_relocated_dynamic_array(DynamicEntry::TAG tag) const
Return the array defined by the given tag (e.g. DynamicEntry::TAG::INIT_ARRAY) with relocations appli...
it_const_pltgot_relocations pltgot_relocations() const
it_const_symbols_version_requirement symbols_version_requirement() const
Definition ELF/Binary.hpp:364
it_notes notes()
Definition ELF/Binary.hpp:877
it_const_imported_symbols imported_symbols() const
void patch_address(uint64_t address, const std::vector< uint8_t > &patch_value, LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override
Patch the content at virtual address address with patch_value.
Note * operator[](Note::TYPE type)
Definition ELF/Binary.hpp:1009
Binary & operator+=(const Segment &segment)
Definition ELF/Binary.hpp:963
void write(const std::string &filename, Builder::config_t config)
Reconstruct the binary object with the given config and write it in filename
Binary & operator=(const Binary &)=delete
Segment * segment_from_virtual_address(Segment::TYPE type, uint64_t address)
Definition ELF/Binary.hpp:789
void permute_dynamic_symbols(const std::vector< size_t > &permutation)
Apply the given permutation on the dynamic symbols table.
bool has_section_with_va(uint64_t va) const
Check if a section that handles the given virtual address exists.
void patch_pltgot(const std::string &symbol_name, uint64_t address)
Patch the imported symbol's name with the address
void accept(LIEF::Visitor &visitor) const override
Method associated with the visitor pattern.
void remove(const Segment &seg)
Remove the given segment.
const Note * get(Note::TYPE type) const
Return the first ELF::Note associated with the given type If a note can't be found,...
Symbol & export_symbol(const Symbol &symbol)
Export the given symbol and create it if it doesn't exist.
it_const_symbols_version symbols_version() const
Definition ELF/Binary.hpp:346
Relocation & add_pltgot_relocation(const Relocation &relocation)
Add a .plt.got relocation. This kind of relocation is usually associated with a PLT stub that aims at...
Binary & operator+=(const Note ¬e)
Definition ELF/Binary.hpp:968
result< uint64_t > get_function_address(const std::string &func_name) const override
Return the address of the given function name.
const GnuHash * gnu_hash() const
Return the GnuHash object in readonly If the ELF binary does not use the GNU hash table,...
Definition ELF/Binary.hpp:441
bool has_nx() const override
Check if the binary uses the NX protection (Non executable stack)
void remove(const DynamicEntry &entry)
Remove the given dynamic entry.
DynamicEntry & add(const DynamicEntry &entry)
Add the given dynamic entry and return the new entry.
bool has(Segment::TYPE type) const
Check if ELF::Segment associated with the given type exists.
Definition ELF/Binary.hpp:834
bool has(DynamicEntry::TAG tag) const
Check if an ELF::DynamicEntry associated with the given tag exists.
Definition ELF/Binary.hpp:829
Class which represents a DT_NEEDED entry in the dynamic table.
Definition DynamicEntryLibrary.hpp:29
Class which provides a view over the GNU Hash implementation. Most of the fields are read-only since ...
Definition GnuHash.hpp:36
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Class that represents an ELF relocation.
Definition ELF/Relocation.hpp:40
Class wich represents an ELF Section.
Definition ELF/Section.hpp:48
Class which represents the ELF segments.
Definition Segment.hpp:46
Class which represents an entry defined in DT_VERDEF or .gnu.version_d
Definition SymbolVersionDefinition.hpp:37
Class which represents an entry in the DT_VERNEED or .gnu.version_r table.
Definition SymbolVersionRequirement.hpp:39
Class which represents an entry defined in the DT_VERSYM dynamic entry.
Definition SymbolVersion.hpp:32
Class which represents an ELF symbol.
Definition ELF/Symbol.hpp:35
Class which represents the SYSV hash for the symbols resolution.
Definition SysvHash.hpp:39
@ not_found
Definition errors.hpp:25
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition errors.hpp:52
Definition ELF/Binary.hpp:38
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42