36 coff::section_header_t* scn,
37 std::vector<std::uint8_t>& fn,
39 : m_img(img), m_scn(scn), m_data(fn), m_dcmp_type(dcmp_type), m_sym(sym) {}
42 std::vector<decomp::symbol_t> result;
44 switch (m_dcmp_type) {
46 std::vector<recomp::reloc_t> relocs;
47 auto scn_relocs =
reinterpret_cast<coff::reloc_t*
>(
48 m_scn->ptr_relocs +
reinterpret_cast<std::uint8_t*
>(m_img));
50 for (
auto idx = 0u; idx < m_scn->num_relocs; ++idx) {
51 auto scn_reloc = &scn_relocs[idx];
53 if (scn_reloc->virtual_address >= m_sym->value &&
54 scn_reloc->virtual_address < m_sym->value + m_data.size()) {
55 auto sym_reloc = m_img->get_symbol(scn_relocs[idx].symbol_index);
60 sym_hash, sym_name.data()));
70 std::uint32_t offset = {};
73 xed_decoded_inst_t instr;
74 xed_state_t istate{XED_MACHINE_MODE_LONG_64, XED_ADDRESS_WIDTH_64b};
75 xed_decoded_inst_zero_set_mode(&instr, &istate);
79 while ((err = xed_decode(&instr, m_data.data() + offset,
80 m_data.size() - offset)) == XED_ERROR_NONE) {
88 new_sym_name.append(
"@").append(std::to_string(offset));
90 std::vector<recomp::reloc_t> relocs;
91 auto scn_relocs =
reinterpret_cast<coff::reloc_t*
>(
92 m_scn->ptr_relocs +
reinterpret_cast<std::uint8_t*
>(m_img));
97 auto reloc = std::find_if(
98 scn_relocs, scn_relocs + m_scn->num_relocs,
99 [&](coff::reloc_t reloc) {
100 return reloc.virtual_address >= m_sym->value + offset &&
101 reloc.virtual_address <
102 m_sym->value + offset +
103 xed_decoded_inst_get_length(&instr);
108 if (reloc != scn_relocs + m_scn->num_relocs) {
109 auto sym_reloc = m_img->get_symbol(reloc->symbol_index);
112 auto reloc_offset = reloc->virtual_address - m_sym->value - offset;
125 .append(std::to_string(offset +
126 xed_decoded_inst_get_length(&instr)));
133 std::vector<std::uint8_t> inst_bytes(
134 m_data.data() + offset,
135 m_data.data() + offset + xed_decoded_inst_get_length(&instr));
138 inst_bytes, m_scn, m_sym, relocs,
145 offset += xed_decoded_inst_get_length(&instr);
146 xed_format_context(XED_SYNTAX_INTEL, &instr, buff,
sizeof buff, NULL,
149 spdlog::info(
"{}: {}", new_sym_name, buff);
151 xed_decoded_inst_zero_set_mode(&instr, &istate);
156 auto& last_inst = result.back();
157 auto& last_inst_relocs = last_inst.relocs();
158 last_inst_relocs.erase(last_inst_relocs.end() - 1);