|
|
@ -48,15 +48,16 @@ std::optional<comp::symbol_table_t*> decomp_t::decompose() {
|
|
|
|
// if the symbol is a function then we are going to decompose it...
|
|
|
|
// if the symbol is a function then we are going to decompose it...
|
|
|
|
// data symbols are handled after this...
|
|
|
|
// data symbols are handled after this...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (sym->has_section() &&
|
|
|
|
if (sym->has_section()) {
|
|
|
|
sym->derived_type == coff::derived_type_id::function) {
|
|
|
|
if (sym->derived_type == coff::derived_type_id::function) {
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
auto dcmp_type =
|
|
|
|
auto dcmp_type = scn->name.to_string(img->get_strings()) ==
|
|
|
|
scn->name.to_string(img->get_strings()) == INSTR_SPLIT_SECTION_NAME
|
|
|
|
INSTR_SPLIT_SECTION_NAME
|
|
|
|
? decomp::sym_type_t::inst_split
|
|
|
|
? decomp::sym_type_t::inst_split
|
|
|
|
: decomp::sym_type_t::function;
|
|
|
|
: decomp::sym_type_t::function;
|
|
|
|
auto fn_size = scn->size_raw_data;
|
|
|
|
auto fn_size = scn->size_raw_data;
|
|
|
|
auto fn_bgn = scn->ptr_raw_data + reinterpret_cast<std::uint8_t*>(img);
|
|
|
|
auto fn_bgn =
|
|
|
|
|
|
|
|
scn->ptr_raw_data + reinterpret_cast<std::uint8_t*>(img);
|
|
|
|
|
|
|
|
|
|
|
|
spdlog::info("decomposing function: {} size: {}",
|
|
|
|
spdlog::info("decomposing function: {} size: {}",
|
|
|
|
sym->name.to_string(img->get_strings()), fn_size);
|
|
|
|
sym->name.to_string(img->get_strings()), fn_size);
|
|
|
@ -67,13 +68,13 @@ std::optional<comp::symbol_table_t*> decomp_t::decompose() {
|
|
|
|
auto syms = rtn.decompose();
|
|
|
|
auto syms = rtn.decompose();
|
|
|
|
spdlog::info("decomposed routine into {} symbols...", syms.size());
|
|
|
|
spdlog::info("decomposed routine into {} symbols...", syms.size());
|
|
|
|
m_syms->add_symbols(syms);
|
|
|
|
m_syms->add_symbols(syms);
|
|
|
|
} else if (sym->has_section() &&
|
|
|
|
} else if (sym->storage_class ==
|
|
|
|
sym->storage_class == coff::storage_class_id::public_symbol) {
|
|
|
|
coff::storage_class_id::public_symbol) {
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
auto scn_sym = m_syms->sym_from_hash(m_scn_hash_tbl[scn]);
|
|
|
|
auto scn_sym = m_syms->sym_from_hash(m_scn_hash_tbl[scn]);
|
|
|
|
|
|
|
|
|
|
|
|
// if the section doesnt have a symbol then make one and put it into the
|
|
|
|
// if the section doesnt have a symbol then make one and put it into
|
|
|
|
// symbol table...
|
|
|
|
// the symbol table...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (!scn_sym.has_value()) {
|
|
|
|
if (!scn_sym.has_value()) {
|
|
|
|
auto scn_sym_name =
|
|
|
|
auto scn_sym_name =
|
|
|
@ -102,9 +103,9 @@ std::optional<comp::symbol_table_t*> decomp_t::decompose() {
|
|
|
|
|
|
|
|
|
|
|
|
// create a symbol for the data...
|
|
|
|
// create a symbol for the data...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
decomp::symbol_t new_sym(sym->name.to_string(img->get_strings()).data(),
|
|
|
|
decomp::symbol_t new_sym(
|
|
|
|
sym->value, {}, scn, sym, {},
|
|
|
|
sym->name.to_string(img->get_strings()).data(), sym->value, {},
|
|
|
|
sym_type_t::data);
|
|
|
|
scn, sym, {}, sym_type_t::data);
|
|
|
|
|
|
|
|
|
|
|
|
spdlog::info("adding data symbol: {} located inside of section: {}",
|
|
|
|
spdlog::info("adding data symbol: {} located inside of section: {}",
|
|
|
|
new_sym.name(),
|
|
|
|
new_sym.name(),
|
|
|
@ -114,6 +115,24 @@ std::optional<comp::symbol_table_t*> decomp_t::decompose() {
|
|
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_sym);
|
|
|
|
m_syms->add_symbol(new_sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (sym->storage_class ==
|
|
|
|
|
|
|
|
coff::storage_class_id::
|
|
|
|
|
|
|
|
external_definition) { // else if the symbol has no
|
|
|
|
|
|
|
|
// section... these symbols require
|
|
|
|
|
|
|
|
// the linker to allocate space for
|
|
|
|
|
|
|
|
// them...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the data is init to all zeros...
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> data(sym->value, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the symbol is data, it has no section...
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
decomp::symbol_t bss_sym(sym->name.to_string(img->get_strings()).data(),
|
|
|
|
|
|
|
|
{}, data, {}, sym, {}, sym_type_t::data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(bss_sym);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|