forked from IDontCode/Theodosius
parent
0e8d76b564
commit
062fdd49bd
@ -0,0 +1 @@
|
||||
Subproject commit 09b6654be0c52bf1df44e88c88b411a67b624cbd
|
@ -1,54 +0,0 @@
|
||||
#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,22 @@
|
||||
#pragma once
|
||||
#include <coff/archive.hpp>
|
||||
#include <coff/image.hpp>
|
||||
#include <theo/engine/iff.hpp>
|
||||
#include <theo/engine/swapchain.hpp>
|
||||
#include <theo/obf_pass/obf_pass.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
class engine_t
|
||||
{
|
||||
public:
|
||||
explicit engine_t( const std::vector< std::uint8_t > &lib_img );
|
||||
engine_t &add_pass( const obf_pass_t &pass );
|
||||
engine_t &add_passes( const std::vector< obf_pass_t > &passes );
|
||||
void run( std::vector< std::uint8_t > &result );
|
||||
|
||||
private:
|
||||
std::shared_ptr< theo::swapchain_t > swapchain;
|
||||
std::vector< theo::obf_pass_t > obf_passes;
|
||||
};
|
||||
} // namespace theo
|
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <coff/image.hpp>
|
||||
#include <vector>
|
||||
#include <xtils.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
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;
|
||||
};
|
||||
} // namespace theo
|
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <coff/archive.hpp>
|
||||
#include <coff/image.hpp>
|
||||
#include <theo/engine/iff.hpp>
|
||||
#include <xtils.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
class swapchain_t
|
||||
{
|
||||
/// <summary>
|
||||
/// pair of front and back buffers...
|
||||
/// changes are flushed to the back buffer, then the front
|
||||
/// buffer gets overwritten by the back buffer when swapped...
|
||||
/// </summary>
|
||||
struct pair_t
|
||||
{
|
||||
std::vector< std::uint8_t > front, back;
|
||||
};
|
||||
|
||||
std::vector< pair_t > objs;
|
||||
std::vector< std::uint8_t > archive;
|
||||
|
||||
public:
|
||||
explicit swapchain_t( const std::vector< std::uint8_t > &img );
|
||||
static std::shared_ptr< swapchain_t > make( const std::vector< std::uint8_t > &img );
|
||||
|
||||
/// <summary>
|
||||
/// if theo::swapchain::swap takes in an empty vector then it will simply fill it up
|
||||
/// instead of flushing the iff data to the back buffer then swapping...
|
||||
/// </summary>
|
||||
/// <param name="iffs"></param>
|
||||
void swap( std::vector< iff_t > &iffs );
|
||||
};
|
||||
} // namespace theo
|
@ -1,23 +0,0 @@
|
||||
#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,35 @@
|
||||
#pragma once
|
||||
#include <theo/symbol.hpp>
|
||||
#include <xtils.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
enum class lvl_t
|
||||
{
|
||||
/// <summary>
|
||||
/// callback gets passed entire IFF structures...
|
||||
/// </summary>
|
||||
l_iff,
|
||||
|
||||
/// <summary>
|
||||
/// callback gets passed entire IFF section structures...
|
||||
/// </summary>
|
||||
l_section,
|
||||
|
||||
/// <summary>
|
||||
/// callback gets passed entire IFF symbols...
|
||||
/// </summary>
|
||||
l_symbol
|
||||
};
|
||||
|
||||
class obf_pass_t
|
||||
{
|
||||
friend class engine_t;
|
||||
virtual void obfuscate( const theo::iff_t & ) = 0;
|
||||
lvl_t lvl;
|
||||
|
||||
public:
|
||||
explicit obf_pass_t( const lvl_t &pass_lvl );
|
||||
lvl_t get_lvl() const;
|
||||
};
|
||||
} // namespace theo
|
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
#include <theo/engine/engine.hpp>
|
||||
#include <theo/obf_pass/obf_pass.hpp>
|
||||
#include <theo/symbol.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
/// <summary>
|
||||
/// obfuscation pass at the IFF level...
|
||||
/// </summary>
|
||||
class obf_pass_iff_t : public obf_pass_t
|
||||
{
|
||||
void obfuscate( const theo::iff_t & ) override;
|
||||
|
||||
public:
|
||||
obf_pass_iff_t() : obf_pass_t( lvl_t::l_iff )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// obfuscation pass at the IFF section level...
|
||||
/// </summary>
|
||||
class obf_pass_section_t : public obf_pass_t
|
||||
{
|
||||
void obfuscate( const theo::iff_t & ) override;
|
||||
|
||||
public:
|
||||
obf_pass_section_t() : obf_pass_t( lvl_t::l_section )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// obfuscation pass at the IFF symbol level..
|
||||
/// </summary>
|
||||
class obf_pass_symbol_t : public obf_pass_t
|
||||
{
|
||||
void obfuscate( const theo::iff_t & ) override;
|
||||
|
||||
public:
|
||||
obf_pass_symbol_t() : obf_pass_t( lvl_t::l_symbol )
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace theo
|
@ -1,10 +1,27 @@
|
||||
#pragma once
|
||||
#include <coff/image.hpp>
|
||||
#include <xtils.hpp>
|
||||
|
||||
namespace llo
|
||||
#define XED_DECODER
|
||||
extern "C"
|
||||
{
|
||||
class symbol_t
|
||||
#include <xed-decode.h>
|
||||
}
|
||||
|
||||
namespace theo
|
||||
{
|
||||
class symbol_t
|
||||
{
|
||||
public:
|
||||
std::uint32_t symbol_table_idx;
|
||||
coff::symbol_t coff_symbol;
|
||||
|
||||
std::vector< symbol_t * > deps;
|
||||
std::vector< xed_decoded_inst_t > instrs;
|
||||
|
||||
void on_update();
|
||||
|
||||
public:
|
||||
symbol_t();
|
||||
void add_dep( const symbol_t &dep );
|
||||
};
|
||||
}
|
||||
} // namespace theo
|
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <theo/engine/engine.hpp>
|
||||
#include <theo/obf_pass/obf_pass_wrapper.hpp>
|
||||
#include <theo/symbol.hpp>
|
@ -0,0 +1,33 @@
|
||||
#include <theo/engine/engine.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
engine_t::engine_t( const std::vector< std::uint8_t > &lib_img ) : swapchain( theo::swapchain_t::make( lib_img ) )
|
||||
{
|
||||
}
|
||||
|
||||
engine_t &theo::engine_t::add_pass( const obf_pass_t &pass )
|
||||
{
|
||||
obf_passes.push_back( pass );
|
||||
return *this;
|
||||
}
|
||||
|
||||
engine_t &theo::engine_t::add_passes( const std::vector< obf_pass_t > &passes )
|
||||
{
|
||||
obf_passes.insert( obf_passes.end(), passes.begin(), passes.end() );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void theo::engine_t::run( std::vector< std::uint8_t > &result )
|
||||
{
|
||||
std::for_each( obf_passes.begin(), obf_passes.end(), [ & ]( theo::obf_pass_t &obf_pass ) {
|
||||
std::vector< theo::iff_t > iffs;
|
||||
swapchain->swap( iffs );
|
||||
|
||||
std::for_each( iffs.begin(), iffs.end(), [ & ]( const theo::iff_t &iff ) {
|
||||
obf_pass.obfuscate( iff );
|
||||
swapchain->swap( iffs );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
} // namespace theo
|
@ -0,0 +1,35 @@
|
||||
#include <theo/engine/swapchain.hpp>
|
||||
|
||||
namespace theo
|
||||
{
|
||||
swapchain_t::swapchain_t( const std::vector< std::uint8_t > &img ) : archive( img )
|
||||
{
|
||||
ar::view lib( archive.data(), archive.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() }, { coff_img.begin(), coff_img.end() } } );
|
||||
} );
|
||||
}
|
||||
|
||||
std::shared_ptr< theo::swapchain_t > swapchain_t::make( const std::vector< std::uint8_t > &img )
|
||||
{
|
||||
return std::make_shared< theo::swapchain_t >( img );
|
||||
}
|
||||
|
||||
void theo::swapchain_t::swap( std::vector< iff_t > &iffs )
|
||||
{
|
||||
if ( iffs.empty() )
|
||||
{
|
||||
for ( auto &[ front, back ] : objs )
|
||||
{
|
||||
theo::iff_t iff( reinterpret_cast< coff::image_t * >( front.data() ) );
|
||||
iffs.push_back( iff );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO flush results to the back buffer and swap front and back...
|
||||
}
|
||||
}
|
||||
} // namespace theo
|
Loading…
Reference in new issue