LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
SymbolVersionRequirement.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_SYMBOL_VERSION_REQUIREMENTS_H
17#define LIEF_ELF_SYMBOL_VERSION_REQUIREMENTS_H
18
19#include <string_view>
20#include <cstdint>
21#include <memory>
22#include <ostream>
23#include <string>
24#include <vector>
25
26#include "LIEF/Object.hpp"
27#include "LIEF/iterators.hpp"
28#include "LIEF/visibility.h"
29
30
31namespace LIEF::ELF {
32class Parser;
34
35namespace details {
36struct Elf64_Verneed;
37struct Elf32_Verneed;
38}
39
42 friend class Parser;
43
44 public:
46 std::vector<std::unique_ptr<SymbolVersionAuxRequirement>>;
52
54 SymbolVersionRequirement(const details::Elf64_Verneed& header);
55 SymbolVersionRequirement(const details::Elf32_Verneed& header);
56 ~SymbolVersionRequirement() override = default;
57
61
66 uint16_t version() const {
67 return version_;
68 }
69
71 size_t cnt() const {
72 return aux_requirements_.size();
73 }
74
77 return aux_requirements_;
78 }
79
81 return aux_requirements_;
82 }
83
85 std::string_view name() const LIEF_LIFETIMEBOUND {
86 return name_;
87 }
88
89 void version(uint16_t version) {
90 version_ = version;
91 }
92
93 void name(const std::string& name) {
94 name_ = name;
95 }
96
99 const SymbolVersionAuxRequirement& aux_requirement
101
105 find_aux(const std::string& name) const LIEF_LIFETIMEBOUND;
106
108 find_aux(const std::string& name) LIEF_LIFETIMEBOUND {
109 return const_cast<SymbolVersionAuxRequirement*>(
110 static_cast<const SymbolVersionRequirement*>(this)->find_aux(name)
111 );
112 }
113
121 bool remove_aux_requirement(const std::string& name) {
123 return remove_aux_requirement(*aux);
124 }
125 return false;
126 }
127
136
137 void accept(Visitor& visitor) const override;
138
139 LIEF_API friend std::ostream& operator<<(std::ostream& os,
140 const SymbolVersionRequirement& symr) {
141 os << symr.version() << " " << symr.name();
142 return os;
143 }
144
145 private:
146 aux_requirement_t aux_requirements_;
147 uint16_t version_ = 0;
148 std::string name_;
149};
150
151}
152
153#endif
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Definition SymbolVersionAuxRequirement.hpp:33
std::string_view name() const
Return the library name associated with this requirement (e.g. libc.so.6).
Definition SymbolVersionRequirement.hpp:85
void accept(Visitor &visitor) const override
size_t cnt() const
Number of auxiliary entries.
Definition SymbolVersionRequirement.hpp:71
void swap(SymbolVersionRequirement &other)
std::vector< std::unique_ptr< SymbolVersionAuxRequirement > > aux_requirement_t
Definition SymbolVersionRequirement.hpp:45
const_ref_iterator< const aux_requirement_t &, const SymbolVersionAuxRequirement * > it_const_aux_requirement
Definition SymbolVersionRequirement.hpp:49
bool remove_aux_requirement(SymbolVersionAuxRequirement &aux)
Try to remove the given auxiliary requirement symbol. The function returns true if the operation succ...
void version(uint16_t version)
Definition SymbolVersionRequirement.hpp:89
const SymbolVersionAuxRequirement * find_aux(const std::string &name) const
Try to find the SymbolVersionAuxRequirement with the given name (e.g. GLIBC_2.27).
it_const_aux_requirement auxiliary_symbols() const
Definition SymbolVersionRequirement.hpp:80
SymbolVersionRequirement(const details::Elf64_Verneed &header)
uint16_t version() const
Version revision.
Definition SymbolVersionRequirement.hpp:66
bool remove_aux_requirement(const std::string &name)
Try to remove the auxiliary requirement symbol with the given name. The function returns true if the ...
Definition SymbolVersionRequirement.hpp:121
SymbolVersionRequirement & operator=(SymbolVersionRequirement other)
it_aux_requirement auxiliary_symbols()
Auxiliary entries as an iterator over SymbolVersionAuxRequirement.
Definition SymbolVersionRequirement.hpp:76
friend class Parser
Definition SymbolVersionRequirement.hpp:42
friend std::ostream & operator<<(std::ostream &os, const SymbolVersionRequirement &symr)
Definition SymbolVersionRequirement.hpp:139
SymbolVersionRequirement(const SymbolVersionRequirement &other)
SymbolVersionAuxRequirement * find_aux(const std::string &name)
Definition SymbolVersionRequirement.hpp:108
~SymbolVersionRequirement() override=default
void name(const std::string &name)
Definition SymbolVersionRequirement.hpp:93
SymbolVersionAuxRequirement & add_aux_requirement(const SymbolVersionAuxRequirement &aux_requirement)
Add a version auxiliary requirement to the existing list.
SymbolVersionRequirement(const details::Elf32_Verneed &header)
ref_iterator< aux_requirement_t &, SymbolVersionAuxRequirement * > it_aux_requirement
Definition SymbolVersionRequirement.hpp:47
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:47
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DynamicEntry.hpp:29
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
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:316
#define LIEF_API
Definition visibility.h:45