|
|
@ -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) {}
|
|
|
|
: m_lib(lib), m_syms(syms) {}
|
|
|
|
|
|
|
|
|
|
|
|
std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
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...
|
|
|
|
// extract obj files from the archive file...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
ar::view<false> lib(m_lib.data(), m_lib.size());
|
|
|
|
ar::view<false> lib(m_lib.data(), m_lib.size());
|
|
|
@ -17,22 +17,26 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (!itr.second.is_symbol_table() && !itr.second.is_string_table()) {
|
|
|
|
if (!itr.second.is_symbol_table() && !itr.second.is_string_table()) {
|
|
|
|
spdlog::info("extracted obj from archive: {}", itr.first);
|
|
|
|
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) {
|
|
|
|
std::for_each(
|
|
|
|
for (auto idx = 0u; idx < img->file_header.num_symbols; ++idx) {
|
|
|
|
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 = img->get_symbol(idx);
|
|
|
|
auto sym_name = symbol_t::name(img, sym);
|
|
|
|
auto sym_name = symbol_t::name(img, sym);
|
|
|
|
if (sym_name.length()) {
|
|
|
|
if (sym_name.length()) {
|
|
|
|
auto sym_hash = symbol_t::hash(sym_name.data());
|
|
|
|
auto sym_hash = symbol_t::hash(sym_name.data());
|
|
|
|
auto sym_size =
|
|
|
|
auto sym_size =
|
|
|
|
sym->has_section()
|
|
|
|
sym->has_section()
|
|
|
|
? next_sym(img, img->get_section(sym->section_index - 1), sym)
|
|
|
|
? next_sym(img, img->get_section(sym->section_index - 1),
|
|
|
|
|
|
|
|
sym)
|
|
|
|
: 0u;
|
|
|
|
: 0u;
|
|
|
|
|
|
|
|
|
|
|
|
m_lookup_tbl[sym_hash].push_back({img, sym, sym_size});
|
|
|
|
m_lookup_tbl[sym_hash].emplace_back(img, sym, sym_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -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) {
|
|
|
|
std::for_each(m_used_syms.begin(), m_used_syms.end(), [&](sym_data_t data) {
|
|
|
|
auto [img, sym, size] = data;
|
|
|
|
auto [img, sym, size] = data;
|
|
|
|
|
|
|
|
|
|
|
|
// populate section hash table with sections for the img of this
|
|
|
|
// populate section hash table with sections for the img of this
|
|
|
|
// symbol... only populate the hash table if its not been populated for
|
|
|
|
// symbol... only populate the hash table if its not been populated for
|
|
|
|
// this obj before...
|
|
|
|
// 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) {
|
|
|
|
for (auto idx = 0u; idx < img->file_header.num_symbols; ++idx) {
|
|
|
|
auto q = img->get_symbol(idx);
|
|
|
|
auto q = img->get_symbol(idx);
|
|
|
|
if (q->derived_type == coff::derived_type_id::function &&
|
|
|
|
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)
|
|
|
|
if (q->value > s->value && q->value < res)
|
|
|
|
res = q->value;
|
|
|
|
res = q->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -244,7 +249,7 @@ std::vector<std::uint8_t> decomp_t::lib() {
|
|
|
|
return m_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;
|
|
|
|
return m_objs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|