From cc078810f1b359f548969e6f464c04e2015df4aa Mon Sep 17 00:00:00 2001 From: revsic Date: Mon, 18 Feb 2019 05:24:30 +0900 Subject: [PATCH] obfs, string: Modify file name --- obfuscator/impl/string.hpp | 65 +++++++++++++++++++++++++++++++++ obfuscator/impl/string_obfs.hpp | 38 ------------------- 2 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 obfuscator/impl/string.hpp delete mode 100644 obfuscator/impl/string_obfs.hpp diff --git a/obfuscator/impl/string.hpp b/obfuscator/impl/string.hpp new file mode 100644 index 0000000..b50e74b --- /dev/null +++ b/obfuscator/impl/string.hpp @@ -0,0 +1,65 @@ +#ifndef STRING_OBFS +#define STRING_OBFS + +#include "random.hpp" +#include "sequence.hpp" + +#include + +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 + } + + constexpr std::size_t len() const { + return size; + } + + 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 + constexpr auto make_string(char const (&str)[size]) { + using pair = Table::get; + // constexpr Encoder encoder = pair::get<0>::value; + // constexpr Decoder decoder = pair::get<1>::value; + + constexpr Encoder encoder = pair::type::value; + constexpr Decoder decoder = pair::next::type::value; + + return make_string(str); + } +} + +#endif \ No newline at end of file diff --git a/obfuscator/impl/string_obfs.hpp b/obfuscator/impl/string_obfs.hpp deleted file mode 100644 index 0269252..0000000 --- a/obfuscator/impl/string_obfs.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef STRING_OBFS -#define STRING_OBFS - -#include - -namespace obfs { - template - class String { - public: - template - constexpr String(char const* str, - std::index_sequence): - str{ encoder(str[Idx])... } { - // Do Nothing - } - - constexpr std::size_t len() const { - return size; - } - - 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()); - } -} - -#endif \ No newline at end of file