From b3a0af913dfb8a1d17a1030d598e512c1ff20e31 Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Thu, 24 Jun 2021 18:06:19 -0700 Subject: [PATCH] added lib dctor... beginning work on symbol loader(s)... --- README.md | 1 + include/llodctor/llodctor_lib.cpp | 5 ++++ include/llodctor/llodctor_lib.hpp | 27 +++++++++++++++++++ .../llodisposition/llodisposition_types.hpp | 2 +- llo-s1.vcxproj | 5 ++++ llo-s1.vcxproj.filters | 3 +++ llo-s1.vcxproj.user | 9 ++++++- src/llodctor_pe.cpp | 5 +++- src/main.cpp | 7 ++++- 9 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 include/llodctor/llodctor_lib.cpp diff --git a/README.md b/README.md index f9738af..36ab5ee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # stage-one +this is a draft showing how stage one might be implimented using c++ inheritance. please refer to main.cpp for more. \ No newline at end of file diff --git a/include/llodctor/llodctor_lib.cpp b/include/llodctor/llodctor_lib.cpp new file mode 100644 index 0000000..a4841f3 --- /dev/null +++ b/include/llodctor/llodctor_lib.cpp @@ -0,0 +1,5 @@ +#include + +void llo::s1::dctor_lib_t::generate( lloiff_t &iff ) +{ +} \ No newline at end of file diff --git a/include/llodctor/llodctor_lib.hpp b/include/llodctor/llodctor_lib.hpp index e69de29..a6543c9 100644 --- a/include/llodctor/llodctor_lib.hpp +++ b/include/llodctor/llodctor_lib.hpp @@ -0,0 +1,27 @@ +#include +#include + +namespace llo::s1 +{ + class dctor_lib_t : public dctor_base_t + { + 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; + + do + { + // skip these since we dont want to extract them... they are not obj files... + if ( lib_entry->is_string_table() || lib_entry->is_symbol_table() ) + continue; + + std::printf( "> object name = %s\n", lib_entry->to_string()); + } while ( ( lib_entry = lib_header->first_entry.next() ) ); + } + void generate( lloiff_t &iff ) override; + }; +} // namespace llo::s1 \ No newline at end of file diff --git a/include/llodisposition/llodisposition_types.hpp b/include/llodisposition/llodisposition_types.hpp index 4cee73c..99975a8 100644 --- a/include/llodisposition/llodisposition_types.hpp +++ b/include/llodisposition/llodisposition_types.hpp @@ -9,7 +9,7 @@ namespace llo public: explicit disposition_t( const llo::utils::hash_t< std::string > &iff_name, const llo::utils::hash_t< std::string > §ion_name, std::uint32_t section_offset ) - : iff_name( iff_name ), section_name( section_name ), offset( offset ) + : iff_name( iff_name ), section_name( section_name ), offset( section_offset ) { } diff --git a/llo-s1.vcxproj b/llo-s1.vcxproj index 3329818..efaa38e 100644 --- a/llo-s1.vcxproj +++ b/llo-s1.vcxproj @@ -105,6 +105,7 @@ + @@ -163,6 +164,8 @@ Console true $(ProjectDir)dependencies\fcml\fcml.lib;%(AdditionalDependencies) + true + true @@ -181,6 +184,8 @@ true true $(ProjectDir)dependencies\fcml\fcml.lib;%(AdditionalDependencies) + true + true diff --git a/llo-s1.vcxproj.filters b/llo-s1.vcxproj.filters index 9957344..981dca8 100644 --- a/llo-s1.vcxproj.filters +++ b/llo-s1.vcxproj.filters @@ -330,5 +330,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/llo-s1.vcxproj.user b/llo-s1.vcxproj.user index 88a5509..6452c4d 100644 --- a/llo-s1.vcxproj.user +++ b/llo-s1.vcxproj.user @@ -1,4 +1,11 @@  - + + -i llo-s1.exe -s llo-s1.map + WindowsLocalDebugger + + + -i llo-s1.exe -s llo-s1.map + WindowsLocalDebugger + \ No newline at end of file diff --git a/src/llodctor_pe.cpp b/src/llodctor_pe.cpp index 0de7078..d01a5ad 100644 --- a/src/llodctor_pe.cpp +++ b/src/llodctor_pe.cpp @@ -17,15 +17,18 @@ void llo::s1::dctor_pe_t::generate( lloiff_t &iff ) // check to see if this section contains the entry point of the module... if ( entry_point >= sections[ idx ].virtual_address && entry_point < sections[ idx ].virtual_address + sections[ idx ].virtual_size ) + { // lift entry point to iff... iff.entry = - llo::disposition_t::make( iff.name, section_name, sections[ idx ].virtual_address - entry_point ); + llo::disposition_t::make( iff.name, section_name, ( entry_point - sections[ idx ].virtual_address ) ); + } // copy the sections raw bytes... section.raw.insert( section.raw.begin(), raw_img.data(), raw_img.data() + sections[ idx ].ptr_raw_data ); iff.sections.push_back( section ); } + // run symbol loader pass... this could be pdb, map, etc... if ( symbol_loader ) symbol_loader->load( iff ); } diff --git a/src/main.cpp b/src/main.cpp index 05e00ca..0524b99 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -73,6 +74,10 @@ int __cdecl main( int argc, const char *argv[] ) // TODO: elf file format... return -1; } + else if ( file_path.extension().compare( ".lib" ) ) + { + file_dctor = std::make_shared< llo::s1::dctor_lib_t >( image, symbol_loader.get() ); + } else { std::printf( "[!] unknown file extension: %s\n", file_path.extension().c_str() ); @@ -83,7 +88,7 @@ int __cdecl main( int argc, const char *argv[] ) file_dctor->generate( iff ); std::printf( "> number of sections = %d\n", iff.sections.size() ); - if ( iff.entry ) + 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 );