LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
RelocationObject.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_MACHO_RELOCATION_OBJECT_COMMAND_H
17#define LIEF_MACHO_RELOCATION_OBJECT_COMMAND_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21
23
24namespace LIEF {
25namespace MachO {
26
27class BinaryParser;
28
29namespace details {
30struct relocation_info;
31struct scattered_relocation_info;
32}
33
39
40 friend class BinaryParser;
41
42 public:
43 using Relocation::Relocation;
44 RelocationObject() = default;
45 RelocationObject(const details::relocation_info& relocinfo);
46 RelocationObject(const details::scattered_relocation_info& scattered_relocinfo);
47
49 RelocationObject(const RelocationObject& other) = default;
50
51 void swap(RelocationObject& other) noexcept;
52
53 ~RelocationObject() override = default;
54
55 std::unique_ptr<Relocation> clone() const override {
56 return std::unique_ptr<RelocationObject>(new RelocationObject(*this));
57 }
58
60 bool is_pc_relative() const override {
61 return is_pcrel_;
62 }
63
65 size_t size() const override;
66
69 uint64_t address() const override;
70
72 bool is_scattered() const {
73 return is_scattered_;
74 }
75
84 int32_t value() const;
85
87 ORIGIN origin() const override {
88 return ORIGIN::RELOC_TABLE;
89 }
90
91 void pc_relative(bool val) override {
92 is_pcrel_ = val;
93 }
94 void size(size_t size) override;
95
96 void value(int32_t value);
97
98 void accept(Visitor& visitor) const override;
99
100 std::ostream& print(std::ostream& os) const override {
101 return Relocation::print(os);
102 }
103
104 static bool classof(const Relocation& r) {
105 return r.origin() == Relocation::ORIGIN::RELOC_TABLE;
106 }
107
108 private:
109 bool is_pcrel_ = false;
110 bool is_scattered_ = false;
111 int32_t value_ = 0;
112};
113
114}
115}
116#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class that represents a relocation presents in the MachO object file (.o). Usually,...
Definition RelocationObject.hpp:38
void value(int32_t value)
bool is_scattered() const
true if the relocation is a scattered one
Definition RelocationObject.hpp:72
static bool classof(const Relocation &r)
Definition RelocationObject.hpp:104
std::unique_ptr< Relocation > clone() const override
Definition RelocationObject.hpp:55
void size(size_t size) override
void swap(RelocationObject &other) noexcept
void pc_relative(bool val) override
Definition RelocationObject.hpp:91
int32_t value() const
For scattered relocations: The address of the relocatable expression for the item in the file that ne...
RelocationObject & operator=(const RelocationObject &other)=default
bool is_pc_relative() const override
Whether the relocation is PC relative.
Definition RelocationObject.hpp:60
uint64_t address() const override
Address where the relocation is applied This address is relative to the start of the section where th...
size_t size() const override
Size of the relocation.
RelocationObject(const details::scattered_relocation_info &scattered_relocinfo)
RelocationObject(const RelocationObject &other)=default
void accept(Visitor &visitor) const override
~RelocationObject() override=default
ORIGIN origin() const override
Origin of the relocation. For this object it should be Relocation::ORIGIN::RELOC_TABLE)
Definition RelocationObject.hpp:87
std::ostream & print(std::ostream &os) const override
Definition RelocationObject.hpp:100
RelocationObject(const details::relocation_info &relocinfo)
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
virtual ORIGIN origin() const =0
Origin of the relocation.
ORIGIN
Definition MachO/Relocation.hpp:48
Definition Visitor.hpp:224
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41