16#ifndef LIEF_MACHO_DYLD_CHAINED_FIXUPS_CREATOR_H
17#define LIEF_MACHO_DYLD_CHAINED_FIXUPS_CREATOR_H
24#include <unordered_map>
36class ChainedBindingInfoList;
44 static constexpr uint32_t
MAX_IMPORTS = (uint32_t(1) << 24) - 1;
61 fixups_version_ = value;
66 imports_format_ = fmt;
74 std::copy(relocations.begin(), relocations.end(),
75 std::back_inserter(relocations_));
80 std::string library, uint64_t addend = 0,
84 uint64_t addend = 0,
bool weak =
false) {
85 return add_binding(address, std::move(symbol),
"", addend, weak);
90 std::copy(bindings.begin(), bindings.end(), std::back_inserter(bindings_));
109 binding_rebase_t(ChainedBindingInfo& info) :
113 binding_rebase_t(RelocationFixup& fixup) :
117 uint64_t addr()
const;
119 bool is_binding()
const {
120 return type == BINDING;
123 bool is_fixup()
const {
124 return type == FIXUP;
127 friend bool operator<(
const binding_rebase_t& lhs,
128 const binding_rebase_t& rhs) {
129 return lhs.addr() < rhs.addr();
132 friend bool operator>(
const binding_rebase_t& lhs,
133 const binding_rebase_t& rhs) {
134 return lhs.addr() > rhs.addr();
137 friend bool operator>=(
const binding_rebase_t& lhs,
138 const binding_rebase_t& rhs) {
142 friend bool operator<=(
const binding_rebase_t& lhs,
143 const binding_rebase_t& rhs) {
147 LIEF_LOCAL result<size_t> lib2ord(
const Binary& bin,
const Symbol& sym,
148 const std::string& lib);
149 LIEF_LOCAL const Symbol* find_symbol(
const Binary& bin, std::string_view name);
153 LIEF_LOCAL ok_error_t process_relocations(Binary& target,
154 DYLD_CHAINED_PTR_FORMAT ptr_fmt);
156 process_bindings(Binary& target, strong_map_t& strong_map,
157 std::unordered_map<std::string, size_t>& symbols_idx,
158 DyldChainedFixups* cmd);
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:94
This class represents a symbol binding operation associated with the LC_DYLD_CHAINED_FIXUPS command.
Definition ChainedBindingInfo.hpp:48
Definition DyldChainedFixupsCreator.hpp:42
DyldChainedFixupsCreator()=default
static constexpr uint32_t MAX_IMPORTS
Definition DyldChainedFixupsCreator.hpp:44
DyldChainedFixupsCreator & fixups_version(uint32_t value)
Definition DyldChainedFixupsCreator.hpp:60
DyldChainedFixups * create(Binary &target)
DyldChainedFixupsCreator & add_relocations(const std::vector< reloc_info_t > &relocations)
Definition DyldChainedFixupsCreator.hpp:73
static constexpr uint32_t BIND24_THRESHOLD
Definition DyldChainedFixupsCreator.hpp:45
DyldChainedFixupsCreator & add_bindings(const std::vector< binding_info_t > &bindings)
Definition DyldChainedFixupsCreator.hpp:89
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:65
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:50
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:54
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:34
Definition DyldChainedFixupsCreator.hpp:46
std::string library
Definition DyldChainedFixupsCreator.hpp:48
uint64_t address
Definition DyldChainedFixupsCreator.hpp:47
uint64_t addend
Definition DyldChainedFixupsCreator.hpp:51
bool weak
Definition DyldChainedFixupsCreator.hpp:50
std::string symbol
Definition DyldChainedFixupsCreator.hpp:49
Definition DyldChainedFixupsCreator.hpp:54
uint64_t target
Definition DyldChainedFixupsCreator.hpp:56
uint64_t addr
Definition DyldChainedFixupsCreator.hpp:55
#define LIEF_LOCAL
Definition visibility.h:46