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;
60 fixups_version_ = value;
65 imports_format_ = fmt;
73 std::copy(relocations.begin(), relocations.end(),
74 std::back_inserter(relocations_));
79 std::string library, uint64_t addend = 0,
83 uint64_t addend = 0,
bool weak =
false) {
84 return add_binding(address, std::move(symbol),
"", addend, weak);
89 std::copy(bindings.begin(), bindings.end(), std::back_inserter(bindings_));
108 binding_rebase_t(ChainedBindingInfo& info) :
112 binding_rebase_t(RelocationFixup& fixup) :
116 uint64_t addr()
const;
118 bool is_binding()
const {
119 return type == BINDING;
122 bool is_fixup()
const {
123 return type == FIXUP;
126 friend bool operator<(
const binding_rebase_t& lhs,
127 const binding_rebase_t& rhs) {
128 return lhs.addr() < rhs.addr();
131 friend bool operator>(
const binding_rebase_t& lhs,
132 const binding_rebase_t& rhs) {
133 return lhs.addr() > rhs.addr();
136 friend bool operator>=(
const binding_rebase_t& lhs,
137 const binding_rebase_t& rhs) {
141 friend bool operator<=(
const binding_rebase_t& lhs,
142 const binding_rebase_t& rhs) {
146 LIEF_LOCAL result<size_t> lib2ord(
const Binary& bin,
const Symbol& sym,
147 const std::string& lib);
148 LIEF_LOCAL const Symbol* find_symbol(
const Binary& bin,
const std::string& name);
152 LIEF_LOCAL ok_error_t process_relocations(Binary& target,
153 DYLD_CHAINED_PTR_FORMAT ptr_fmt);
155 process_bindings(Binary& target, strong_map_t& strong_map,
156 std::unordered_map<std::string, size_t>& symbols_idx,
157 DyldChainedFixups* cmd,
158 DyldChainedFixups::binding_info_t& all_bindings);
160 uint32_t fixups_version_ = 0;
162 std::vector<binding_info_t> bindings_;
163 std::vector<reloc_info_t> relocations_;
164 std::unordered_map<SegmentCommand*, std::vector<binding_rebase_t>>
166 std::unordered_map<std::string, size_t> lib2ord_;
Class which represents a MachO binary.
Definition MachO/Binary.hpp:89
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
static constexpr uint32_t MAX_IMPORTS
Definition DyldChainedFixupsCreator.hpp:43
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
static constexpr uint32_t BIND24_THRESHOLD
Definition DyldChainedFixupsCreator.hpp:44
DyldChainedFixupsCreator & add_bindings(const std::vector< binding_info_t > &bindings)
Definition DyldChainedFixupsCreator.hpp:88
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:82
DyldChainedFixupsCreator & imports_format(DYLD_CHAINED_FORMAT fmt)
Definition DyldChainedFixupsCreator.hpp:64
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:49
Class that represents a rebase relocation found in the LC_DYLD_CHAINED_FIXUPS command.
Definition RelocationFixup.hpp:55
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:51
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:24
DYLD_CHAINED_PTR_FORMAT
Definition DyldChainedFormat.hpp:29
LIEF namespace.
Definition Abstract/Binary.hpp:40
Definition DyldChainedFixupsCreator.hpp:45
std::string library
Definition DyldChainedFixupsCreator.hpp:47
uint64_t address
Definition DyldChainedFixupsCreator.hpp:46
uint64_t addend
Definition DyldChainedFixupsCreator.hpp:50
bool weak
Definition DyldChainedFixupsCreator.hpp:49
std::string symbol
Definition DyldChainedFixupsCreator.hpp:48
Definition DyldChainedFixupsCreator.hpp:53
uint64_t target
Definition DyldChainedFixupsCreator.hpp:55
uint64_t addr
Definition DyldChainedFixupsCreator.hpp:54
#define LIEF_LOCAL
Definition visibility.h:46