diff --git a/include/theo/engine.hpp b/include/theo/engine.hpp new file mode 100644 index 0000000..559564e --- /dev/null +++ b/include/theo/engine.hpp @@ -0,0 +1,54 @@ +#include +#include +#include + +namespace theo +{ + class engine_t + { + class swapchain_t + { + std::vector< std::uint8_t > front, back; + std::vector< std::vector< std::uint8_t > > objs; + + public: + class iff_t + { + /// + /// swapchain_t is the only one who needs to call iff_t::flush... + /// so its a friend class... flush is also private... + /// + friend class swapchain_t; + + public: + struct section_t + { + coff::section_header_t header; + std::vector< std::pair< std::uint32_t, coff::symbol_t > > symbols; + }; + + explicit iff_t( coff::image_t *img ); + std::vector< section_t > sections; + + private: + /// + /// flush changes from "sections" back to img... + /// + void flush(); + coff::image_t *img; + }; + explicit swapchain_t( const std::vector< std::uint8_t > &img ); + std::shared_ptr< swapchain_t > make( const std::vector< std::uint8_t > &img ); + void swap( std::vector< iff_t > &iffs ); + }; + + public: + explicit engine_t( const std::vector< std::uint8_t > &lib_img ); + void add_pass( const obf_pass_t &pass ); + void run( std::vector< std::uint8_t > &result ); + + private: + swapchain_t swap; + std::vector< theo::obf_pass_t > passes; + }; +} // namespace theo \ No newline at end of file diff --git a/include/theo/obf_pass.hpp b/include/theo/obf_pass.hpp new file mode 100644 index 0000000..2a176c2 --- /dev/null +++ b/include/theo/obf_pass.hpp @@ -0,0 +1,23 @@ +#include +#include + +namespace theo +{ + class obf_pass_t + { + friend class engine_t; + + public: + enum class lvl_t + { + l_section, + l_function, + l_instr + }; + obf_pass_t( const lvl_t &pass_lvl ); + + private: + virtual void callback() = 0; + lvl_t lvl; + }; +} // namespace theo \ No newline at end of file diff --git a/include/theo/symbol.hpp b/include/theo/symbol.hpp new file mode 100644 index 0000000..bec3c2f --- /dev/null +++ b/include/theo/symbol.hpp @@ -0,0 +1,10 @@ +#include + +namespace llo +{ + class symbol_t + { + public: + + }; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 40ab3c7..757d7e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include int __cdecl main( int argc, const char *argv[] ) @@ -27,23 +28,7 @@ int __cdecl main( int argc, const char *argv[] ) std::vector< std::uint8_t > lib; umtils->open_binary_file( cli_parser.get< std::string >( "i" ), lib ); - ar::view lib_view( lib.data(), lib.size() ); - const auto &symbol_map = lib_view.read_symbols(); - for ( auto itr = lib_view.begin(); itr != lib_view.end(); ++itr ) - { - std::printf( "> itr->to_string = %s\n", itr->to_string( lib_view.string_table ).data() ); - - auto coff_img = reinterpret_cast< coff::image_t * >( itr->data() ); - std::printf( "> number of sections = %d\n", coff_img->file_header.num_sections ); - - for ( auto idx = 0u; idx < coff_img->file_header.num_sections; ++idx ) - { - if ( coff_img->get_section( idx )->is_discardable() ) - continue; - - std::printf( "> section name = %s\n", - coff_img->get_section( idx )->name.to_string( coff_img->get_strings() ).data() ); - } - } + theo::engine_t theo( lib ); + //theo.add_pass( { theo::obf_pass_t::lvl_t::l_function } ); } \ No newline at end of file diff --git a/src/theo/engine.cpp b/src/theo/engine.cpp new file mode 100644 index 0000000..eb1a8b2 --- /dev/null +++ b/src/theo/engine.cpp @@ -0,0 +1,49 @@ +#include + +namespace theo +{ + engine_t::swapchain_t::iff_t::iff_t( coff::image_t *img ) + { + // add sections to iff... + std::for_each( img->get_sections(), img->get_sections() + img->file_header.num_sections, + [ & ]( const coff::section_header_t §ion_header ) { + sections.emplace_back( section_header ); + + // add symbols to section... + const auto num_symbols = img->file_header.num_symbols; + for ( auto idx = 0u; idx < num_symbols; ++idx ) + // important to note that we are making a COPY of this symbol... + sections.back().symbols.push_back( { idx, *img->get_symbol( idx ) } ); + } ); + } + + void engine_t::swapchain_t::iff_t::flush() + { + // for each section, loop over symbols to see if they have changed... + std::for_each( sections.begin(), sections.end(), [ & ]( const iff_t::section_t &iff_section ) { + std::for_each( iff_section.symbols.begin(), iff_section.symbols.end(), [ & ]( const auto &symbol_data ) { + const auto &[ symbol_idx, symbol ] = symbol_data; + img->get_symbol( symbol_idx )->value = symbol.value; + } ); + } ); + } + + engine_t::swapchain_t::swapchain_t( const std::vector< std::uint8_t > &img ) : front( img ), back( img ) + { + ar::view lib( front.data(), front.size() ); + // extract obj files from lib archive... + std::for_each( lib.begin(), lib.end(), [ & ]( const auto &coff_data ) { + const auto &[ coff_name, coff_img ] = coff_data; + objs.push_back( { coff_img.begin(), coff_img.end() } ); + } ); + } + + std::shared_ptr< engine_t::swapchain_t > engine_t::swapchain_t::make( const std::vector< std::uint8_t > &img ) + { + return std::make_shared< engine_t::swapchain_t >( img ); + } + + engine_t::engine_t( const std::vector< std::uint8_t > &lib_img ) : swap{ lib_img } + { + } +} // namespace theo \ No newline at end of file diff --git a/theodosius.vcxproj b/theodosius.vcxproj index 8c957ad..009a93f 100644 --- a/theodosius.vcxproj +++ b/theodosius.vcxproj @@ -12,6 +12,7 @@ + @@ -86,6 +87,9 @@ + + + 16.0 @@ -122,17 +126,17 @@ true - $(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath) + $(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(ProjectDir)include\;$(IncludePath);$(ProjectDir)include\ false - $(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath) + $(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath);$(ProjectDir)include\ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS true stdcpplatest @@ -153,7 +157,7 @@ true true true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS true stdcpplatest true diff --git a/theodosius.vcxproj.filters b/theodosius.vcxproj.filters index aaa6a67..846fbd5 100644 --- a/theodosius.vcxproj.filters +++ b/theodosius.vcxproj.filters @@ -31,11 +31,20 @@ {57f58b85-e562-44a1-a017-dd0237aa0d80} + + {cb3ff52c-9bb7-4355-b0f1-508a0e8761e2} + + + {348d8bd4-31b6-445d-a487-bc39267daf6b} + Source Files + + Source Files\theo + @@ -250,5 +259,14 @@ Header Files\xed + + Header Files\theo + + + Header Files\theo + + + Header Files\theo + \ No newline at end of file