diff --git a/include/llodctor/llodctor_lib.hpp b/include/llodctor/llodctor_lib.hpp index c77127c..c3a82e2 100644 --- a/include/llodctor/llodctor_lib.hpp +++ b/include/llodctor/llodctor_lib.hpp @@ -1,28 +1,36 @@ #include +#include #include namespace llo::s1 { class dctor_lib_t : public dctor_base_t { + struct obj_t + { + std::string_view name; + std::vector< std::uint8_t > raw; + + coff::image_t *operator->() + { + return reinterpret_cast< coff::image_t * >( raw.data() ); + } + }; + + std::vector< obj_t > objs; + public: explicit dctor_lib_t( const std::vector< std::uint8_t > &image, llo::s1::symbol_loader_base_t *symbol_loader = nullptr ) : dctor_base_t( image, symbol_loader ) { - const auto lib_header = reinterpret_cast< const ar::header_t * >( image.data() ); - auto lib_entry = &lib_header->first_entry; - ar::entry_t *string_table = nullptr; + ar::view lib( image.data(), image.size() ); - do + for ( auto itr = lib.begin(); itr != lib.end(); ++itr ) { - // TODO... - // BROKE! - if ( lib_entry->is_string_table() ) - string_table = ( ar::entry_t * )lib_entry; - - std::printf( "> object name = %s\n", lib_entry->to_string( string_table ) ); - } while ( ( lib_entry = lib_header->first_entry.next() ) ); + std::vector obj_data( itr->begin(), itr->end() ); + objs.push_back( { itr->to_string( lib.string_table ), obj_data } ); + } } void generate( lloiff_t &iff ) override; }; diff --git a/include/lloiff.hpp b/include/lloiff.hpp index 9103f0c..9582f5b 100644 --- a/include/lloiff.hpp +++ b/include/lloiff.hpp @@ -26,11 +26,53 @@ namespace llo llo::utils::hash_t< std::string > section_name; /// - /// opaque value, lifted from the original file format... - /// this is should only be used by code that understands what the underlying file - /// format was... + /// section protections... /// - std::uint64_t characteristics; + struct prot_t + { + /// + /// section protection types... + /// + enum prot_e : std::uint16_t + { + none = 0b0000, + executable = 0b0001, + writeable = 0b0010 + }; + + /// + /// IL section protections (writeable/executable)... + /// + prot_e prots; + + /// + /// opaque value containing the native characteristics... + /// + std::uint64_t native; + + /// + /// returns true if section is executable... + /// + /// + bool is_executable() + { + return ( prots & prot_e::executable ); + } + + /// + /// returns true if section is writable... + /// + /// + bool is_writable() + { + return ( prots & prot_e::writeable ); + } + }; + + /// + /// section protections and characteristics + /// + prot_t protections; /// /// vector of symbols for this section... @@ -52,6 +94,17 @@ namespace llo { } + /// + /// makes a shared pointer containing a llo::lloiff_t... + /// + /// name of the file... + /// vector of bytes containing the raw file... + /// returns a shared pointer of the new object... + static std::shared_ptr< llo::lloiff_t > make( const std::string &name, const std::vector< std::uint8_t > &raw ) + { + return std::make_shared< llo::lloiff_t >( name, raw ); + } + /// /// entry point, where code execution begins.... /// this is lifted from the underlying file format... @@ -72,5 +125,11 @@ namespace llo /// vector of bytes containing the entire original file... /// std::vector< std::uint8_t > raw; + + /// + /// some file formats contain multiple other files inside of them such as LIB... + /// which is just an archive of OBJ's... + /// + std::vector< std::shared_ptr< llo::lloiff_t > > children; }; } // namespace llo \ No newline at end of file diff --git a/include/llosymbol/llosymbol_opaque.hpp b/include/llosymbol/llosymbol_opaque.hpp index 6f6313b..7d33ccf 100644 --- a/include/llosymbol/llosymbol_opaque.hpp +++ b/include/llosymbol/llosymbol_opaque.hpp @@ -4,6 +4,8 @@ namespace llo::symbol { class symbol_opaque_t : public symbol_base_t { + symbol_type_t type = symbol_type_t::s_opaque; + public: explicit symbol_opaque_t( const llo::utils::hash_t< std::string > &symbol_name, const llo::disposition_t &disposition ) @@ -14,6 +16,7 @@ namespace llo::symbol static std::shared_ptr< symbol_opaque_t > make( const llo::utils::hash_t< std::string > &symbol_name, const llo::disposition_t &disposition ); + void set_size( std::size_t size ); symbol_type_t get_type() const override; std::size_t get_size() const override; }; diff --git a/include/llosymbol_loader/llosymbol_loader_coff.hpp b/include/llosymbol_loader/llosymbol_loader_coff.hpp new file mode 100644 index 0000000..e69de29 diff --git a/llo-s1.vcxproj b/llo-s1.vcxproj index 7a9b3a2..1b6bf95 100644 --- a/llo-s1.vcxproj +++ b/llo-s1.vcxproj @@ -93,6 +93,7 @@ + diff --git a/llo-s1.vcxproj.filters b/llo-s1.vcxproj.filters index 1fc64cb..6076016 100644 --- a/llo-s1.vcxproj.filters +++ b/llo-s1.vcxproj.filters @@ -311,6 +311,9 @@ Header Files\linux-pe\coff\auxiliaries + + Header Files\llosymbol_loader + diff --git a/llo-s1.vcxproj.user b/llo-s1.vcxproj.user index 1d9f7e1..16c21f5 100644 --- a/llo-s1.vcxproj.user +++ b/llo-s1.vcxproj.user @@ -5,7 +5,7 @@ WindowsLocalDebugger - -i llo-s1.lib + -i demo.lib WindowsLocalDebugger \ No newline at end of file diff --git a/src/llodctor/llodctor_lib.cpp b/src/llodctor/llodctor_lib.cpp index bcd6c40..dc4aeff 100644 --- a/src/llodctor/llodctor_lib.cpp +++ b/src/llodctor/llodctor_lib.cpp @@ -2,5 +2,28 @@ void llo::s1::dctor_lib_t::generate( lloiff_t &iff ) { - // TODO + // add obj as children to the IFF as the IFF passed in is simply + // the LIB... also add section information for each... + std::for_each( objs.begin(), objs.end(), [ & ]( llo::s1::dctor_lib_t::obj_t &obj ) { + // use llo::lloiff::make to make a std::shared_ptr... + iff.children.push_back( iff.make( std::string( obj.name ), obj.raw ) ); + + // add sections to last IFF... + for ( auto idx = 0u; idx < obj->file_header.num_sections; ++idx ) + { + auto obj_section = obj->get_section( idx ); + std::string section_name( obj_section->name.to_string( obj->get_strings() ) ); + llo::lloiff_t::iff_section_t section{ section_name }; + + section.protections.native = obj_section->prots.flags; + section.raw.insert( section.raw.begin(), obj_section->ptr_raw_data + obj.raw.data(), + obj_section->size_raw_data + obj_section->ptr_raw_data + obj.raw.data() ); + + iff.children.back()->sections.push_back( section ); + } + } ); + + // coff symbol loader... + if ( symbol_loader ) + symbol_loader->load( iff ); } \ No newline at end of file diff --git a/src/llodctor/llodctor_pe.cpp b/src/llodctor/llodctor_pe.cpp index 192b7a0..7dc6dc7 100644 --- a/src/llodctor/llodctor_pe.cpp +++ b/src/llodctor/llodctor_pe.cpp @@ -7,7 +7,7 @@ void llo::s1::dctor_pe_t::generate( lloiff_t &iff ) { llo::utils::hash_t< std::string > section_name{ std::string( sections[ idx ].name.to_string() ) }; llo::lloiff_t::iff_section_t section{ section_name }; - section.characteristics = sections[ idx ].characteristics.flags; + section.protections.native = sections[ idx ].prots.flags; // check to see if this section contains the entry point of the module... if ( entry_point >= sections[ idx ].virtual_address && diff --git a/src/llosymbol/llosymbol_opaque.cpp b/src/llosymbol/llosymbol_opaque.cpp index 1ac7ff3..2ae2b43 100644 --- a/src/llosymbol/llosymbol_opaque.cpp +++ b/src/llosymbol/llosymbol_opaque.cpp @@ -10,11 +10,16 @@ namespace llo::symbol symbol_type_t symbol_opaque_t::get_type() const { - return symbol_type_t::s_opaque; + return type; } std::size_t symbol_opaque_t::get_size() const { return symbol_size; } + + void symbol_opaque_t::set_size( std::size_t size ) + { + symbol_size = size; + } } // namespace llo::symbol \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 24622a2..2ceb500 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,15 +92,18 @@ int __cdecl main( int argc, const char *argv[] ) llo::lloiff_t iff( name, image ); file_dctor->generate( iff ); - std::printf( "> number of sections = %d\n", iff.sections.size() ); - if ( iff.entry.get() ) - std::printf( "> entry section name = %s, section offest = 0x%x\n", iff.entry->section_name.get_data().c_str(), - iff.entry->offset ); - - for ( auto §ion : iff.sections ) + std::printf( "> iff number of children = %d\n", iff.children.size() ); + for ( auto &child : iff.children ) { - std::printf( "> section name = %s\n", section.section_name.get_data().c_str() ); - std::printf( "> size of raw section = %d\n", section.raw.size() ); - std::printf( "> number of symbols = %d\n", section.symbols.size() ); + if ( iff.entry.get() ) + std::printf( "> entry section name = %s, section offest = 0x%x\n", + iff.entry->section_name.get_data().c_str(), iff.entry->offset ); + + for ( auto §ion : child->sections ) + { + std::printf( "> section name = %s\n", section.section_name.get_data().c_str() ); + std::printf( "> size of raw section = %d\n", section.raw.size() ); + std::printf( "> number of symbols = %d\n", section.symbols.size() ); + } } } \ No newline at end of file