added theo::engine_t, as well as a swapchain design for applying

changes...
2.0
_xeroxz 4 years ago
parent 5246236cd3
commit 0e8d76b564

@ -0,0 +1,54 @@
#include <coff/archive.hpp>
#include <coff/image.hpp>
#include <theo/obf_pass.hpp>
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
{
/// <summary>
/// swapchain_t is the only one who needs to call iff_t::flush...
/// so its a friend class... flush is also private...
/// </summary>
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:
/// <summary>
/// flush changes from "sections" back to img...
/// </summary>
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

@ -0,0 +1,23 @@
#include <xtils.hpp>
#include <theo/symbol.hpp>
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

@ -0,0 +1,10 @@
#include <xtils.hpp>
namespace llo
{
class symbol_t
{
public:
};
}

@ -2,6 +2,7 @@
#include <cli-parser.hpp>
#include <coff/archive.hpp>
#include <coff/image.hpp>
#include <theo/engine.hpp>
#include <xtils.hpp>
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 } );
}

@ -0,0 +1,49 @@
#include <theo/engine.hpp>
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 &section_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

@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\theo\engine.cpp" />
</ItemGroup>
<ItemGroup>
<None Include=".clang-format" />
@ -86,6 +87,9 @@
<ClInclude Include="dependencies\xed\include\public\xed\xed-util.h" />
<ClInclude Include="dependencies\xed\include\public\xed\xed-version.h" />
<ClInclude Include="dependencies\xtils\xtils.hpp" />
<ClInclude Include="include\theo\engine.hpp" />
<ClInclude Include="include\theo\obf_pass.hpp" />
<ClInclude Include="include\theo\symbol.hpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
@ -122,17 +126,17 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(ProjectDir)include\;$(IncludePath);$(ProjectDir)include\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)dependencies\xtils;$(ProjectDir)dependencies\linux-pe\includes;$(ProjectDir)dependencies\xed\include\public\xed;$(ProjectDir)dependencies\cli-parser\;$(IncludePath);$(ProjectDir)include\</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
@ -153,7 +157,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<EnableModules>true</EnableModules>

@ -31,11 +31,20 @@
<Filter Include="Header Files\xed">
<UniqueIdentifier>{57f58b85-e562-44a1-a017-dd0237aa0d80}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\theo">
<UniqueIdentifier>{cb3ff52c-9bb7-4355-b0f1-508a0e8761e2}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\theo">
<UniqueIdentifier>{348d8bd4-31b6-445d-a487-bc39267daf6b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\theo\engine.cpp">
<Filter>Source Files\theo</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include=".clang-format">
@ -250,5 +259,14 @@
<ClInclude Include="dependencies\xed\include\public\xed\xed-version.h">
<Filter>Header Files\xed</Filter>
</ClInclude>
<ClInclude Include="include\theo\engine.hpp">
<Filter>Header Files\theo</Filter>
</ClInclude>
<ClInclude Include="include\theo\obf_pass.hpp">
<Filter>Header Files\theo</Filter>
</ClInclude>
<ClInclude Include="include\theo\symbol.hpp">
<Filter>Header Files\theo</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading…
Cancel
Save