LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Abstract/Relocation.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_ABSTRACT_RELOCATION_H
17#define LIEF_ABSTRACT_RELOCATION_H
18
19#include <ostream>
20#include <cstdint>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
27class LIEF_API Relocation : public Object {
28
29 public:
30 Relocation() = default;
31
33 Relocation(uint64_t address, uint8_t size) :
34 address_(address),
35 size_(size)
36 {}
37
38 ~Relocation() override = default;
39
40 Relocation& operator=(const Relocation&) = default;
41 Relocation(const Relocation&) = default;
42 void swap(Relocation& other) {
43 std::swap(address_, other.address_);
44 std::swap(size_, other.size_);
45 }
46
48 virtual uint64_t address() const {
49 return address_;
50 }
51
53 virtual size_t size() const {
54 return size_;
55 }
56
57 virtual void address(uint64_t address) {
58 address_ = address;
59 }
60
61 virtual void size(size_t size) {
62 size_ = (uint8_t)size;
63 }
64
66 void accept(Visitor& visitor) const override;
67
68
70 virtual bool operator<(const Relocation& rhs) const {
71 return address() < rhs.address();
72 }
73
75 virtual bool operator<=(const Relocation& rhs) const {
76 return !(address() > rhs.address());
77 }
78
80 virtual bool operator>(const Relocation& rhs) const {
81 return address() > rhs.address();
82 }
83
85 virtual bool operator>=(const Relocation& rhs) const {
86 return !(address() < rhs.address());
87 }
88
89 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Relocation& entry);
90
91 protected:
92 uint64_t address_ = 0;
93 uint8_t size_ = 0;
94};
95
96
97}
98#endif
friend std::ostream & operator<<(std::ostream &os, const Relocation &entry)
void swap(Relocation &other)
Definition Abstract/Relocation.hpp:42
Relocation()=default
virtual void address(uint64_t address)
Definition Abstract/Relocation.hpp:57
Relocation & operator=(const Relocation &)=default
virtual void size(size_t size)
Definition Abstract/Relocation.hpp:61
Relocation(const Relocation &)=default
virtual bool operator<(const Relocation &rhs) const
Comparaison based on the Relocation's address.
Definition Abstract/Relocation.hpp:70
virtual size_t size() const
Relocation size in bits.
Definition Abstract/Relocation.hpp:53
virtual bool operator<=(const Relocation &rhs) const
Comparaison based on the Relocation's address.
Definition Abstract/Relocation.hpp:75
virtual bool operator>(const Relocation &rhs) const
Comparaison based on the Relocation's address.
Definition Abstract/Relocation.hpp:80
virtual uint64_t address() const
Relocation's address.
Definition Abstract/Relocation.hpp:48
virtual bool operator>=(const Relocation &rhs) const
Comparaison based on the Relocation's address.
Definition Abstract/Relocation.hpp:85
void accept(Visitor &visitor) const override
Method so that the visitor can visit us.
Relocation(uint64_t address, uint8_t size)
Constructor from a relocation's address and size.
Definition Abstract/Relocation.hpp:33
~Relocation() override=default
Definition Visitor.hpp:210
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41