You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
2.2 KiB
45 lines
2.2 KiB
#include <llodctor/llodctor_coff.hpp>
|
|
|
|
namespace llo::s1
|
|
{
|
|
void dctor_coff_t::generate( lloiff_t &iff )
|
|
{
|
|
std::for_each(
|
|
img_header->get_sections(), img_header->get_sections() + num_sections,
|
|
[ & ]( const coff::section_header_t section_header ) {
|
|
const auto section_name = std::string( section_header.name.to_string( img_header->get_strings() ) );
|
|
lloiff_t::iff_section_t iff_section{ section_name };
|
|
|
|
iff_section.raw = { img.data() + section_header.ptr_raw_data,
|
|
img.data() + section_header.ptr_raw_data + section_header.size_raw_data };
|
|
|
|
const auto &prots = section_header.prots;
|
|
iff_section.characteristics.prot = { prots.mem_execute, prots.mem_write, prots.mem_discardable };
|
|
iff_section.characteristics.characteristics = section_header.prots.flags;
|
|
|
|
// if the section is writable then we want to disassamble the entire section...
|
|
if ( iff_section.characteristics.prot.is_executable && iff_section.raw.data() )
|
|
{
|
|
std::uint32_t offset = 0u;
|
|
xed_error_enum_t err;
|
|
|
|
xed_decoded_inst_t instr;
|
|
xed_state_t istate{ XED_MACHINE_MODE_LONG_64, XED_ADDRESS_WIDTH_64b };
|
|
xed_decoded_inst_zero_set_mode( &instr, &istate );
|
|
|
|
// keep looping over the section, lower the number of bytes each time...
|
|
while ( ( err = xed_decode( &instr, iff_section.raw.data() + offset,
|
|
iff_section.raw.size() - offset ) ) == XED_ERROR_NONE )
|
|
{
|
|
offset += xed_decoded_inst_get_length( &instr );
|
|
iff_section.instrs.push_back( instr );
|
|
|
|
// need to set this so that instr can be used to decode again...
|
|
xed_decoded_inst_zero_set_mode( &instr, &istate );
|
|
}
|
|
}
|
|
|
|
iff.sections.emplace_back( iff_section );
|
|
} );
|
|
}
|
|
} // namespace llo::s1
|