ADVobfuscator icon indicating copy to clipboard operation
ADVobfuscator copied to clipboard

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

Open macvip opened this issue 6 years ago • 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_ */
};

macvip avatar May 20 '18 14:05 macvip

My code definitely needs improvements for the latest versions of compilers

andrivet avatar May 21 '18 20:05 andrivet

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 avatar Sep 11 '20 05:09 MeroZemory

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

andrivet avatar Sep 11 '20 09:09 andrivet

@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 avatar Sep 11 '20 11:09 MeroZemory

@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?

AlexanderQueen avatar Oct 29 '20 12:10 AlexanderQueen

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.

andrivet avatar Oct 29 '20 13:10 andrivet

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?

AlexanderQueen avatar Oct 29 '20 13:10 AlexanderQueen

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

andrivet avatar Oct 29 '20 13:10 andrivet

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

codecat avatar Nov 08 '21 18:11 codecat

Yes (when ? when I can find some time)

andrivet avatar Nov 09 '21 10:11 andrivet