42 lines
1.6 KiB
42 lines
1.6 KiB
#include <theo/engine/iff.hpp>
|
|
|
|
namespace theo
|
|
{
|
|
iff_t::iff_t( coff::image_t *img )
|
|
{
|
|
const auto img_ptr = reinterpret_cast< std::uint8_t * >( img );
|
|
const auto num_sections = img->file_header.num_sections;
|
|
|
|
for ( auto section_num = 0u; section_num != num_sections; ++section_num )
|
|
{
|
|
const auto section = img->get_section( section_num );
|
|
iff_t::section_t iff_section{ *section };
|
|
|
|
if ( section->characteristics.mem_execute && section->size_raw_data )
|
|
{
|
|
xed_error_enum_t err;
|
|
xed_decoded_inst_t instr;
|
|
std::uint32_t offset = 0u;
|
|
const xed_state_t istate{ XED_MACHINE_MODE_LONG_64, XED_ADDRESS_WIDTH_64b };
|
|
xed_decoded_inst_zero_set_mode( &instr, &istate );
|
|
|
|
// decodes instructions for this given section...
|
|
while ( ( err = xed_decode( &instr, img_ptr + section->ptr_raw_data + offset,
|
|
section->size_raw_data - offset ) ) == XED_ERROR_NONE )
|
|
{
|
|
offset += xed_decoded_inst_get_length( &instr );
|
|
iff_section.instrs.push_back( instr );
|
|
}
|
|
}
|
|
|
|
// add all symbols for this section...
|
|
for ( auto idx = 0u; idx < img->file_header.num_symbols; ++idx )
|
|
if ( img->get_symbol( idx )->section_index - 1 == section_num )
|
|
iff_section.symbols.push_back( { idx, *img->get_symbol( idx ) } );
|
|
}
|
|
}
|
|
|
|
void iff_t::flush()
|
|
{
|
|
}
|
|
} // namespace theo
|