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:
|
||||
|
||||
};
|
||||
}
|
@ -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 §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
|
Loading…
Reference in new issue