LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
RelocationObject.hpp
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
22#include "LIEF/MachO/Relocation.hpp"
23
24namespace LIEF {
25namespace MachO {
26
27class BinaryParser;
28
29namespace details {
30struct relocation_info;
31struct scattered_relocation_info;
32}
33
38class LIEF_API RelocationObject : public Relocation {
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
48 RelocationObject& operator=(const RelocationObject& other) = default;
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 Relocation::ORIGIN origin() const override {
88 return Relocation::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:73
Class that represents a relocation presents in the MachO object file (.o). Usually,...
Definition RelocationObject.hpp:38
bool is_scattered() const
true if the relocation is a scattered one
Definition RelocationObject.hpp:72
Relocation::ORIGIN origin() const override
Origin of the relocation. For this object it should be Relocation::ORIGIN::RELOC_TABLE)
Definition RelocationObject.hpp:87
int32_t value() const
For scattered relocations: The address of the relocatable expression for the item in the file that ne...
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.
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32