LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ELF/Binary.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_ELF_BINARY_H
17#define LIEF_ELF_BINARY_H
18
19#include <vector>
20#include <memory>
21
22#include "LIEF/visibility.h"
23#include "LIEF/errors.hpp"
24#include "LIEF/iterators.hpp"
25
27
28#include "LIEF/ELF/Note.hpp"
30#include "LIEF/ELF/Header.hpp"
31#include "LIEF/ELF/Section.hpp"
32#include "LIEF/ELF/Segment.hpp"
33#include "LIEF/ELF/Builder.hpp"
34
35namespace LIEF {namespace ELF {
38namespace DataHandler {
39class Handler;
40}
41
42class ExeLayout;
43class GnuHash;
44class Layout;
45class ObjectFileLayout;
46class Parser;
47class Relocation;
48class Section;
49class Segment;
50class Symbol;
51class SymbolVersion;
55class SysvHash;
56struct sizing_info_t;
57class LIEF_API Binary : public LIEF::Binary {
60 friend class Parser;
61 friend class Builder;
62 friend class ExeLayout;
63 friend class Layout;
64 friend class ObjectFileLayout;
65
66 public:
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*>;
191
192 public:
196 enum PHDR_RELOC {
200 AUTO = 0,
201
207 PIE_SHIFT,
208
213 BSS_END,
217 BINARY_END,
223 SEGMENT_GAP,
224 };
225 enum class SEC_INSERT_POS { AUTO = 0,
231 POST_SEGMENT,
238 POST_SECTION,
243 };
244
245 public:
246 Binary& operator=(const Binary& ) = delete;
247 Binary(const Binary& copy) = delete;
248 Header::CLASS type() const {
251 return type_;
252 }
253 Header& header() {
256 return header_;
257 }
258
259 const Header& header() const {
260 return header_;
261 }
262 uint64_t last_offset_section() const;
266 uint64_t last_offset_segment() const;
270 uint64_t next_virtual_address() const;
273 it_sections sections() {
276 return sections_;
277 }
278
279 it_const_sections sections() const {
280 return sections_;
281 }
282 uint64_t entrypoint() const override {
285 return header_.entrypoint();
286 }
287 it_segments segments() {
290 return segments_;
291 }
292
293 it_const_segments segments() const {
294 return segments_;
295 }
296 it_dynamic_entries dynamic_entries() {
299 return dynamic_entries_;
300 }
301
302 it_const_dynamic_entries dynamic_entries() const {
303 return dynamic_entries_;
304 }
305 DynamicEntry& add(const DynamicEntry& entry);
308 Note& add(const Note& note);
311 void remove(const DynamicEntry& entry);
314 void remove(DynamicEntry::TAG tag);
317 void remove(const Section& section, bool clear = false);
324 void remove(const Note& note);
327 void remove(Note::TYPE type);
330 void remove(const Segment& seg);
333 it_dynamic_symbols dynamic_symbols() {
337 return dynamic_symbols_;
338 }
339
340 it_const_dynamic_symbols dynamic_symbols() const {
341 return dynamic_symbols_;
342 }
343 it_exported_symbols exported_symbols();
346 it_const_exported_symbols exported_symbols() const;
347 it_imported_symbols imported_symbols();
350 it_const_imported_symbols imported_symbols() const;
351 it_symtab_symbols symtab_symbols() {
354 return symtab_symbols_;
355 }
356
357 it_const_symtab_symbols symtab_symbols() const {
358 return symtab_symbols_;
359 }
360 it_symbols_version symbols_version() {
363 return symbol_version_table_;
364 }
365 it_const_symbols_version symbols_version() const {
366 return symbol_version_table_;
367 }
368 it_symbols_version_definition symbols_version_definition() {
371 return symbol_version_definition_;
372 }
373
374 it_const_symbols_version_definition symbols_version_definition() const {
375 return symbol_version_definition_;
376 }
377 it_symbols_version_requirement symbols_version_requirement() {
380 return symbol_version_requirements_;
381 }
382
383 it_const_symbols_version_requirement symbols_version_requirement() const {
384 return symbol_version_requirements_;
385 }
386 it_dynamic_relocations dynamic_relocations();
389 it_const_dynamic_relocations dynamic_relocations() const;
390 Relocation& add_dynamic_relocation(const Relocation& relocation);
397 Relocation& add_pltgot_relocation(const Relocation& relocation);
403 Relocation* add_object_relocation(const Relocation& relocation, const Section& section);
412 it_pltgot_relocations pltgot_relocations();
415 it_const_pltgot_relocations pltgot_relocations() const;
416 it_object_relocations object_relocations();
419 it_const_object_relocations object_relocations() const;
420 it_relocations relocations() {
423 return relocations_;
424 }
425
426 it_const_relocations relocations() const {
427 return relocations_;
428 }
429 const Relocation* get_relocation(uint64_t address) const;
433 Relocation* get_relocation(uint64_t address) {
434 return const_cast<Relocation*>(static_cast<const Binary*>(this)->get_relocation(address));
435 }
436 const Relocation* get_relocation(const Symbol& symbol) const;
440 Relocation* get_relocation(const Symbol& symbol) {
441 return const_cast<Relocation*>(static_cast<const Binary*>(this)->get_relocation(symbol));
442 }
443 const Relocation* get_relocation(const std::string& symbol_name) const;
447 Relocation* get_relocation(const std::string& symbol_name) {
448 return const_cast<Relocation*>(static_cast<const Binary*>(this)->get_relocation(symbol_name));
449 }
450 bool use_gnu_hash() const {
455 return gnu_hash_ != nullptr && has(DynamicEntry::TAG::GNU_HASH);
456 }
457 const GnuHash* gnu_hash() const {
461 return use_gnu_hash() ? gnu_hash_.get() : nullptr;
462 }
463 bool use_sysv_hash() const {
468 return sysv_hash_ != nullptr && has(DynamicEntry::TAG::HASH);
469 }
470 const SysvHash* sysv_hash() const {
474 return use_sysv_hash() ? sysv_hash_.get() : nullptr;
475 }
476 bool has_section(const std::string& name) const {
479 return get_section(name) != nullptr;
480 }
481 bool has_section_with_offset(uint64_t offset) const;
484 bool has_section_with_va(uint64_t va) const;
487 Section* get_section(const std::string& name) {
491 return const_cast<Section*>(static_cast<const Binary*>(this)->get_section(name));
492 }
493 const Section* get_section(const std::string& name) const;
494 Section* text_section() {
498 return get_section(".text");
499 }
500 Section* dynamic_section();
504 Section* hash_section();
508 Section* symtab_symbols_section();
512 uint64_t imagebase() const override;
518 uint64_t virtual_size() const;
521 bool has_interpreter() const;
525 const std::string& interpreter() const {
531 return interpreter_;
532 }
533 void interpreter(const std::string& interpreter) {
536 interpreter_ = interpreter;
537 }
538 it_symbols symbols() {
541 return symtab_dyn_symbols();
542 }
543
544 it_const_symbols symbols() const {
545 return symtab_dyn_symbols();
546 }
547 Symbol& export_symbol(const Symbol& symbol);
550 Symbol& export_symbol(const std::string& symbol_name, uint64_t value = 0);
553 bool has_dynamic_symbol(const std::string& name) const {
556 return get_dynamic_symbol(name) != nullptr;
557 }
558 const Symbol* get_dynamic_symbol(const std::string& name) const;
562
563 Symbol* get_dynamic_symbol(const std::string& name) {
564 return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_dynamic_symbol(name));
565 }
566 bool has_symtab_symbol(const std::string& name) const {
569 return get_symtab_symbol(name) != nullptr;
570 }
571 const Symbol* get_symtab_symbol(const std::string& name) const;
575
576 Symbol* get_symtab_symbol(const std::string& name) {
577 return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_symtab_symbol(name));
578 }
579 string_list_t strings(size_t min_size = 5) const;
584 void remove_symbol(const std::string& name);
591 void remove_symtab_symbol(const std::string& name);
594 void remove_symtab_symbol(Symbol* symbol);
595 void remove_dynamic_symbol(const std::string& name);
598 void remove_dynamic_symbol(Symbol* symbol);
605 result<uint64_t> get_function_address(const std::string& func_name) const override;
608 // result<uint64_t> get_function_address(const std::string& func_name, bool demangled) const;
614 Section* add(const Section& section, bool loaded = true,
626 SEC_INSERT_POS pos = SEC_INSERT_POS::AUTO);
627
628 Section* extend(const Section& section, uint64_t size);
629 Symbol& add_symtab_symbol(const Symbol& symbol);
632 Symbol& add_dynamic_symbol(const Symbol& symbol, const SymbolVersion* version = nullptr);
635 Symbol& add_exported_function(uint64_t address, const std::string& name = "");
638 DynamicEntryLibrary& add_library(const std::string& library_name);
641 void remove_library(const std::string& library_name);
644 DynamicEntryLibrary* get_library(const std::string& library_name) {
648 return const_cast<DynamicEntryLibrary*>(static_cast<const Binary*>(this)->get_library(library_name));
649 }
650 const DynamicEntryLibrary* get_library(const std::string& library_name) const;
654 bool has_library(const std::string& name) const {
657 return get_library(name) != nullptr;
658 }
659 Segment* add(const Segment& segment, uint64_t base = 0);
668 Segment* replace(const Segment& new_segment, const Segment& original_segment, uint64_t base = 0);
673
674 Segment* extend(const Segment& segment, uint64_t size);
675
676 void patch_address(uint64_t address, const std::vector<uint8_t>& patch_value,
683 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
684
685 void patch_address(uint64_t address, uint64_t patch_value,
693 size_t size = sizeof(uint64_t),
694 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
695 void patch_pltgot(const Symbol& symbol, uint64_t address);
701
702 void patch_pltgot(const std::string& symbol_name, uint64_t address);
708 void strip();
711 void remove_section(const std::string& name, bool clear = false) override;
717 void write(const std::string& filename);
725 void write(const std::string& filename, Builder::config_t config);
734 void write(std::ostream& os);
742 void write(std::ostream& os, Builder::config_t config);
748 std::vector<uint8_t> raw();
751 result<uint64_t> virtual_address_to_offset(uint64_t virtual_address) const;
754 result<uint64_t> offset_to_virtual_address(uint64_t offset, uint64_t slide = 0) const override;
760 bool is_pie() const override;
766 bool has_nx() const override;
769 int64_t dynsym_idx(const std::string& name) const;
773
774 int64_t dynsym_idx(const Symbol& sym) const;
775 int64_t symtab_idx(const std::string& name) const;
778
779 int64_t symtab_idx(const Symbol& sym) const;
780 const Section* section_from_offset(uint64_t offset, bool skip_nobits = true) const;
787 Section* section_from_offset(uint64_t offset, bool skip_nobits = true) {
788 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_offset(offset, skip_nobits));
789 }
790 const Section* section_from_virtual_address(uint64_t address, bool skip_nobits = true) const;
797 Section* section_from_virtual_address(uint64_t address, bool skip_nobits = true) {
798 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_virtual_address(address, skip_nobits));
799 }
800 const Segment* segment_from_virtual_address(uint64_t address) const;
804 Segment* segment_from_virtual_address(uint64_t address) {
805 return const_cast<Segment*>(static_cast<const Binary*>(this)->segment_from_virtual_address(address));
806 }
807
808
809 const Segment* segment_from_virtual_address(Segment::TYPE type, uint64_t address) const;
810 Segment* segment_from_virtual_address(Segment::TYPE type, uint64_t address) {
811 return const_cast<Segment*>(static_cast<const Binary*>(this)->segment_from_virtual_address(type, address));
812 }
813 const Segment* segment_from_offset(uint64_t offset) const;
817 Segment* segment_from_offset(uint64_t offset) {
818 return const_cast<Segment*>(static_cast<const Binary*>(this)->segment_from_offset(offset));
819 }
820 const DynamicEntry* get(DynamicEntry::TAG tag) const;
824 DynamicEntry* get(DynamicEntry::TAG tag) {
825 return const_cast<DynamicEntry*>(static_cast<const Binary*>(this)->get(tag));
826 }
827 const Segment* get(Segment::TYPE type) const;
831 Segment* get(Segment::TYPE type) {
832 return const_cast<Segment*>(static_cast<const Binary*>(this)->get(type));
833 }
834 const Note* get(Note::TYPE type) const;
838 Note* get(Note::TYPE type) {
839 return const_cast<Note*>(static_cast<const Binary*>(this)->get(type));
840 }
841 const Section* get(Section::TYPE type) const;
845 Section* get(Section::TYPE type) {
846 return const_cast<Section*>(static_cast<const Binary*>(this)->get(type));
847 }
848 bool has(DynamicEntry::TAG tag) const {
851 return get(tag) != nullptr;
852 }
853 bool has(Segment::TYPE type) const {
856 return get(type) != nullptr;
857 }
858 bool has(Note::TYPE type) const {
861 return get(type) != nullptr;
862 }
863 bool has(Section::TYPE type) const {
866 return get(type) != nullptr;
867 }
868 span<const uint8_t> get_content_from_virtual_address(uint64_t virtual_address, uint64_t size,
871 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO) const override;
872 void accept(LIEF::Visitor& visitor) const override;
875 void permute_dynamic_symbols(const std::vector<size_t>& permutation);
878 LIEF::Binary::functions_t ctor_functions() const override;
881 LIEF::Binary::functions_t dtor_functions() const;
884 LIEF::Binary::functions_t functions() const;
887 bool has_notes() const;
890 it_const_notes notes() const {
895 return notes_;
896 }
897
898 it_notes notes() {
899 return notes_;
900 }
901 uint64_t eof_offset() const;
905 bool has_overlay() const {
908 return !overlay_.empty();
909 }
910 span<const uint8_t> overlay() const {
913 return overlay_;
914 }
915 void overlay(std::vector<uint8_t> overlay) {
918 overlay_ = std::move(overlay);
919 }
920 uint64_t relocate_phdr_table(PHDR_RELOC type);
930 std::vector<uint64_t> get_relocated_dynamic_array(DynamicEntry::TAG tag) const;
934 bool is_targeting_android() const;
937 result<size_t> get_section_idx(const Section& section) const {
940 auto it = std::find_if(sections_.begin(), sections_.end(),
941 [&section] (const std::unique_ptr<Section>& S) {
942 return S.get() == &section;
943 }
944 );
945 if (it == sections_.end()) {
946 return make_error_code(lief_errors::not_found);
947 }
948 return std::distance(sections_.begin(), it);
949 }
950 result<size_t> get_section_idx(const std::string& name) const {
953 auto it = std::find_if(sections_.begin(), sections_.end(),
954 [name] (const std::unique_ptr<Section>& S) {
955 return S->name() == name;
956 }
957 );
958 if (it == sections_.end()) {
959 return make_error_code(lief_errors::not_found);
960 }
961 return std::distance(sections_.begin(), it);
962 }
963
964 uint8_t ptr_size() const {
965 switch (type()) {
966 case Header::CLASS::ELF32:
967 return sizeof(uint32_t);
968 case Header::CLASS::ELF64:
969 return sizeof(uint64_t);
970 default:
971 return 0;
972 }
973 return 0;
974 }
975
976 static bool classof(const LIEF::Binary* bin) {
977 return bin->format() == Binary::FORMATS::ELF ||
978 bin->format() == Binary::FORMATS::OAT;
979 }
980
981 size_t hash(const std::string& name);
982
983 ~Binary() override;
984
985 std::ostream& print(std::ostream& os) const override;
986
987 Binary& operator+=(const DynamicEntry& entry) {
988 add(entry);
989 return *this;
990 }
991 Binary& operator+=(const Section& section) {
992 add(section);
993 return *this;
994 }
995
996 Binary& operator+=(const Segment& segment) {
997 add(segment);
998 return *this;
999 }
1000
1001 Binary& operator+=(const Note& note) {
1002 add(note);
1003 return *this;
1004 }
1005
1006 Binary& operator-=(const DynamicEntry& entry) {
1007 remove(entry);
1008 return *this;
1009 }
1010
1011 Binary& operator-=(DynamicEntry::TAG tag) {
1012 remove(tag);
1013 return *this;
1014 }
1015
1016 Binary& operator-=(const Note& note) {
1017 remove(note);
1018 return *this;
1019 }
1020
1021 Binary& operator-=(Note::TYPE type) {
1022 remove(type);
1023 return *this;
1024 }
1025
1026 Segment* operator[](Segment::TYPE type) {
1027 return get(type);
1028 }
1029
1030 const Segment* operator[](Segment::TYPE type) const {
1031 return get(type);
1032 }
1033
1034 DynamicEntry* operator[](DynamicEntry::TAG tag) {
1035 return get(tag);
1036 }
1037
1038 const DynamicEntry* operator[](DynamicEntry::TAG tag) const {
1039 return get(tag);
1040 }
1041
1042 Note* operator[](Note::TYPE type) {
1043 return get(type);
1044 }
1045
1046 const Note* operator[](Note::TYPE type) const {
1047 return get(type);
1048 }
1049
1050 Section* operator[](Section::TYPE type) {
1051 return get(type);
1052 }
1053
1054 const Section* operator[](Section::TYPE type) const {
1055 return get(type);
1056 }
1057
1058 protected:
1059 struct phdr_relocation_info_t {
1060 uint64_t new_offset = 0;
1061 size_t nb_segments = 0;
1062 void clear() {
1063 new_offset = 0;
1064 nb_segments = 0;
1065 }
1066 };
1067 LIEF_LOCAL Binary();
1068 LIEF_LOCAL LIEF::Binary::sections_t get_abstract_sections() override;
1071
1072 LIEF_LOCAL LIEF::Header get_abstract_header() const override {
1073 return LIEF::Header::from(*this);
1074 }
1075
1076 LIEF_LOCAL LIEF::Binary::functions_t get_abstract_exported_functions() const override;
1077 LIEF_LOCAL LIEF::Binary::functions_t get_abstract_imported_functions() const override;
1078 LIEF_LOCAL std::vector<std::string> get_abstract_imported_libraries() const override;
1079 LIEF_LOCAL LIEF::Binary::symbols_t get_abstract_symbols() override;
1080 LIEF_LOCAL LIEF::Binary::relocations_t get_abstract_relocations() override;
1081
1082 template<ELF::ARCH ARCH>
1083 LIEF_LOCAL void patch_relocations(uint64_t from, uint64_t shift);
1084
1085 template<class T>
1086 LIEF_LOCAL void patch_addend(Relocation& relocatio, uint64_t from, uint64_t shift);
1087
1088 LIEF_LOCAL void shift_sections(uint64_t from, uint64_t shift);
1089 LIEF_LOCAL void shift_segments(uint64_t from, uint64_t shift);
1090 LIEF_LOCAL void shift_dynamic_entries(uint64_t from, uint64_t shift);
1091 LIEF_LOCAL void shift_symbols(uint64_t from, uint64_t shift);
1092 LIEF_LOCAL void shift_relocations(uint64_t from, uint64_t shift);
1093
1094 template<class ELF_T>
1095 LIEF_LOCAL void fix_got_entries(uint64_t from, uint64_t shift);
1096
1097 LIEF_LOCAL LIEF::Binary::functions_t eh_frame_functions() const;
1098 LIEF_LOCAL LIEF::Binary::functions_t armexid_functions() const;
1099
1100 template<Header::FILE_TYPE OBJECT_TYPE, bool note = false>
1101 LIEF_LOCAL Segment* add_segment(const Segment& segment, uint64_t base);
1102
1103 LIEF_LOCAL uint64_t relocate_phdr_table_auto();
1104 LIEF_LOCAL uint64_t relocate_phdr_table_pie();
1105 LIEF_LOCAL uint64_t relocate_phdr_table_v1();
1106 LIEF_LOCAL uint64_t relocate_phdr_table_v2();
1107 LIEF_LOCAL uint64_t relocate_phdr_table_v3();
1108
1109 template<Segment::TYPE PT>
1110 LIEF_LOCAL Segment* extend_segment(const Segment& segment, uint64_t size);
1111
1112 template<bool LOADED>
1113 LIEF_LOCAL Section* add_section(const Section& section, SEC_INSERT_POS pos);
1114
1115 std::vector<Symbol*> symtab_dyn_symbols() const;
1116
1117 LIEF_LOCAL std::string shstrtab_name() const;
1118 LIEF_LOCAL Section* add_frame_section(const Section& sec);
1119 LIEF_LOCAL Section* add_section(std::unique_ptr<Section> sec);
1120
1121 LIEF_LOCAL LIEF::Binary::functions_t tor_functions(DynamicEntry::TAG tag) const;
1122
1123 Header::CLASS type_ = Header::CLASS::NONE;
1124 Header header_;
1125 sections_t sections_;
1126 segments_t segments_;
1127 dynamic_entries_t dynamic_entries_;
1128 symbols_t dynamic_symbols_;
1129 symbols_t symtab_symbols_;
1130 relocations_t relocations_;
1131 symbols_version_t symbol_version_table_;
1132 symbols_version_requirement_t symbol_version_requirements_;
1133 symbols_version_definition_t symbol_version_definition_;
1134 notes_t notes_;
1135 std::unique_ptr<GnuHash> gnu_hash_;
1136 std::unique_ptr<SysvHash> sysv_hash_;
1137 std::unique_ptr<DataHandler::Handler> datahandler_;
1138 phdr_relocation_info_t phdr_reloc_info_;
1139
1140 std::string interpreter_;
1141 std::vector<uint8_t> overlay_;
1142 std::unique_ptr<sizing_info_t> sizing_info_;
1143};
1144
1145}
1146}
1147#endif
Binary.hpp
DynamicEntry.hpp
Builder.hpp
Header.hpp
Section.hpp
Note.hpp
Segment.hpp
LIEF::Binary::functions_t
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:67
LIEF::Binary::format
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:109
LIEF::Binary::symbols_t
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:79
LIEF::Binary::VA_TYPES
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:53
LIEF::Binary::VA_TYPES::AUTO
@ AUTO
Try to guess if it's relative or not.
Definition Abstract/Binary.hpp:54
LIEF::Binary::sections_t
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:70
LIEF::Binary::relocations_t
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:88
LIEF::ELF::Binary
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
LIEF::ELF::Binary::~Binary
~Binary() override
LIEF::ELF::Binary::add
Segment * add(const Segment &segment, uint64_t base=0)
Add a new segment in the binary.
LIEF::ELF::Binary::use_gnu_hash
bool use_gnu_hash() const
true if GNU hash is used
Definition ELF/Binary.hpp:454
LIEF::ELF::Binary::get
const DynamicEntry * get(DynamicEntry::TAG tag) const
Return the first ELF::DynamicEntry associated with the given tag If the tag can't be found,...
LIEF::ELF::Binary::type
Header::CLASS type() const
Return binary's class (ELF32 or ELF64)
Definition ELF/Binary.hpp:250
LIEF::ELF::Binary::virtual_address_to_offset
result< uint64_t > virtual_address_to_offset(uint64_t virtual_address) const
Convert a virtual address to a file offset.
LIEF::ELF::Binary::symbols
it_const_symbols symbols() const
Definition ELF/Binary.hpp:544
LIEF::ELF::Binary::last_offset_section
uint64_t last_offset_section() const
Return the last offset used in binary according to sections table.
LIEF::ELF::Binary::get_content_from_virtual_address
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.
LIEF::ELF::Binary::header
Header & header()
Return Elf header .
Definition ELF/Binary.hpp:255
LIEF::ELF::Binary::section_from_offset
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.
LIEF::ELF::Binary::dynamic_entries
it_dynamic_entries dynamic_entries()
Return binary's dynamic entries.
Definition ELF/Binary.hpp:298
LIEF::ELF::Binary::symbols_version_requirement
it_symbols_version_requirement symbols_version_requirement()
Return Symbol version requirement.
Definition ELF/Binary.hpp:379
LIEF::ELF::Binary::hash
size_t hash(const std::string &name)
LIEF::ELF::Binary::dynamic_relocations
it_const_dynamic_relocations dynamic_relocations() const
LIEF::ELF::Binary::pltgot_relocations
it_pltgot_relocations pltgot_relocations()
Return plt.got relocations.
LIEF::ELF::Binary::strip
void strip()
Strip the binary by removing symtab symbols.
LIEF::ELF::Binary::add
Note & add(const Note &note)
Add the given note and return the created entry.
LIEF::ELF::Binary::export_symbol
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.
LIEF::ELF::Binary::remove_symtab_symbol
void remove_symtab_symbol(Symbol *symbol)
LIEF::ELF::Binary::operator+=
Binary & operator+=(const DynamicEntry &entry)
Definition ELF/Binary.hpp:987
LIEF::ELF::Binary::remove
void remove(const Note &note)
Remove the given note.
LIEF::ELF::Binary::operator[]
const Note * operator[](Note::TYPE type) const
Definition ELF/Binary.hpp:1046
LIEF::ELF::Binary::has_notes
bool has_notes() const
true if the binary embeds notes
LIEF::ELF::Binary::dynsym_idx
int64_t dynsym_idx(const std::string &name) const
Symbol index in the dynamic symbol table or -1 if the symbol does not exist.
LIEF::ELF::Binary::segment_from_virtual_address
Segment * segment_from_virtual_address(uint64_t address)
Definition ELF/Binary.hpp:804
LIEF::ELF::Binary::get_relocation
const Relocation * get_relocation(const Symbol &symbol) const
Return relocation associated with the given Symbol It returns a nullptr if it is not found.
LIEF::ELF::Binary::remove_dynamic_symbol
void remove_dynamic_symbol(const std::string &name)
Remove dynamic symbols with the given name.
LIEF::ELF::Binary::operator-=
Binary & operator-=(const Note &note)
Definition ELF/Binary.hpp:1016
LIEF::ELF::Binary::section_from_virtual_address
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.
LIEF::ELF::Binary::get_relocation
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.
LIEF::ELF::Binary::symtab_symbols
it_symtab_symbols symtab_symbols()
Return the debug symbols from the .symtab section.
Definition ELF/Binary.hpp:353
LIEF::ELF::Binary::ctor_functions
LIEF::Binary::functions_t ctor_functions() const override
List of binary constructors (typically, the functions located in the .init_array)
LIEF::ELF::Binary::imagebase
uint64_t imagebase() const override
Return program image base. For instance 0x40000
LIEF::ELF::Binary::functions
LIEF::Binary::functions_t functions() const
List of the functions found the in the binary.
LIEF::ELF::Binary::has_library
bool has_library(const std::string &name) const
Check if the given library name exists in the current binary.
Definition ELF/Binary.hpp:656
LIEF::ELF::Binary::dynsym_idx
int64_t dynsym_idx(const Symbol &sym) const
LIEF::ELF::Binary::dtor_functions
LIEF::Binary::functions_t dtor_functions() const
List of the binary destructors (typically, the functions located in the .fini_array)
LIEF::ELF::Binary::operator[]
Segment * operator[](Segment::TYPE type)
Definition ELF/Binary.hpp:1026
LIEF::ELF::Binary::get_dynamic_symbol
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.
LIEF::ELF::Binary::get_relocation
Relocation * get_relocation(uint64_t address)
Definition ELF/Binary.hpp:433
LIEF::ELF::Binary::segment_from_virtual_address
const Segment * segment_from_virtual_address(Segment::TYPE type, uint64_t address) const
LIEF::ELF::Binary::get_library
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:647
LIEF::ELF::Binary::is_pie
bool is_pie() const override
Check if the binary has been compiled with -fpie -pie flags.
LIEF::ELF::Binary::get_symtab_symbol
Symbol * get_symtab_symbol(const std::string &name)
Definition ELF/Binary.hpp:576
LIEF::ELF::Binary::symbols_version
it_symbols_version symbols_version()
Return the symbol versions.
Definition ELF/Binary.hpp:362
LIEF::ELF::Binary::add_library
DynamicEntryLibrary & add_library(const std::string &library_name)
Add a library as dependency.
LIEF::ELF::Binary::text_section
Section * text_section()
Return the .text section. If the section can't be found, it returns a nullptr.
Definition ELF/Binary.hpp:497
LIEF::ELF::Binary::object_relocations
it_object_relocations object_relocations()
Return relocations used in an object file (*.o)
LIEF::ELF::Binary::get_section
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:490
LIEF::ELF::Binary::imported_symbols
it_imported_symbols imported_symbols()
Return symbols which are imported by the binary.
LIEF::ELF::Binary::sections
it_sections sections()
Return an iterator over the binary's sections.
Definition ELF/Binary.hpp:275
LIEF::ELF::Binary::notes
it_const_notes notes() const
Return an iterator over the ELF's LIEF::ELF::Note.
Definition ELF/Binary.hpp:894
LIEF::ELF::Binary::patch_address
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.
LIEF::ELF::Binary::symbols_version_definition
it_symbols_version_definition symbols_version_definition()
Return symbols version definition.
Definition ELF/Binary.hpp:370
LIEF::ELF::Binary::object_relocations
it_const_object_relocations object_relocations() const
LIEF::ELF::Binary::get_symtab_symbol
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.
LIEF::ELF::Binary::dynamic_relocations
it_dynamic_relocations dynamic_relocations()
Return dynamic relocations.
LIEF::ELF::Binary::overlay
void overlay(std::vector< uint8_t > overlay)
Function to set the overlay.
Definition ELF/Binary.hpp:917
LIEF::ELF::Binary::get
Note * get(Note::TYPE type)
Definition ELF/Binary.hpp:838
LIEF::ELF::Binary::remove_dynamic_symbol
void remove_dynamic_symbol(Symbol *symbol)
Remove the given symbol from the dynamic symbols table.
LIEF::ELF::Binary::overlay
span< const uint8_t > overlay() const
Overlay data (if any)
Definition ELF/Binary.hpp:912
LIEF::ELF::Binary::has_overlay
bool has_overlay() const
True if data are present at the end of the binary.
Definition ELF/Binary.hpp:907
LIEF::ELF::Binary::has
bool has(Section::TYPE type) const
Check if a ELF::Section associated with the given type exists.
Definition ELF/Binary.hpp:865
LIEF::ELF::Binary::print
std::ostream & print(std::ostream &os) const override
LIEF::ELF::Binary::get_relocation
Relocation * get_relocation(const std::string &symbol_name)
Definition ELF/Binary.hpp:447
LIEF::ELF::Binary::add_dynamic_symbol
Symbol & add_dynamic_symbol(const Symbol &symbol, const SymbolVersion *version=nullptr)
Add a dynamic symbol with the associated SymbolVersion.
LIEF::ELF::Binary::add_symtab_symbol
Symbol & add_symtab_symbol(const Symbol &symbol)
Add a symtab symbol.
LIEF::ELF::Binary::operator+=
Binary & operator+=(const Section &section)
Definition ELF/Binary.hpp:991
LIEF::ELF::Binary::get_section
const Section * get_section(const std::string &name) const
LIEF::ELF::Binary::interpreter
void interpreter(const std::string &interpreter)
Change the interpreter.
Definition ELF/Binary.hpp:535
LIEF::ELF::Binary::Binary
Binary(const Binary &copy)=delete
LIEF::ELF::Binary::symtab_idx
int64_t symtab_idx(const Symbol &sym) const
LIEF::ELF::Binary::operator[]
const Segment * operator[](Segment::TYPE type) const
Definition ELF/Binary.hpp:1030
LIEF::ELF::Binary::sections
it_const_sections sections() const
Definition ELF/Binary.hpp:279
LIEF::ELF::Binary::get_section_idx
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:952
LIEF::ELF::Binary::add_object_relocation
Relocation * add_object_relocation(const Relocation &relocation, const Section &section)
Add relocation for object file (.o)
LIEF::ELF::Binary::virtual_size
uint64_t virtual_size() const
Return the size of the mapped binary.
LIEF::ELF::Binary::exported_symbols
it_exported_symbols exported_symbols()
Return symbols which are exported by the binary.
LIEF::ELF::Binary::header
const Header & header() const
Definition ELF/Binary.hpp:259
LIEF::ELF::Binary::symtab_symbols
it_const_symtab_symbols symtab_symbols() const
Definition ELF/Binary.hpp:357
LIEF::ELF::Binary::get_section_idx
result< size_t > get_section_idx(const Section &section) const
Find the index of the section given in the first parameter.
Definition ELF/Binary.hpp:939
LIEF::ELF::Binary::extend
Section * extend(const Section &section, uint64_t size)
LIEF::ELF::Binary::get
const Segment * get(Segment::TYPE type) const
Return the first ELF::Segment associated with the given type. If a segment can't be found,...
LIEF::ELF::Binary::entrypoint
uint64_t entrypoint() const override
Return the binary's entrypoint.
Definition ELF/Binary.hpp:284
LIEF::ELF::Binary::write
void write(const std::string &filename)
Reconstruct the binary object and write it in filename
LIEF::ELF::Binary::has
bool has(Note::TYPE type) const
Check if a ELF::Note associated with the given type exists.
Definition ELF/Binary.hpp:860
LIEF::ELF::Binary::segment_from_offset
Segment * segment_from_offset(uint64_t offset)
Definition ELF/Binary.hpp:817
LIEF::ELF::Binary::has_symtab_symbol
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:568
LIEF::ELF::Binary::has_dynamic_symbol
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:555
LIEF::ELF::Binary::operator[]
DynamicEntry * operator[](DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:1034
LIEF::ELF::Binary::offset_to_virtual_address
result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const override
Convert the given offset into a virtual address.
LIEF::ELF::Binary::symbols_version_definition
it_const_symbols_version_definition symbols_version_definition() const
Definition ELF/Binary.hpp:374
LIEF::ELF::Binary::get
const Section * get(Section::TYPE type) const
Return the first ELF::Section associated with the given type If a section can't be found,...
LIEF::ELF::Binary::hash_section
Section * hash_section()
Return the hash section. If the section can't be found, it returns a nullptr.
LIEF::ELF::Binary::next_virtual_address
uint64_t next_virtual_address() const
Return the next virtual address available.
LIEF::ELF::Binary::exported_symbols
it_const_exported_symbols exported_symbols() const
LIEF::ELF::Binary::segment_from_virtual_address
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.
LIEF::ELF::Binary::operator-=
Binary & operator-=(const DynamicEntry &entry)
Definition ELF/Binary.hpp:1006
LIEF::ELF::Binary::eof_offset
uint64_t eof_offset() const
Return the last offset used by the ELF binary according to both: the sections table and the segments ...
LIEF::ELF::Binary::remove
void remove(DynamicEntry::TAG tag)
Remove all dynamic entries with the given tag.
LIEF::ELF::Binary::segments
it_segments segments()
Return binary's segments.
Definition ELF/Binary.hpp:289
LIEF::ELF::Binary::remove_library
void remove_library(const std::string &library_name)
Remove the given library from the dependencies.
LIEF::ELF::Binary::get_function_address
result< uint64_t > get_function_address(const std::string &func_name, bool demangled) const
Return the address of the given function name.
LIEF::ELF::Binary::dynamic_symbols
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:336
LIEF::ELF::Binary::dynamic_entries
it_const_dynamic_entries dynamic_entries() const
Definition ELF/Binary.hpp:302
LIEF::ELF::Binary::remove_symtab_symbol
void remove_symtab_symbol(const std::string &name)
Remove symtabl symbols with the given name.
LIEF::ELF::Binary::operator-=
Binary & operator-=(DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:1011
LIEF::ELF::Binary::relocations
it_relocations relocations()
Return all relocations present in the binary.
Definition ELF/Binary.hpp:422
LIEF::ELF::Binary::dynamic_section
Section * dynamic_section()
Return the .dynamic section. If the section can't be found, it returns a nullptr.
LIEF::ELF::Binary::get
Segment * get(Segment::TYPE type)
Definition ELF/Binary.hpp:831
LIEF::ELF::Binary::get_library
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,...
LIEF::ELF::Binary::ptr_size
uint8_t ptr_size() const
Definition ELF/Binary.hpp:964
LIEF::ELF::Binary::operator[]
const DynamicEntry * operator[](DynamicEntry::TAG tag) const
Definition ELF/Binary.hpp:1038
LIEF::ELF::Binary::symbols
it_symbols symbols()
Return an iterator on both static and dynamic symbols.
Definition ELF/Binary.hpp:540
LIEF::ELF::Binary::relocate_phdr_table
uint64_t relocate_phdr_table(PHDR_RELOC type)
Force relocating the segments table in a specific way.
LIEF::ELF::Binary::replace
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...
LIEF::ELF::Binary::remove
void remove(const Section &section, bool clear=false)
Remove the given section. The clear parameter can be used to zeroize the original content beforehand.
LIEF::ELF::Binary::get_dynamic_symbol
Symbol * get_dynamic_symbol(const std::string &name)
Definition ELF/Binary.hpp:563
LIEF::ELF::Binary::operator[]
Section * operator[](Section::TYPE type)
Definition ELF/Binary.hpp:1050
LIEF::ELF::Binary::dynamic_symbols
it_const_dynamic_symbols dynamic_symbols() const
Definition ELF/Binary.hpp:340
LIEF::ELF::Binary::has_section_with_offset
bool has_section_with_offset(uint64_t offset) const
Check if a section that handles the given offset exists.
LIEF::ELF::Binary::strings
string_list_t strings(size_t min_size=5) const
Return list of the strings used by the ELF binary.
LIEF::ELF::Binary::remove_section
void remove_section(const std::string &name, bool clear=false) override
Remove a binary's section.
LIEF::ELF::Binary::raw
std::vector< uint8_t > raw()
Reconstruct the binary object and return its content as a byte vector.
LIEF::ELF::Binary::sysv_hash
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:473
LIEF::ELF::Binary::has_section
bool has_section(const std::string &name) const
Check if a section with the given name exists in the binary.
Definition ELF/Binary.hpp:478
LIEF::ELF::Binary::get_relocation
Relocation * get_relocation(const Symbol &symbol)
Definition ELF/Binary.hpp:440
LIEF::ELF::Binary::section_from_offset
Section * section_from_offset(uint64_t offset, bool skip_nobits=true)
Definition ELF/Binary.hpp:787
LIEF::ELF::Binary::get
Section * get(Section::TYPE type)
Definition ELF/Binary.hpp:845
LIEF::ELF::Binary::classof
static bool classof(const LIEF::Binary *bin)
Definition ELF/Binary.hpp:976
LIEF::ELF::Binary::relocations
it_const_relocations relocations() const
Definition ELF/Binary.hpp:426
LIEF::ELF::Binary::operator-=
Binary & operator-=(Note::TYPE type)
Definition ELF/Binary.hpp:1021
LIEF::ELF::Binary::add_exported_function
Symbol & add_exported_function(uint64_t address, const std::string &name="")
Create a symbol for the function at the given address and export it.
LIEF::ELF::Binary::is_targeting_android
bool is_targeting_android() const
True if the current ELF is targeting Android.
LIEF::ELF::Binary::segments
it_const_segments segments() const
Definition ELF/Binary.hpp:293
LIEF::ELF::Binary::get
DynamicEntry * get(DynamicEntry::TAG tag)
Definition ELF/Binary.hpp:824
LIEF::ELF::Binary::symtab_symbols_section
Section * symtab_symbols_section()
Return section which holds the symtab symbols. If the section can't be found, it returns a nullptr.
LIEF::ELF::Binary::last_offset_segment
uint64_t last_offset_segment() const
Return the last offset used in binary according to segments table.
LIEF::ELF::Binary::use_sysv_hash
bool use_sysv_hash() const
true if SYSV hash is used
Definition ELF/Binary.hpp:467
LIEF::ELF::Binary::patch_pltgot
void patch_pltgot(const Symbol &symbol, uint64_t address)
Patch the imported symbol with the address
LIEF::ELF::Binary::write
void write(std::ostream &os, Builder::config_t config)
Reconstruct the binary object with the given config and write it in os stream.
LIEF::ELF::Binary::has_interpreter
bool has_interpreter() const
Check if the binary uses a loader (also named linker or interpreter)
LIEF::ELF::Binary::get_relocation
const Relocation * get_relocation(uint64_t address) const
Return relocation associated with the given address. It returns a nullptr if it is not found.
LIEF::ELF::Binary::remove_symbol
void remove_symbol(const std::string &name)
Remove symbols with the given name in both:
LIEF::ELF::Binary::operator[]
const Section * operator[](Section::TYPE type) const
Definition ELF/Binary.hpp:1054
LIEF::ELF::Binary::segment_from_offset
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.
LIEF::ELF::Binary::section_from_virtual_address
Section * section_from_virtual_address(uint64_t address, bool skip_nobits=true)
Definition ELF/Binary.hpp:797
LIEF::ELF::Binary::remove
void remove(Note::TYPE type)
Remove all notes with the given type.
LIEF::ELF::Binary::add_dynamic_relocation
Relocation & add_dynamic_relocation(const Relocation &relocation)
Add a new dynamic relocation.
LIEF::ELF::Binary::interpreter
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:530
LIEF::ELF::Binary::symtab_idx
int64_t symtab_idx(const std::string &name) const
Symbol index from the .symtab section or -1 if the symbol is not present.
LIEF::ELF::Binary::extend
Segment * extend(const Segment &segment, uint64_t size)
LIEF::ELF::Binary::get_relocated_dynamic_array
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...
LIEF::ELF::Binary::pltgot_relocations
it_const_pltgot_relocations pltgot_relocations() const
LIEF::ELF::Binary::symbols_version_requirement
it_const_symbols_version_requirement symbols_version_requirement() const
Definition ELF/Binary.hpp:383
LIEF::ELF::Binary::notes
it_notes notes()
Definition ELF/Binary.hpp:898
LIEF::ELF::Binary::imported_symbols
it_const_imported_symbols imported_symbols() const
LIEF::ELF::Binary::patch_address
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.
LIEF::ELF::Binary::operator[]
Note * operator[](Note::TYPE type)
Definition ELF/Binary.hpp:1042
LIEF::ELF::Binary::operator+=
Binary & operator+=(const Segment &segment)
Definition ELF/Binary.hpp:996
LIEF::ELF::Binary::write
void write(const std::string &filename, Builder::config_t config)
Reconstruct the binary object with the given config and write it in filename
LIEF::ELF::Binary::operator=
Binary & operator=(const Binary &)=delete
LIEF::ELF::Binary::add
Section * add(const Section &section, bool loaded=true, SEC_INSERT_POS pos=SEC_INSERT_POS::AUTO)
Add a new section in the binary.
LIEF::ELF::Binary::segment_from_virtual_address
Segment * segment_from_virtual_address(Segment::TYPE type, uint64_t address)
Definition ELF/Binary.hpp:810
LIEF::ELF::Binary::permute_dynamic_symbols
void permute_dynamic_symbols(const std::vector< size_t > &permutation)
Apply the given permutation on the dynamic symbols table.
LIEF::ELF::Binary::has_section_with_va
bool has_section_with_va(uint64_t va) const
Check if a section that handles the given virtual address exists.
LIEF::ELF::Binary::patch_pltgot
void patch_pltgot(const std::string &symbol_name, uint64_t address)
Patch the imported symbol's name with the address
LIEF::ELF::Binary::accept
void accept(LIEF::Visitor &visitor) const override
Method associated with the visitor pattern.
LIEF::ELF::Binary::remove
void remove(const Segment &seg)
Remove the given segment.
LIEF::ELF::Binary::get
const Note * get(Note::TYPE type) const
Return the first ELF::Note associated with the given type If a note can't be found,...
LIEF::ELF::Binary::export_symbol
Symbol & export_symbol(const Symbol &symbol)
Export the given symbol and create it if it doesn't exist.
LIEF::ELF::Binary::symbols_version
it_const_symbols_version symbols_version() const
Definition ELF/Binary.hpp:365
LIEF::ELF::Binary::add_pltgot_relocation
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...
LIEF::ELF::Binary::operator+=
Binary & operator+=(const Note &note)
Definition ELF/Binary.hpp:1001
LIEF::ELF::Binary::get_function_address
result< uint64_t > get_function_address(const std::string &func_name) const override
Return the address of the given function name.
LIEF::ELF::Binary::gnu_hash
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:460
LIEF::ELF::Binary::write
void write(std::ostream &os)
Reconstruct the binary object and write it in os stream.
LIEF::ELF::Binary::has_nx
bool has_nx() const override
Check if the binary uses the NX protection (Non executable stack)
LIEF::ELF::Binary::remove
void remove(const DynamicEntry &entry)
Remove the given dynamic entry.
LIEF::ELF::Binary::add
DynamicEntry & add(const DynamicEntry &entry)
Add the given dynamic entry and return the new entry.
LIEF::ELF::Binary::has
bool has(Segment::TYPE type) const
Check if ELF::Segment associated with the given type exists.
Definition ELF/Binary.hpp:855
LIEF::ELF::Binary::has
bool has(DynamicEntry::TAG tag) const
Check if an ELF::DynamicEntry associated with the given tag exists.
Definition ELF/Binary.hpp:850
LIEF::ELF::DynamicEntryLibrary
Class which represents a DT_NEEDED entry in the dynamic table.
Definition DynamicEntryLibrary.hpp:29
LIEF::ELF::GnuHash
Class which provides a view over the GNU Hash implementation. Most of the fields are read-only since ...
Definition GnuHash.hpp:36
LIEF::ELF::Parser
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
LIEF::ELF::Relocation
Class that represents an ELF relocation.
Definition ELF/Relocation.hpp:40
LIEF::ELF::Section
Class wich represents an ELF Section.
Definition ELF/Section.hpp:48
LIEF::ELF::Segment
Class which represents the ELF segments.
Definition Segment.hpp:48
LIEF::ELF::SymbolVersionDefinition
Class which represents an entry defined in DT_VERDEF or .gnu.version_d
Definition SymbolVersionDefinition.hpp:37
LIEF::ELF::SymbolVersionRequirement
Class which represents an entry in the DT_VERNEED or .gnu.version_r table.
Definition SymbolVersionRequirement.hpp:39
LIEF::ELF::SymbolVersion
Class which represents an entry defined in the DT_VERSYM dynamic entry.
Definition SymbolVersion.hpp:32
LIEF::ELF::Symbol
Class which represents an ELF symbol.
Definition ELF/Symbol.hpp:35
LIEF::ELF::SysvHash
Class which represents the SYSV hash for the symbols resolution.
Definition SysvHash.hpp:39
LIEF::Header::from
static Header from(const LIEF::ELF::Binary &elf)
errors.hpp
lief_errors::not_found
@ not_found
Definition errors.hpp:25
make_error_code
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition errors.hpp:52
iterators.hpp
LIEF::ELF::DataHandler
Definition ELF/Binary.hpp:38
LIEF::ELF
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42