Skip to content

revsic/cpp-obfuscator

Repository files navigation

cpp-obfuscator

License Build Status

C++ implementation of compile time obfuscator

Compiler Support

Compiler Version
Visual Studio 2019
Clang++ 8.0
g++ 7.3
Apple Clang Mojave

Usage

Use existing single header obfuscator.hpp or run script to merge multiple headers in directory obfuscator.

python -m script.merge

Include obfuscator.hpp to use it.

#include "../obfuscator.hpp"

template <char key>
constexpr char xor_(char c) {
    return c ^ key;
}

std::cout << obfs::make_string<xor_<0x50>, xor_<0x50>>("Hello World !\n").decode();

String

Compile time string obfuscator. No more raw string in binary, sample string_obfuscator.

  1. Sample encoder, decoder
template <char key>
constexpr char xor_(char c) {
    return c ^ key;
}

template <char Key>
constexpr char add(char c) {
    return c + Key;
}

template <char(*f)(char), char(*g)(char)>
constexpr char comp(char c) {
    return f(g(c));
}
  1. Single encoder, decoder.
std::cout << obfs::make_string<xor_<0x50>, xor_<0x50>>("Hello World !\n").decode();
  1. Multiple encoder, decoder and random selection.
using table = obfs::make_table<
    obfs::encoder_seq<xor_<0x50>, add<10>, comp<xor_<0x50>, add<10>>>,
    obfs::decoder_seq<xor_<0x50>, add<-10>, comp<add<-10>, xor_<0x50>>>>;

std::cout << obfs::make_string<table>("Hello World !\n").decode();
  1. Multiple encoder, decoder as pair.
using table = obfs::make_pair_table<
    obfs::encoder_pair<xor_<0x50>, xor_<0x50>>,
    obfs::encoder_pair<add<10>, add<-10>>,
    obfs::encoder_pair<comp<xor_<0x50>, add<10>>, comp<add<-10>, xor_<0x50>>>
>;

std::cout << obfs::make_string<table>("Hello World !\n").decode();
  1. String obfuscator macro.
MAKE_STRING(str, "Hello World !\n", table);
std::cout << str.decode();

Finite state machine

Compile time finite state machine based routine obfuscator, sample state_machine.

  1. Make state table.
using namespace obfs;
using machine = StateMachine<
    Stage<state1, Next<event5 , state2, Dummy::dummy1>,
                  Next<event1 , state3, Dummy::dummy3>>,
    Stage<state2, Next<event2 , state4>>,
    Stage<state3, Next<None   , state3>>,
    Stage<state4, Next<event4 , state1>,
                  Next<event3 , state5, Dummy::dummy2>>,
    Stage<state5, Next<Trigger, Final, Action::action>>>;
  1. Run state machine, each execution returns next state.
auto next1 = machine::run(state1{}, event5{}); // dummy1 executed
auto next2 = machine::run(next1, event2{});
auto next3 = machine::run(next2, event3{});    // dummy2 executed
auto next4 = machine::run(next3, Trigger{});   // action executed

About

C++ implementation of compile time obfuscator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published