#ifndef OBFUSCATOR_HPP #define OBFUSCATOR_HPP #include #include #define COMPILE_TIME_SEQUENCE #define OBFS_FINITE_STATE_MACHINE #define COMPILE_TIME_RANDOM #define MAKE_RAND_VAL(MOD) obfs::RAND_VAL<__LINE__, MOD> #define OBFS_STRING #define MAKE_STRING(Var, String, ...) constexpr auto Var = obfs::make_string<__VA_ARGS__>(String); namespace obfs { template struct TypeVal { using value_type = T; constexpr static T value = Val; }; struct Nothing {}; template struct Sequence { using value = TypeVal; using next = Sequence; constexpr static std::size_t size = 1 + sizeof...(Others); template using index = std::conditional_t>; }; template struct Sequence { using value = TypeVal; constexpr static std::size_t size = 1; template using index = std::conditional_t; }; template struct TypeSeq { using type = T; using next = TypeSeq; constexpr static std::size_t size = 1 + sizeof...(Ts); template using index = std::conditional_t>; }; template struct TypeSeq { using type = T; constexpr static std::size_t size = 1; template using index = std::conditional_t; }; template struct MinVal { constexpr static std::size_t value = Val < MinVal::value ? Val : MinVal::value; }; template struct MinVal { constexpr static std::size_t value = Val; }; template struct SeqPack { constexpr static std::size_t size = MinVal::value; template using getter = typename U::template index; template using index = TypeSeq...>; }; struct Pass {}; template struct First { using type = std::conditional_t< std::is_same_v, typename First::type, T>; }; template struct First { using type = std::conditional_t< std::is_same_v, IfAllPass, T>; }; } namespace obfs { void FreeAction() {} template struct Next { using event = Event; using state = State; constexpr static void(*action)() = Action; }; struct None {}; template struct Stage { using state = State; template using act = std::conditional_t< std::is_same_v, NextInfo, Pass>; template using next = typename First...>::type; }; template struct next_stage { using type = typename Stage_::template next; }; template struct next_stage { using type = None; }; template struct action_invoker { static auto action() { State::action(); return typename State::state{}; } }; template <> struct action_invoker { static auto action() { return None{}; } }; template struct StateMachine { template using filter = std::conditional_t< std::is_same_v, StageT, Pass>; template using find = typename First...>::type; template using next_t = typename next_stage, Event>::type; template static auto run(State state, Event event) { using next_state = next_t, std::decay_t>; return action_invoker::action(); } }; } namespace obfs { using size_t = decltype(sizeof(void*)); constexpr char TIME[] = __TIME__; constexpr int digit(char c) { return c - '0'; } constexpr size_t SEED = digit(TIME[7]) + digit(TIME[6]) * 10 + digit(TIME[4]) * 60 + digit(TIME[3]) * 600 + digit(TIME[1]) * 3600 + digit(TIME[0]) * 36000; template struct Xorshiftplus { using prev = Xorshiftplus; constexpr static size_t update() { constexpr size_t x = prev::state0 ^ (prev::state0 << 23); constexpr size_t y = prev::state1; return x ^ y ^ (x >> 17) ^ (y >> 26); } constexpr static size_t state0 = prev::state1; constexpr static size_t state1 = update(); constexpr static size_t value = state0 + state1; }; template struct Xorshiftplus { constexpr static size_t state0 = Seed; constexpr static size_t state1 = Seed << 1; constexpr static size_t value = state0 + state1; }; template constexpr size_t RAND_VAL = Xorshiftplus::value % Mod; } namespace obfs { using Encoder = char(*)(char); using Decoder = char(*)(char); template class String { public: template constexpr String(char const* str, std::index_sequence): str{ encoder(str[Idx])... } { // Do Nothing } inline char const* decode() const { for (char& chr : str) { chr = decoder(chr); } return str; } private: mutable char str[size]; }; template constexpr auto make_string(char const (&str)[size]) { return String(str, std::make_index_sequence()); } template using encoder_seq = Sequence; template using decoder_seq = Sequence; template using make_table = SeqPack; template using encoder_pair = Sequence; template using make_pair_table = TypeSeq; template constexpr auto make_string(char const(&str)[size]) { using pair = typename Table::template index; constexpr Encoder encoder = pair::template index<0>::value; constexpr Decoder decoder = pair::template index<1>::value; return make_string(str); } } #endif