|
|
|
@ -48,71 +48,90 @@ std::optional<comp::symbol_table_t*> decomp_t::decompose() {
|
|
|
|
|
// if the symbol is a function then we are going to decompose it...
|
|
|
|
|
// data symbols are handled after this...
|
|
|
|
|
//
|
|
|
|
|
if (sym->has_section() &&
|
|
|
|
|
sym->derived_type == coff::derived_type_id::function) {
|
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
|
auto dcmp_type =
|
|
|
|
|
scn->name.to_string(img->get_strings()) == INSTR_SPLIT_SECTION_NAME
|
|
|
|
|
? decomp::sym_type_t::inst_split
|
|
|
|
|
: decomp::sym_type_t::function;
|
|
|
|
|
auto fn_size = scn->size_raw_data;
|
|
|
|
|
auto fn_bgn = scn->ptr_raw_data + reinterpret_cast<std::uint8_t*>(img);
|
|
|
|
|
|
|
|
|
|
spdlog::info("decomposing function: {} size: {}",
|
|
|
|
|
sym->name.to_string(img->get_strings()), fn_size);
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> fn(fn_bgn, fn_bgn + fn_size);
|
|
|
|
|
decomp::routine_t rtn(sym, img, scn, fn, dcmp_type);
|
|
|
|
|
|
|
|
|
|
auto syms = rtn.decompose();
|
|
|
|
|
spdlog::info("decomposed routine into {} symbols...", syms.size());
|
|
|
|
|
m_syms->add_symbols(syms);
|
|
|
|
|
} else if (sym->has_section() &&
|
|
|
|
|
sym->storage_class == coff::storage_class_id::public_symbol) {
|
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
|
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
|
|
|
|
|
// symbol table...
|
|
|
|
|
//
|
|
|
|
|
if (!scn_sym.has_value()) {
|
|
|
|
|
auto scn_sym_name =
|
|
|
|
|
std::string(scn->name.to_string(img->get_strings()))
|
|
|
|
|
.append("#")
|
|
|
|
|
.append(std::to_string(sym->section_index - 1))
|
|
|
|
|
.append("!")
|
|
|
|
|
.append(std::to_string(img->file_header.timedate_stamp));
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> scn_data(
|
|
|
|
|
reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data,
|
|
|
|
|
reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data +
|
|
|
|
|
scn->size_raw_data);
|
|
|
|
|
|
|
|
|
|
decomp::symbol_t new_scn_sym(scn_sym_name, 0, scn_data, scn, {}, {},
|
|
|
|
|
sym_type_t::section);
|
|
|
|
|
|
|
|
|
|
spdlog::info(
|
|
|
|
|
"generating symbol for section: {} sym name: {} hash: {:X} "
|
|
|
|
|
"section size: {}",
|
|
|
|
|
scn->name.to_string(img->get_strings()), new_scn_sym.name(),
|
|
|
|
|
new_scn_sym.hash(), scn->size_raw_data);
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_scn_sym);
|
|
|
|
|
if (sym->has_section()) {
|
|
|
|
|
if (sym->derived_type == coff::derived_type_id::function) {
|
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
|
auto dcmp_type = scn->name.to_string(img->get_strings()) ==
|
|
|
|
|
INSTR_SPLIT_SECTION_NAME
|
|
|
|
|
? decomp::sym_type_t::inst_split
|
|
|
|
|
: decomp::sym_type_t::function;
|
|
|
|
|
auto fn_size = scn->size_raw_data;
|
|
|
|
|
auto fn_bgn =
|
|
|
|
|
scn->ptr_raw_data + reinterpret_cast<std::uint8_t*>(img);
|
|
|
|
|
|
|
|
|
|
spdlog::info("decomposing function: {} size: {}",
|
|
|
|
|
sym->name.to_string(img->get_strings()), fn_size);
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> fn(fn_bgn, fn_bgn + fn_size);
|
|
|
|
|
decomp::routine_t rtn(sym, img, scn, fn, dcmp_type);
|
|
|
|
|
|
|
|
|
|
auto syms = rtn.decompose();
|
|
|
|
|
spdlog::info("decomposed routine into {} symbols...", syms.size());
|
|
|
|
|
m_syms->add_symbols(syms);
|
|
|
|
|
} else if (sym->storage_class ==
|
|
|
|
|
coff::storage_class_id::public_symbol) {
|
|
|
|
|
auto scn = img->get_section(sym->section_index - 1);
|
|
|
|
|
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 symbol table...
|
|
|
|
|
//
|
|
|
|
|
if (!scn_sym.has_value()) {
|
|
|
|
|
auto scn_sym_name =
|
|
|
|
|
std::string(scn->name.to_string(img->get_strings()))
|
|
|
|
|
.append("#")
|
|
|
|
|
.append(std::to_string(sym->section_index - 1))
|
|
|
|
|
.append("!")
|
|
|
|
|
.append(std::to_string(img->file_header.timedate_stamp));
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> scn_data(
|
|
|
|
|
reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data,
|
|
|
|
|
reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data +
|
|
|
|
|
scn->size_raw_data);
|
|
|
|
|
|
|
|
|
|
decomp::symbol_t new_scn_sym(scn_sym_name, 0, scn_data, scn, {}, {},
|
|
|
|
|
sym_type_t::section);
|
|
|
|
|
|
|
|
|
|
spdlog::info(
|
|
|
|
|
"generating symbol for section: {} sym name: {} hash: {:X} "
|
|
|
|
|
"section size: {}",
|
|
|
|
|
scn->name.to_string(img->get_strings()), new_scn_sym.name(),
|
|
|
|
|
new_scn_sym.hash(), scn->size_raw_data);
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_scn_sym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create a symbol for the data...
|
|
|
|
|
//
|
|
|
|
|
decomp::symbol_t new_sym(
|
|
|
|
|
sym->name.to_string(img->get_strings()).data(), sym->value, {},
|
|
|
|
|
scn, sym, {}, sym_type_t::data);
|
|
|
|
|
|
|
|
|
|
spdlog::info("adding data symbol: {} located inside of section: {}",
|
|
|
|
|
new_sym.name(),
|
|
|
|
|
m_syms->sym_from_hash(m_scn_hash_tbl[new_sym.scn()])
|
|
|
|
|
.value()
|
|
|
|
|
.name());
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_sym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create a symbol for the data...
|
|
|
|
|
} 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...
|
|
|
|
|
//
|
|
|
|
|
decomp::symbol_t new_sym(sym->name.to_string(img->get_strings()).data(),
|
|
|
|
|
sym->value, {}, scn, sym, {},
|
|
|
|
|
sym_type_t::data);
|
|
|
|
|
std::vector<std::uint8_t> data(sym->value, 0);
|
|
|
|
|
|
|
|
|
|
spdlog::info("adding data symbol: {} located inside of section: {}",
|
|
|
|
|
new_sym.name(),
|
|
|
|
|
m_syms->sym_from_hash(m_scn_hash_tbl[new_sym.scn()])
|
|
|
|
|
.value()
|
|
|
|
|
.name());
|
|
|
|
|
// 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(new_sym);
|
|
|
|
|
m_syms->add_symbol(bss_sym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|