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;
92 void 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;
155 void recomp_t::copy_syms() {
172 m_resolver = resolve;
175 std::uintptr_t recomp_t::resolve(
const std::string&& sym) {
177 return res.has_value() ? res.value()->allocated_at() : 0;
the main decomposition class which is responsible for breaking down lib file into coff files,...
recomp::symbol_table_t * syms()
gets the symbol table.
symbol_t is an abstraction upon the coff symbol. this allows for easier manipulation of the symbol....
sym_type_t type() const
returns the type of the symbol.
coff::section_header_t * scn() const
gets the section header of the section in which the symbol is contained.
std::string name() const
gets the name of the symbol.
std::size_t hash()
gets the hash of the symbol name.
std::vector< std::uint8_t > & data()
returns a vector by reference of bytes containing the data of the symbol.
std::vector< recomp::reloc_t > & relocs()
returns a vector of relocations.
std::uint32_t size() const
returns the size of the symbol.
std::uintptr_t allocated_at() const
returns the address where the symbol is allocated.
void allocate()
when called, this function allocates space for every symbol.
recomp_t(decomp::decomp_t *dcmp, allocator_t alloc, copier_t copy, resolver_t resolve)
the explicit constructor for the recomp_t class.
meta data about a relocation for a symbol
std::uint32_t offset()
returns the offset into the symbol to which the relocation will be applied. the offset is in bytes....
std::string name()
returns the name of the relocation symbol.
std::size_t hash()
returns the hash of the relocation symbol.
std::vector< std::pair< obf::transform::transform_t *, std::uint32_t > > & get_transforms()
gets the vector of transformation.
void for_each(std::function< void(decomp::symbol_t &sym)> fn)
this function is a wrapper function that allows you to get at each entry in the symbol table by refer...
this namespace encompasses all recomposition related code.
std::function< void(std::uintptr_t, void *, std::uint32_t)> copier_t
a function which is called by recomp_t to copy symbols into memory.
std::function< std::uintptr_t(std::string)> resolver_t
a function which is called by recomp_t to resolve external symbols
std::function< std::uintptr_t(std::uint32_t, coff::section_characteristics_t)> allocator_t
a function which is called to allocate space for a symbol.