16#ifndef LIEF_MACHO_DYLD_CHAINED_FIXUPS_CREATOR_H
17#define LIEF_MACHO_DYLD_CHAINED_FIXUPS_CREATOR_H
25#include <unordered_map>
35class ChainedBindingInfoList;
43 static constexpr uint32_t MAX_IMPORTS = (uint32_t(1) << 24) - 1;
44 static constexpr uint32_t BIND24_THRESHOLD = (uint32_t(1) << 16) - 1;
45 struct binding_info_t {
60 fixups_version_ = value;
65 imports_format_ = fmt;
71 DyldChainedFixupsCreator&
74 std::copy(relocations.begin(), relocations.end(),
75 std::back_inserter(relocations_));
80 std::string symbol, std::string library,
81 uint64_t addend = 0,
bool weak =
false);
85 uint64_t addend = 0,
bool weak =
false)
87 return add_binding(address, std::move(symbol),
"", addend, weak);
90 DyldChainedFixupsCreator&
add_bindings(
const std::vector<binding_info_t>& bindings) {
91 std::copy(bindings.begin(), bindings.end(), std::back_inserter(bindings_));
95 DyldChainedFixups*
create(Binary& target);
104 ChainedBindingInfo* binding =
nullptr;
105 RelocationFixup* fixup;
109 binding_rebase_t(ChainedBindingInfo& info) :
114 binding_rebase_t(RelocationFixup& fixup) :
119 uint64_t addr()
const;
121 bool is_binding()
const {
122 return type == BINDING;
125 bool is_fixup()
const {
126 return type == FIXUP;
129 friend bool operator<(
const binding_rebase_t& lhs,
130 const binding_rebase_t& rhs) {
131 return lhs.addr() < rhs.addr();
134 friend bool operator>(
const binding_rebase_t& lhs,
135 const binding_rebase_t& rhs) {
136 return lhs.addr() > rhs.addr();
139 friend bool operator>=(
const binding_rebase_t& lhs,
140 const binding_rebase_t& rhs) {
144 friend bool operator<=(
const binding_rebase_t& lhs,
145 const binding_rebase_t& rhs) {
150 LIEF_LOCAL result<size_t> lib2ord(
const Binary& bin,
const Symbol& sym,
151 const std::string& lib);
152 LIEF_LOCAL const Symbol* find_symbol(
const Binary& bin,
const std::string& name);
157 Binary& target, strong_map_t& strong_map,
158 std::unordered_map<std::string, size_t>& symbols_idx, DyldChainedFixups* cmd,
159 DyldChainedFixups::binding_info_t& all_bindings);
161 uint32_t fixups_version_ = 0;
163 std::vector<binding_info_t> bindings_;
164 std::vector<reloc_info_t> relocations_;
165 std::unordered_map<SegmentCommand*, std::vector<binding_rebase_t>> segment_chains_;
166 std::unordered_map<std::string, size_t> lib2ord_;
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
This class represents a symbol binding operation associated with the LC_DYLD_CHAINED_FIXUPS command.
Definition ChainedBindingInfo.hpp:48
Definition DyldChainedFixupsCreator.hpp:41
DyldChainedFixupsCreator()=default
DyldChainedFixupsCreator & fixups_version(uint32_t value)
Definition DyldChainedFixupsCreator.hpp:59
DyldChainedFixups * create(Binary &target)
DyldChainedFixupsCreator & add_relocations(const std::vector< reloc_info_t > &relocations)
Definition DyldChainedFixupsCreator.hpp:72
DyldChainedFixupsCreator & add_bindings(const std::vector< binding_info_t > &bindings)
Definition DyldChainedFixupsCreator.hpp:90
DyldChainedFixupsCreator & add_relocation(uint64_t address, uint64_t target)
DyldChainedFixupsCreator & add_binding(uint64_t address, std::string symbol, std::string library, uint64_t addend=0, bool weak=false)
DyldChainedFixupsCreator & add_binding(uint64_t address, std::string symbol, uint64_t addend=0, bool weak=false)
Definition DyldChainedFixupsCreator.hpp:83
DyldChainedFixupsCreator & imports_format(DYLD_CHAINED_FORMAT fmt)
Definition DyldChainedFixupsCreator.hpp:64
Class that represents a rebase relocation found in the LC_DYLD_CHAINED_FIXUPS command.
Definition RelocationFixup.hpp:50
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
DYLD_CHAINED_FORMAT
Definition DyldChainedFormat.hpp:22
@ UNKNOWN
Definition MachO/enums.hpp:25
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:29
LIEF namespace.
Definition Abstract/Binary.hpp:36
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
#define LIEF_LOCAL
Definition visibility.h:42