From ac061639266b21f3d5fccedee3324ed75eabd855 Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Thu, 24 Jun 2021 16:25:46 -0700 Subject: [PATCH] lifted pe sections to iff... still needs to be mulled over... --- include/lloiff.hpp | 22 ++++++++++++++-------- src/llodctor_pe.cpp | 10 +++++++++- src/main.cpp | 10 +++++++++- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/lloiff.hpp b/include/lloiff.hpp index 8e377e5..cfc842f 100644 --- a/include/lloiff.hpp +++ b/include/lloiff.hpp @@ -12,22 +12,23 @@ namespace llo class lloiff_t { public: - explicit lloiff_t( std::string &&file_name ) : file_name( file_name ) - { - } - - lloiff_t( std::string &file_name ) : file_name( file_name ) - { - } - class section_t { public: llo::utils::hash_t< std::string > section_name; + std::uint64_t characteristics; std::vector< std::shared_ptr< llo::symbol::symbol_base_t > > symbols; std::vector< std::uint8_t > section_raw; }; + explicit lloiff_t( std::string &&file_name ) : file_name( file_name ) + { + } + + lloiff_t( std::string &file_name ) : file_name( file_name ) + { + } + llo::utils::hash_t< std::string > get_name() const { return file_name; @@ -43,6 +44,11 @@ namespace llo sections.push_back( section ); } + void add_section( section_t §ion ) + { + sections.push_back( section ); + } + private: llo::utils::hash_t< std::string > file_name; std::vector< section_t > sections; diff --git a/src/llodctor_pe.cpp b/src/llodctor_pe.cpp index ffa1dd6..1ac9a1b 100644 --- a/src/llodctor_pe.cpp +++ b/src/llodctor_pe.cpp @@ -6,9 +6,17 @@ void llo::s1::dctor_pe_t::generate( lloiff_t &iff ) auto sections = dos_header->get_nt_headers()->get_sections(); auto section_count = dos_header->get_nt_headers()->file_header.num_sections; - for ( auto idx = 0u; idx < section_count; ++idx, ++sections ) + for ( auto idx = 0u; idx < section_count; ++idx ) { + llo::utils::hash_t< std::string > section_name{ std::string( sections[idx].name.to_string() ) }; + llo::lloiff_t::section_t section{ section_name }; + section.characteristics = sections[idx].characteristics.flags; + // copy the sections raw bytes... + section.section_raw.insert( section.section_raw.begin(), raw_img.data(), + raw_img.data() + sections[ idx ].ptr_raw_data ); + + iff.add_section( section ); } if ( symbol_loader ) diff --git a/src/main.cpp b/src/main.cpp index 07d0790..d9b4159 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,5 +82,13 @@ int __cdecl main( int argc, const char *argv[] ) llo::lloiff_t iff( file_name ); file_dctor->generate( iff ); - std::printf( "> number of sections = %d\n", iff.get_sections().size() ); + const auto §ions = iff.get_sections(); + std::printf( "> number of sections = %d\n", sections.size() ); + + for ( auto §ion : sections ) + { + std::printf( "> section name = %s\n", section.section_name.get_data().c_str() ); + std::printf( "> size of raw section = %d\n", section.section_raw.size() ); + std::printf( "> number of symbols = %d\n", section.symbols.size() ); + } } \ No newline at end of file