LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DynamicEntryArray.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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_DYNAMIC_ENTRY_ARRAY_H
17#define LIEF_ELF_DYNAMIC_ENTRY_ARRAY_H
18
19#include "LIEF/visibility.h"
21
22#include <vector>
23
24namespace LIEF {
25namespace ELF {
36 public:
37 using array_t = std::vector<uint64_t>;
38 using DynamicEntry::DynamicEntry;
39
41 DynamicEntryArray(DynamicEntry::TAG tag, array_t array) :
42 DynamicEntry(tag, 0),
43 array_(std::move(array))
44 {}
45
46 DynamicEntryArray& operator=(const DynamicEntryArray&) = default;
47 DynamicEntryArray(const DynamicEntryArray&) = default;
48
49 std::unique_ptr<DynamicEntry> clone() const override {
50 return std::unique_ptr<DynamicEntryArray>(new DynamicEntryArray(*this));
51 }
52 array_t& array() {
55 return array_;
56 }
57
58 const array_t& array() const {
59 return array_;
60 }
61 void array(const array_t& array) {
62 array_ = array;
63 }
64 DynamicEntryArray& insert(size_t pos, uint64_t function);
67 DynamicEntryArray& append(uint64_t function) {
70 array_.push_back(function);
71 return *this;
72 }
73 DynamicEntryArray& remove(uint64_t function);
76 size_t size() const {
79 return array_.size();
80 }
81
82 DynamicEntryArray& operator+=(uint64_t value) {
83 return append(value);
84 }
85
86 DynamicEntryArray& operator-=(uint64_t value) {
87 return remove(value);
88 }
89
90 const uint64_t& operator[](size_t idx) const;
91 uint64_t& operator[](size_t idx);
92
93 void accept(Visitor& visitor) const override;
94
95 std::ostream& print(std::ostream& os) const override;
96
97 ~DynamicEntryArray() override = default;
98
99 static bool classof(const DynamicEntry* entry) {
100 const DynamicEntry::TAG tag = entry->tag();
101 return tag == DynamicEntry::TAG::INIT_ARRAY ||
102 tag == DynamicEntry::TAG::FINI_ARRAY ||
103 tag == DynamicEntry::TAG::PREINIT_ARRAY;
104 }
105
106 private:
107 array_t array_;
108};
109}
110}
111
112#endif
DynamicEntry.hpp
LIEF::ELF::DynamicEntryArray
Class that represent an Array in the dynamic table. This entry is associated with constructors:
Definition DynamicEntryArray.hpp:35
LIEF::ELF::DynamicEntryArray::DynamicEntryArray
DynamicEntryArray()=delete
LIEF::ELF::DynamicEntryArray::DynamicEntryArray
DynamicEntryArray(DynamicEntry::TAG tag, array_t array)
Definition DynamicEntryArray.hpp:41
LIEF::ELF::DynamicEntryArray::remove
DynamicEntryArray & remove(uint64_t function)
Remove the given function.
LIEF::ELF::DynamicEntryArray::array
const array_t & array() const
Definition DynamicEntryArray.hpp:58
LIEF::ELF::DynamicEntryArray::DynamicEntryArray
DynamicEntryArray(const DynamicEntryArray &)=default
LIEF::ELF::DynamicEntryArray::classof
static bool classof(const DynamicEntry *entry)
Definition DynamicEntryArray.hpp:99
LIEF::ELF::DynamicEntryArray::operator[]
uint64_t & operator[](size_t idx)
LIEF::ELF::DynamicEntryArray::clone
std::unique_ptr< DynamicEntry > clone() const override
Definition DynamicEntryArray.hpp:49
LIEF::ELF::DynamicEntryArray::operator+=
DynamicEntryArray & operator+=(uint64_t value)
Definition DynamicEntryArray.hpp:82
LIEF::ELF::DynamicEntryArray::~DynamicEntryArray
~DynamicEntryArray() override=default
LIEF::ELF::DynamicEntryArray::operator-=
DynamicEntryArray & operator-=(uint64_t value)
Definition DynamicEntryArray.hpp:86
LIEF::ELF::DynamicEntryArray::print
std::ostream & print(std::ostream &os) const override
LIEF::ELF::DynamicEntryArray::append
DynamicEntryArray & append(uint64_t function)
Append the given function.
Definition DynamicEntryArray.hpp:69
LIEF::ELF::DynamicEntryArray::operator=
DynamicEntryArray & operator=(const DynamicEntryArray &)=default
LIEF::ELF::DynamicEntryArray::size
size_t size() const
Number of function registred in this array.
Definition DynamicEntryArray.hpp:78
LIEF::ELF::DynamicEntryArray::insert
DynamicEntryArray & insert(size_t pos, uint64_t function)
Insert the given function at pos
LIEF::ELF::DynamicEntryArray::operator[]
const uint64_t & operator[](size_t idx) const
LIEF::ELF::DynamicEntryArray::accept
void accept(Visitor &visitor) const override
LIEF::ELF::DynamicEntryArray::array
void array(const array_t &array)
Definition DynamicEntryArray.hpp:61
LIEF::ELF::DynamicEntryArray::array
array_t & array()
Return the array values (list of pointers)
Definition DynamicEntryArray.hpp:54
LIEF::ELF::DynamicEntry
Class which represents an entry in the dynamic table These entries are located in the ....
Definition DynamicEntry.hpp:36
LIEF::ELF::DynamicEntry::tag
TAG tag() const
Tag of the current entry. The most common tags are: DT_NEEDED, DT_INIT, ...
Definition DynamicEntry.hpp:205
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