mirror of
https://github.com/revsic/cpp-obfuscator
synced 2026-06-08 17:08:30 +00:00
obfs, fsm: Move pass to seq
This commit is contained in:
+74
-74
@@ -4,15 +4,84 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#define COMPILE_TIME_SEQUENCE
|
||||
#define OBFS_FINITE_STATE_MACHINE
|
||||
#define COMPILE_TIME_RANDOM
|
||||
#define MAKE_RAND_VAL(MOD) RAND_VAL<__LINE__, MOD>
|
||||
#define COMPILE_TIME_SEQUENCE
|
||||
#define OBFS_STRING
|
||||
#define MAKE_STRING(Var, String, ...) constexpr auto Var = obfs::make_string<__VA_ARGS__>(String);
|
||||
|
||||
|
||||
namespace obfs {
|
||||
template <typename T, T Val>
|
||||
struct TypeVal {
|
||||
using value_type = T;
|
||||
constexpr static T value = Val;
|
||||
};
|
||||
|
||||
struct Nothing {};
|
||||
|
||||
template <typename T, T Val, T... Others>
|
||||
struct Sequence {
|
||||
using value = TypeVal<T, Val>;
|
||||
using next = Sequence<T, Others...>;
|
||||
|
||||
constexpr static std::size_t size = 1 + sizeof...(Others);
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, value, typename next::template index<Idx - 1>>;
|
||||
};
|
||||
|
||||
template <typename T, T Val>
|
||||
struct Sequence<T, Val> {
|
||||
using value = TypeVal<T, Val>;
|
||||
|
||||
constexpr static std::size_t size = 1;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, value, Nothing>;
|
||||
};
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
struct TypeSeq {
|
||||
using type = T;
|
||||
using next = TypeSeq<Ts...>;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, type, typename next::template index<Idx - 1>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypeSeq<T> {
|
||||
using type = T;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, type, Nothing>;
|
||||
};
|
||||
|
||||
template <std::size_t Val, std::size_t... Others>
|
||||
struct MinVal {
|
||||
constexpr static std::size_t value =
|
||||
Val < MinVal<Others...>::value ? Val : MinVal<Others...>::value;
|
||||
};
|
||||
|
||||
template <std::size_t Val>
|
||||
struct MinVal<Val> {
|
||||
constexpr static std::size_t value = Val;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
struct SeqPack {
|
||||
constexpr static std::size_t size = sizeof...(T);
|
||||
constexpr static std::size_t elem_size = MinVal<T::size...>::value;
|
||||
|
||||
template <std::size_t Idx, typename U>
|
||||
using getter = typename U::template index<Idx>;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = TypeSeq<getter<Idx, T>...>;
|
||||
};
|
||||
|
||||
struct Pass {};
|
||||
|
||||
template <typename IfAllPass, typename T, typename... Ts>
|
||||
@@ -30,8 +99,11 @@ namespace obfs {
|
||||
IfAllPass,
|
||||
T>;
|
||||
};
|
||||
}
|
||||
|
||||
constexpr void FreeAction() {}
|
||||
|
||||
namespace obfs {
|
||||
void FreeAction() {}
|
||||
|
||||
template <typename Event, typename State, void(*Action)() = FreeAction>
|
||||
struct Next {
|
||||
@@ -142,78 +214,6 @@ namespace obfs {
|
||||
}
|
||||
|
||||
|
||||
namespace obfs {
|
||||
template <typename T, T Val>
|
||||
struct TypeVal {
|
||||
using value_type = T;
|
||||
constexpr static T value = Val;
|
||||
};
|
||||
|
||||
struct Nothing {};
|
||||
|
||||
template <typename T, T Val, T... Others>
|
||||
struct Sequence {
|
||||
using value = TypeVal<T, Val>;
|
||||
using next = Sequence<T, Others...>;
|
||||
|
||||
constexpr static std::size_t size = 1 + sizeof...(Others);
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, value, typename next::template index<Idx - 1>>;
|
||||
};
|
||||
|
||||
template <typename T, T Val>
|
||||
struct Sequence<T, Val> {
|
||||
using value = TypeVal<T, Val>;
|
||||
|
||||
constexpr static std::size_t size = 1;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, value, Nothing>;
|
||||
};
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
struct TypeSeq {
|
||||
using type = T;
|
||||
using next = TypeSeq<Ts...>;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, type, typename next::template index<Idx - 1>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypeSeq<T> {
|
||||
using type = T;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = std::conditional_t<Idx == 0, type, Nothing>;
|
||||
};
|
||||
|
||||
template <std::size_t Val, std::size_t... Others>
|
||||
struct MinVal {
|
||||
constexpr static std::size_t value =
|
||||
Val < MinVal<Others...>::value ? Val : MinVal<Others...>::value;
|
||||
};
|
||||
|
||||
template <std::size_t Val>
|
||||
struct MinVal<Val> {
|
||||
constexpr static std::size_t value = Val;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
struct SeqPack {
|
||||
constexpr static std::size_t size = sizeof...(T);
|
||||
constexpr static std::size_t elem_size = MinVal<T::size...>::value;
|
||||
|
||||
template <std::size_t Idx, typename U>
|
||||
using getter = typename U::template index<Idx>;
|
||||
|
||||
template <std::size_t Idx>
|
||||
using index = TypeSeq<getter<Idx, T>...>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace obfs {
|
||||
using Encoder = char(*)(char);
|
||||
using Decoder = char(*)(char);
|
||||
|
||||
+3
-19
@@ -1,28 +1,12 @@
|
||||
#ifndef OBFS_FINITE_STATE_MACHINE
|
||||
#define OBFS_FINITE_STATE_MACHINE
|
||||
|
||||
#include "sequence.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace obfs {
|
||||
struct Pass {};
|
||||
|
||||
template <typename IfAllPass, typename T, typename... Ts>
|
||||
struct First {
|
||||
using type = std::conditional_t<
|
||||
std::is_same_v<T, Pass>,
|
||||
typename First<IfAllPass, Ts...>::type,
|
||||
T>;
|
||||
};
|
||||
|
||||
template <typename IfAllPass, typename T>
|
||||
struct First<IfAllPass, T> {
|
||||
using type = std::conditional_t<
|
||||
std::is_same_v<T, Pass>,
|
||||
IfAllPass,
|
||||
T>;
|
||||
};
|
||||
|
||||
constexpr void FreeAction() {}
|
||||
void FreeAction() {}
|
||||
|
||||
template <typename Event, typename State, void(*Action)() = FreeAction>
|
||||
struct Next {
|
||||
|
||||
@@ -72,6 +72,24 @@ namespace obfs {
|
||||
template <std::size_t Idx>
|
||||
using index = TypeSeq<getter<Idx, T>...>;
|
||||
};
|
||||
|
||||
struct Pass {};
|
||||
|
||||
template <typename IfAllPass, typename T, typename... Ts>
|
||||
struct First {
|
||||
using type = std::conditional_t<
|
||||
std::is_same_v<T, Pass>,
|
||||
typename First<IfAllPass, Ts...>::type,
|
||||
T>;
|
||||
};
|
||||
|
||||
template <typename IfAllPass, typename T>
|
||||
struct First<IfAllPass, T> {
|
||||
using type = std::conditional_t<
|
||||
std::is_same_v<T, Pass>,
|
||||
IfAllPass,
|
||||
T>;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user