decomposes (extracts) the symbols used. this function determines all used symbols given the entry point.
41 ar::view<false>
lib(m_lib.data(), m_lib.size());
44 [&](std::pair<std::string_view, ar::entry_t&> itr) {
48 if (!itr.second.is_symbol_table() && !itr.second.is_string_table()) {
49 spdlog::info(
"extracted obj from archive: {}", itr.first);
50 std::vector<std::uint8_t> data(itr.second.begin(), itr.second.end());
51 m_objs.push_back(data);
56 m_objs.begin(), m_objs.end(), [&](std::vector<std::uint8_t>& img_data) {
57 auto img = reinterpret_cast<coff::image_t*>(img_data.data());
58 for (auto idx = 0u; idx < img->file_header.num_symbols; ++idx) {
59 auto sym = img->get_symbol(idx);
60 if (sym->section_index - 1 > img->file_header.num_sections)
63 auto sym_name = symbol_t::name(img, sym);
64 if (sym_name.length()) {
65 auto sym_hash = symbol_t::hash(sym_name.data());
68 ? next_sym(img, img->get_section(sym->section_index - 1),
72 m_lookup_tbl[sym_hash].emplace_back(img, sym, sym_size);
79 spdlog::info(
"extracted {} symbols being used...",
80 ext_used_syms(entry_sym.data()));
85 std::for_each(m_used_syms.begin(), m_used_syms.end(), [&](
sym_data_t data) {
86 auto [img, sym, size] = data;
92 if (m_processed_objs.emplace(img).second) {
93 for (auto idx = 0u; idx < img->file_header.num_sections; ++idx) {
94 auto scn = img->get_section(idx);
96 std::string(scn->name.to_string(img->get_strings()))
98 .append(std::to_string(idx))
100 .append(std::to_string(img->file_header.timedate_stamp));
105 m_scn_hash_tbl.insert({scn, decomp::symbol_t::hash(scn_sym_name)});
112 if (sym->has_section()) {
113 if (sym->derived_type == coff::derived_type_id::function) {
114 auto scn = img->get_section(sym->section_index - 1);
116 scn->name.to_string(img->get_strings()) == INSTR_SPLIT_SECTION_NAME
117 ? decomp::sym_type_t::instruction
118 : decomp::sym_type_t::function;
120 auto fn_size = next_sym(img, scn, sym);
121 auto fn_bgn = scn->ptr_raw_data + reinterpret_cast<std::uint8_t*>(img) +
124 std::vector<std::uint8_t> fn(fn_bgn, fn_bgn + fn_size);
125 decomp::routine_t rtn(sym, img, scn, fn, dcmp_type);
127 auto syms = rtn.decompose();
128 m_syms->put_symbols(syms);
129 }
else if (sym->storage_class == coff::storage_class_id::public_symbol ||
130 sym->storage_class == coff::storage_class_id::private_symbol) {
131 auto scn = img->get_section(sym->section_index - 1);
132 auto scn_sym = m_syms->sym_from_hash(m_scn_hash_tbl[scn]);
137 if (!scn_sym.has_value()) {
139 std::string(scn->name.to_string(img->get_strings()))
141 .append(std::to_string(sym->section_index - 1))
143 .append(std::to_string(img->file_header.timedate_stamp));
145 std::vector<std::uint8_t> scn_data(scn->size_raw_data);
146 if (scn->characteristics.cnt_uninit_data) {
147 scn_data.insert(scn_data.begin(), scn->size_raw_data, 0);
151 reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data,
152 reinterpret_cast<std::uint8_t*>(img) + scn->ptr_raw_data +
156 std::vector<recomp::reloc_t> relocs;
157 auto scn_relocs = reinterpret_cast<coff::reloc_t*>(
158 scn->ptr_relocs + reinterpret_cast<std::uint8_t*>(img));
160 for (auto idx = 0u; idx < scn->num_relocs; ++idx) {
161 auto scn_reloc = &scn_relocs[idx];
162 auto sym_reloc = img->get_symbol(scn_relocs[idx].symbol_index);
163 auto sym_name = symbol_t::name(img, sym_reloc);
164 auto sym_hash = decomp::symbol_t::hash(sym_name.data());
166 recomp::reloc_t(scn_reloc->virtual_address - sym->value,
167 sym_hash, sym_name.data()));
170 decomp::symbol_t new_scn_sym(img, scn_sym_name, 0, scn_data, scn, {},
171 relocs, sym_type_t::section);
173 m_syms->put_symbol(new_scn_sym);
179 sym->value, {}, scn, sym, {},
184 }
else if (sym->storage_class ==
185 coff::storage_class_id::
186 external_definition) {
191 std::vector<std::uint8_t> data(sym->value, 0);
192 decomp::symbol_t bss_sym(img, symbol_t::name(img, sym).data(), {},
data,
std::string name() const
gets the name of the symbol.
Definition: symbol.cpp:52
void put_symbol(decomp::symbol_t &sym)
add symbol to m_table
Definition: symbol_table.cpp:40
std::tuple< coff::image_t *, coff::symbol_t *, std::uint32_t > sym_data_t
meta symbol data. consists of the coff image which contains the coff symbol, the coff symbol itself,...
Definition: decomp.hpp:55
@ data
Definition: symbol.hpp:46