|
|
@ -24,7 +24,7 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
std::for_each(m_objs.begin(), m_objs.end(), [&](coff::image_t* img) {
|
|
|
|
std::for_each(m_objs.begin(), m_objs.end(), [&](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 sym = img->get_symbol(idx);
|
|
|
|
auto sym = img->get_symbol(idx);
|
|
|
|
auto sym_name = sym->name.to_string(img->get_strings());
|
|
|
|
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 =
|
|
|
@ -104,7 +104,7 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
.append("!")
|
|
|
|
.append("!")
|
|
|
|
.append(std::to_string(img->file_header.timedate_stamp));
|
|
|
|
.append(std::to_string(img->file_header.timedate_stamp));
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> scn_data;
|
|
|
|
std::vector<std::uint8_t> scn_data(scn->size_raw_data);
|
|
|
|
if (scn->characteristics.cnt_uninit_data) {
|
|
|
|
if (scn->characteristics.cnt_uninit_data) {
|
|
|
|
scn_data.insert(scn_data.begin(), scn->size_raw_data, 0);
|
|
|
|
scn_data.insert(scn_data.begin(), scn->size_raw_data, 0);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -115,17 +115,31 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
scn->size_raw_data);
|
|
|
|
scn->size_raw_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<recomp::reloc_t> relocs;
|
|
|
|
|
|
|
|
auto scn_relocs = reinterpret_cast<coff::reloc_t*>(
|
|
|
|
|
|
|
|
scn->ptr_relocs + reinterpret_cast<std::uint8_t*>(img));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto idx = 0u; idx < scn->num_relocs; ++idx) {
|
|
|
|
|
|
|
|
auto scn_reloc = &scn_relocs[idx];
|
|
|
|
|
|
|
|
auto sym_reloc = img->get_symbol(scn_relocs[idx].symbol_index);
|
|
|
|
|
|
|
|
auto sym_name = symbol_t::name(img, sym_reloc);
|
|
|
|
|
|
|
|
auto sym_hash = decomp::symbol_t::hash(sym_name.data());
|
|
|
|
|
|
|
|
relocs.push_back(
|
|
|
|
|
|
|
|
recomp::reloc_t(scn_reloc->virtual_address - sym->value,
|
|
|
|
|
|
|
|
sym_hash, sym_name.data()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
decomp::symbol_t new_scn_sym(img, scn_sym_name, 0, scn_data, scn, {},
|
|
|
|
decomp::symbol_t new_scn_sym(img, scn_sym_name, 0, scn_data, scn, {},
|
|
|
|
{}, sym_type_t::section);
|
|
|
|
relocs, sym_type_t::section);
|
|
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_scn_sym);
|
|
|
|
m_syms->add_symbol(new_scn_sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// create a symbol for the data...
|
|
|
|
// create a symbol for the data...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
decomp::symbol_t new_sym(
|
|
|
|
decomp::symbol_t new_sym(img, symbol_t::name(img, sym).data(),
|
|
|
|
img, sym->name.to_string(img->get_strings()).data(), sym->value, {},
|
|
|
|
sym->value, {}, scn, sym, {},
|
|
|
|
scn, sym, {}, sym_type_t::data);
|
|
|
|
sym_type_t::data);
|
|
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(new_sym);
|
|
|
|
m_syms->add_symbol(new_sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,9 +151,8 @@ std::optional<recomp::symbol_table_t*> decomp_t::decompose(
|
|
|
|
// space for them...
|
|
|
|
// space for them...
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::uint8_t> data(sym->value, 0);
|
|
|
|
std::vector<std::uint8_t> data(sym->value, 0);
|
|
|
|
decomp::symbol_t bss_sym(img,
|
|
|
|
decomp::symbol_t bss_sym(img, symbol_t::name(img, sym).data(), {}, data,
|
|
|
|
sym->name.to_string(img->get_strings()).data(),
|
|
|
|
{}, sym, {}, sym_type_t::data);
|
|
|
|
{}, data, {}, sym, {}, sym_type_t::data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_syms->add_symbol(bss_sym);
|
|
|
|
m_syms->add_symbol(bss_sym);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -188,7 +201,7 @@ std::uint32_t decomp_t::ext_used_syms(const std::string&& entry_sym) {
|
|
|
|
if (reloc->virtual_address >= sym->value &&
|
|
|
|
if (reloc->virtual_address >= sym->value &&
|
|
|
|
reloc->virtual_address < sym->value + size) {
|
|
|
|
reloc->virtual_address < sym->value + size) {
|
|
|
|
auto reloc_sym = img->get_symbol(reloc->symbol_index);
|
|
|
|
auto reloc_sym = img->get_symbol(reloc->symbol_index);
|
|
|
|
auto sym_name = reloc_sym->name.to_string(img->get_strings());
|
|
|
|
auto sym_name = symbol_t::name(img, reloc_sym);
|
|
|
|
entry = get_symbol(sym_name);
|
|
|
|
entry = get_symbol(sym_name);
|
|
|
|
if (m_used_syms.emplace(entry.value()).second)
|
|
|
|
if (m_used_syms.emplace(entry.value()).second)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|