|
|
|
@ -5,7 +5,7 @@ decomp_t::decomp_t(std::vector<std::uint8_t>& lib, recomp::symbol_table_t* syms)
|
|
|
|
|
: m_lib(lib), m_syms(syms) {}
|
|
|
|
|
|
|
|
|
|
std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
|
const std::string&& entry_sym) {
|
|
|
|
|
std::string& entry_sym) {
|
|
|
|
|
// extract obj files from the archive file...
|
|
|
|
|
//
|
|
|
|
|
ar::view<false> lib(m_lib.data(), m_lib.size());
|
|
|
|
@ -17,25 +17,29 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
|
//
|
|
|
|
|
if (!itr.second.is_symbol_table() && !itr.second.is_string_table()) {
|
|
|
|
|
spdlog::info("extracted obj from archive: {}", itr.first);
|
|
|
|
|
m_objs.push_back(reinterpret_cast<coff::image_t*>(itr.second.data()));
|
|
|
|
|
std::vector<std::uint8_t> data(itr.second.begin(), itr.second.end());
|
|
|
|
|
m_objs.push_back(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::for_each(m_objs.begin(), m_objs.end(), [&](coff::image_t* img) {
|
|
|
|
|
for (auto idx = 0u; idx < img->file_header.num_symbols; ++idx) {
|
|
|
|
|
auto sym = img->get_symbol(idx);
|
|
|
|
|
auto sym_name = symbol_t::name(img, sym);
|
|
|
|
|
if (sym_name.length()) {
|
|
|
|
|
auto sym_hash = symbol_t::hash(sym_name.data());
|
|
|
|
|
auto sym_size =
|
|
|
|
|
sym->has_section()
|
|
|
|
|
? next_sym(img, img->get_section(sym->section_index - 1), sym)
|
|
|
|
|
: 0u;
|
|
|
|
|
|
|
|
|
|
m_lookup_tbl[sym_hash].push_back({img, sym, sym_size});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
std::for_each(
|
|
|
|
|
m_objs.begin(), m_objs.end(), [&](std::vector<std::uint8_t>& img_data) {
|
|
|
|
|
auto img = reinterpret_cast<coff::image_t*>(img_data.data());
|
|
|
|
|
for (auto idx = 0u; idx < img->file_header.num_symbols - 1; ++idx) {
|
|
|
|
|
auto sym = img->get_symbol(idx);
|
|
|
|
|
auto sym_name = symbol_t::name(img, sym);
|
|
|
|
|
if (sym_name.length()) {
|
|
|
|
|
auto sym_hash = symbol_t::hash(sym_name.data());
|
|
|
|
|
auto sym_size =
|
|
|
|
|
sym->has_section()
|
|
|
|
|
? next_sym(img, img->get_section(sym->section_index - 1),
|
|
|
|
|
sym)
|
|
|
|
|
: 0u;
|
|
|
|
|
|
|
|
|
|
m_lookup_tbl[sym_hash].emplace_back(img, sym, sym_size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// extract used symbols from objs and create a nice little set of them so that
|
|
|
|
|
// we can easily decompose them... no need deal with every single symbol...
|
|
|
|
@ -47,6 +51,7 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
|
//
|
|
|
|
|
std::for_each(m_used_syms.begin(), m_used_syms.end(), [&](sym_data_t data) {
|
|
|
|
|
auto [img, sym, size] = data;
|
|
|
|
|
|
|
|
|
|
// populate section hash table with sections for the img of this
|
|
|
|
|
// symbol... only populate the hash table if its not been populated for
|
|
|
|
|
// this obj before...
|
|
|
|
@ -173,7 +178,7 @@ std::uint32_t decomp_t::next_sym(coff::image_t* img,
|
|
|
|
|
for (auto idx = 0u; idx < img->file_header.num_symbols; ++idx) {
|
|
|
|
|
auto q = img->get_symbol(idx);
|
|
|
|
|
if (q->derived_type == coff::derived_type_id::function &&
|
|
|
|
|
q->section_index == s->section_index)
|
|
|
|
|
q->section_index == s->section_index && q != s)
|
|
|
|
|
if (q->value > s->value && q->value < res)
|
|
|
|
|
res = q->value;
|
|
|
|
|
}
|
|
|
|
@ -244,7 +249,7 @@ std::vector<std::uint8_t> decomp_t::lib() {
|
|
|
|
|
return m_lib;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<coff::image_t*> decomp_t::objs() {
|
|
|
|
|
std::vector<std::vector<std::uint8_t>> decomp_t::objs() {
|
|
|
|
|
return m_objs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|