38 : m_dcmp(dcmp), m_allocator(alloc), m_copier(copy), m_resolver(resolve) {}
45 case decomp::sym_type_t::section:
46 case decomp::sym_type_t::function:
47 case decomp::sym_type_t::instruction: {
48 sym.allocated_at(m_allocator(sym.size(), sym.scn()->characteristics));
65 m_dcmp->syms()->sym_from_hash(m_dcmp->scn_hash_tbl()[sym.scn()]);
67 if (!scn_sym.has_value()) {
68 spdlog::error(
"failed to locate section: {} for symbol: {}",
69 sym.scn()->name.to_string(), sym.name());
71 assert(scn_sym.has_value());
74 sym.allocated_at(scn_sym.value()->allocated_at() + sym.offset());
82 coff::section_characteristics_t prot = {};
84 prot.mem_write =
true;
92void recomp_t::resolve() {
96 auto& relocs = sym.
relocs();
97 std::for_each(relocs.begin(), relocs.end(), [&](
reloc_t& reloc) {
98 if (reloc.offset() > sym.data().size()) {
100 "invalid relocation... writing outside of symbol length... offset: "
102 sym.offset(), sym.data().size());
104 assert(reloc.offset() > sym.data().size());
110 auto reloc_sym = m_dcmp->syms()->sym_from_hash(reloc.
hash());
111 auto allocated_at = reloc_sym.has_value()
112 ? reloc_sym.value()->allocated_at()
113 : m_resolver(reloc.
name());
116 spdlog::error(
"failed to resolve reloc from symbol: {} to symbol: {}",
119 assert(allocated_at);
122 switch (sym.
type()) {
125 m_dcmp->syms()->sym_from_hash(m_dcmp->scn_hash_tbl()[sym.
scn()]);
127 *
reinterpret_cast<std::uintptr_t*
>(scn_sym.value()->data().data() +
128 reloc.
offset()) = allocated_at;
132 *
reinterpret_cast<std::uintptr_t*
>(sym.
data().data() +
133 reloc.
offset()) = allocated_at;
139 transforms.begin(), transforms.end(),
140 [&](std::pair<obf::transform::transform_t*, std::uint32_t>& t) {
141 allocated_at = (*t.first)(allocated_at, t.second);
144 *
reinterpret_cast<std::uintptr_t*
>(sym.
data().data() +
145 reloc.
offset()) = allocated_at;
155void recomp_t::copy_syms() {
172 m_resolver = resolve;
175std::uintptr_t recomp_t::resolve(
const std::string&& sym) {
177 return res.has_value() ? res.value()->allocated_at() : 0;