LIEF: Library to Instrument Executable Formats Version 0.17.0
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}
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 bool is_pc_relative() const override {
61 return is_pcrel_;
62 }
63 size_t size() const override;
66 uint64_t address() const override;
70 bool is_scattered() const {
73 return is_scattered_;
74 }
75 int32_t value() const;
85 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
Relocation.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
LIEF::MachO::RelocationObject
Class that represents a relocation presents in the MachO object file (.o). Usually,...
Definition RelocationObject.hpp:38
LIEF::MachO::RelocationObject::value
void value(int32_t value)
LIEF::MachO::RelocationObject::is_scattered
bool is_scattered() const
true if the relocation is a scattered one
Definition RelocationObject.hpp:72
LIEF::MachO::RelocationObject::classof
static bool classof(const Relocation &r)
Definition RelocationObject.hpp:104
LIEF::MachO::RelocationObject::clone
std::unique_ptr< Relocation > clone() const override
Definition RelocationObject.hpp:55
LIEF::MachO::RelocationObject::size
void size(size_t size) override
LIEF::MachO::RelocationObject::swap
void swap(RelocationObject &other) noexcept
LIEF::MachO::RelocationObject::pc_relative
void pc_relative(bool val) override
Definition RelocationObject.hpp:91
LIEF::MachO::RelocationObject::value
int32_t value() const
For scattered relocations: The address of the relocatable expression for the item in the file that ne...
LIEF::MachO::RelocationObject::operator=
RelocationObject & operator=(const RelocationObject &other)=default
LIEF::MachO::RelocationObject::is_pc_relative
bool is_pc_relative() const override
Whether the relocation is PC relative.
Definition RelocationObject.hpp:60
LIEF::MachO::RelocationObject::address
uint64_t address() const override
Address where the relocation is applied This address is relative to the start of the section where th...
LIEF::MachO::RelocationObject::size
size_t size() const override
Size of the relocation.
LIEF::MachO::RelocationObject::RelocationObject
RelocationObject(const details::scattered_relocation_info &scattered_relocinfo)
LIEF::MachO::RelocationObject::RelocationObject
RelocationObject(const RelocationObject &other)=default
LIEF::MachO::RelocationObject::accept
void accept(Visitor &visitor) const override
LIEF::MachO::RelocationObject::RelocationObject
RelocationObject()=default
LIEF::MachO::RelocationObject::~RelocationObject
~RelocationObject() override=default
LIEF::MachO::RelocationObject::origin
ORIGIN origin() const override
Origin of the relocation. For this object it should be Relocation::ORIGIN::RELOC_TABLE)
Definition RelocationObject.hpp:87
LIEF::MachO::RelocationObject::print
std::ostream & print(std::ostream &os) const override
Definition RelocationObject.hpp:100
LIEF::MachO::RelocationObject::RelocationObject
RelocationObject(const details::relocation_info &relocinfo)
LIEF::MachO::Relocation
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
LIEF::MachO::Relocation::origin
virtual ORIGIN origin() const =0
Origin of the relocation.
LIEF::MachO::details
Definition endianness_support.hpp:59
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41