57 lines
1.8 KiB
57 lines
1.8 KiB
#include <comp/comp.hpp>
|
|
|
|
namespace theo::comp {
|
|
comp_t::comp_t(decomp::decomp_t* dcmp) : m_dcmp(dcmp) {}
|
|
comp_t::comp_t(decomp::decomp_t* dcmp,
|
|
allocator_t alloc,
|
|
copier_t copy,
|
|
resolver_t resolve)
|
|
: m_dcmp(dcmp), m_allocator(alloc), m_copier(copy), m_resolver(resolve) {}
|
|
|
|
void comp_t::compose() {
|
|
m_dcmp->syms()->for_each([&](theo::decomp::symbol_t& sym) {
|
|
// if this symbol is a function..
|
|
//
|
|
if (sym.scn()->characteristics.mem_execute) {
|
|
// if comp type is none (meaning entire function) then we just allocate
|
|
// it...
|
|
//
|
|
if (sym.dcmp_type() == decomp::decomp_type_t::none) {
|
|
sym.allocated_at(m_allocator(sym.size(), sym.scn()->characteristics));
|
|
spdlog::info("allocated entire function: {} at address: {:X} size: {}",
|
|
sym.name(), sym.allocated_at(), sym.size());
|
|
} else { // else the dcmp_type is split instrs we are going to apply
|
|
// transformations...
|
|
|
|
sym.allocated_at(m_allocator(sym.size(), sym.scn()->characteristics));
|
|
|
|
spdlog::info(
|
|
"transformed relocations of symbol: {} size is now: {} allocated "
|
|
"at: {:X}",
|
|
sym.name(), sym.size(), sym.allocated_at());
|
|
}
|
|
} else { // else the allocation is data which means we dont have any
|
|
// relocs...
|
|
sym.allocated_at(m_allocator(sym.size(), sym.scn()->characteristics));
|
|
}
|
|
});
|
|
}
|
|
|
|
void comp_t::allocator(allocator_t alloc) {
|
|
m_allocator = alloc;
|
|
}
|
|
|
|
void comp_t::copier(copier_t copy) {
|
|
m_copier = copy;
|
|
}
|
|
|
|
void comp_t::resolver(resolver_t resolve) {
|
|
m_resolver = resolve;
|
|
}
|
|
|
|
std::uintptr_t comp_t::resolve(const std::string&& sym) {
|
|
return m_dcmp->syms()
|
|
->sym_from_hash(decomp::symbol_t::hash(sym))
|
|
.allocated_at();
|
|
}
|
|
} // namespace theo::comp
|