From e9596fc19748ada1d3be1709228c8ce796ac217c Mon Sep 17 00:00:00 2001 From: revsic Date: Sun, 7 Apr 2019 00:29:33 +0900 Subject: [PATCH] obfs, fsm: Move pass to seq --- obfuscator.hpp | 148 +++++++++++++++++------------------ obfuscator/obfs/fsm.hpp | 22 +----- obfuscator/obfs/sequence.hpp | 18 +++++ 3 files changed, 95 insertions(+), 93 deletions(-) diff --git a/obfuscator.hpp b/obfuscator.hpp index 20e6fd1..dd0d90b 100644 --- a/obfuscator.hpp +++ b/obfuscator.hpp @@ -4,15 +4,84 @@ #include #include +#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 + 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; + + template + using index = std::conditional_t>; + }; + + template + struct TypeSeq { + using type = T; + + 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 = sizeof...(T); + constexpr static std::size_t elem_size = MinVal::value; + + template + using getter = typename U::template index; + + template + using index = TypeSeq...>; + }; + struct Pass {}; template @@ -30,8 +99,11 @@ namespace obfs { IfAllPass, T>; }; +} - constexpr void FreeAction() {} + +namespace obfs { + void FreeAction() {} template struct Next { @@ -142,78 +214,6 @@ namespace obfs { } -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; - - template - using index = std::conditional_t>; - }; - - template - struct TypeSeq { - using type = T; - - 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 = sizeof...(T); - constexpr static std::size_t elem_size = MinVal::value; - - template - using getter = typename U::template index; - - template - using index = TypeSeq...>; - }; -} - - namespace obfs { using Encoder = char(*)(char); using Decoder = char(*)(char); diff --git a/obfuscator/obfs/fsm.hpp b/obfuscator/obfs/fsm.hpp index f39c4a1..45812c8 100644 --- a/obfuscator/obfs/fsm.hpp +++ b/obfuscator/obfs/fsm.hpp @@ -1,28 +1,12 @@ #ifndef OBFS_FINITE_STATE_MACHINE #define OBFS_FINITE_STATE_MACHINE +#include "sequence.hpp" + #include namespace obfs { - 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>; - }; - - constexpr void FreeAction() {} + void FreeAction() {} template struct Next { diff --git a/obfuscator/obfs/sequence.hpp b/obfuscator/obfs/sequence.hpp index f6bf218..f2c4354 100644 --- a/obfuscator/obfs/sequence.hpp +++ b/obfuscator/obfs/sequence.hpp @@ -72,6 +72,24 @@ namespace obfs { 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>; + }; } #endif \ No newline at end of file