andrivet/ADVobfuscator

MetaString<1, K, Indexes<I...>> doesn't obfuscate string at compile-time but runtime

macvip opened this issue ยท 10 comments

Using MetaString<1, K, Indexes<I...>>, compile with VS 2017 ver 15.7.1, disassemble and you'll find constexpr not working as supposed. As a result, the strings are obfuscated at runtime.
For some unknown reason, the compiler regards the position I as a variant not a const value though it can be and indeed is produced at compile-time.

After several tries, an ugly template function fools the compiler to obfuscate string at compile-time.

template<char K, int... I>
  struct MetaString<1, K, Indexes<I...>>
  {
    // Constructor. Evaluated at compile time. Instantiate template function **encrypt**.
    constexpr ALWAYS_INLINE MetaString(const char* str)
    : key_(K), buffer_ {encrypt<K+I>(str[I])...} { }
    /* untouched  inline const char* decrypt() */
    private:
        // ......
        // decrypt and encrypt2 are evaluated at runtime.
        constexpr char  encrypt2(char c, size_t position) const { return c ^ key(position); }
	constexpr char decrypt(char c, size_t position) const { return encrypt2(c, position); }
        // **encrypt** will be instantiated at compile time in the constructor of this MetaString.
	template<char _k>
	constexpr char encrypt(char c) const { return c ^ _k; }
        /* key_ and buffer_ */
};

My code definitely needs improvements for the latest versions of compilers

I had the same symptoms, so I thought this library actually does not support compile time obfuscation.
Thanks for letting me know that this is a compiler dependent issue.

@MeroZemory It is dependent of the compiler you are using, its version and the compilation flags.
(It was written more than 3 years...)

@andrivet Thank you for writing such a library. I was exploring instruction-level obfuscation techniques so this isn't related to what I was looking for, but it was great to get the first idea of running FSM based on predicates :)

@MeroZemory It is dependent of the compiler you are using, its version and the compilation flags.
(It was written more than 3 years...)

Can you addapt it for VS 2019?

I will update this code once we have good support of C++20 in the major compilers (VS, Clang and GCC). This is currently not the case. More specifically, what I am waiting for is "string literal operator template" support.

I will update this code once we have good support of C++20 in the major compilers (VS, Clang and GCC). This is currently not the case. More specifically, what I am waiting for is "string literal operator template" support.

Thx for faster than light answer. So, VS 20 would got major updates?

VS 20 does not exist so I can't answer.

Visual Studio 2022 came out today, which claims to have proper C++20 support. Is a MetaString rewrite still planned? ๐Ÿ‘ผ

Yes (when ? when I can find some time)