From 8991de23fd1effccdd6df32839a248b29066e856 Mon Sep 17 00:00:00 2001 From: revsic Date: Mon, 25 Feb 2019 14:55:32 +0900 Subject: [PATCH] obfs, fsm: Add state machine executor --- obfuscator.hpp | 35 +++++++++++++++++++++++++++-------- obfuscator/obfs/fsm.hpp | 34 +++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/obfuscator.hpp b/obfuscator.hpp index 528bfd7..b0fd998 100644 --- a/obfuscator.hpp +++ b/obfuscator.hpp @@ -128,6 +128,30 @@ namespace obfs { using next = typename First, act...>::type; }; + template + struct MachineExecutor; + + template + struct MachineExecutor { + using next = typename Machine::template next; + using next_s = typename Machine::template next_s; + + constexpr static void run() { + if (next::action()) { + return; + } + MachineExecutor::run(); + } + }; + + template + struct MachineExecutor { + using next = typename Machine::template next; + constexpr static void run() { + next::action(); + } + }; + template struct StateMachine { template @@ -142,15 +166,10 @@ namespace obfs { template using next_s = StateMachine::state, Specs...>; - template + template constexpr static void run() { - if (next::action()) { - return; - } - - if constexpr (sizeof...(Others) > 0) { - next_s::template run(); - } + using self = StateMachine; + MachineExecutor::run(); } }; } diff --git a/obfuscator/obfs/fsm.hpp b/obfuscator/obfs/fsm.hpp index beba1cb..d7be67b 100644 --- a/obfuscator/obfs/fsm.hpp +++ b/obfuscator/obfs/fsm.hpp @@ -47,6 +47,30 @@ namespace obfs { using next = typename First, act...>::type; }; + template + struct MachineExecutor; + + template + struct MachineExecutor { + using next = typename Machine::template next; + using next_s = typename Machine::template next_s; + + constexpr static void run() { + if (next::action()) { + return; + } + MachineExecutor::run(); + } + }; + + template + struct MachineExecutor { + using next = typename Machine::template next; + constexpr static void run() { + next::action(); + } + }; + template struct StateMachine { template @@ -61,14 +85,10 @@ namespace obfs { template using next_s = StateMachine::state, Specs...>; - template + template constexpr static void run() { - if (next::action()) { - return; - } - if constexpr (sizeof...(Others) > 0) { - next_s::template run(); - } + using self = StateMachine; + MachineExecutor::run(); } }; }