Developer knowledge network · moderated exchange

UnreliableCode 커뮤니티

개발자 연구, 리버스 엔지니어링 및 코딩 커뮤니티

Knowledge index살다
4Categories
919Threads
2.8K게시물
Release

C++20 consteval Compile-Time String Encryption Macro with dynamic XOR keys

vtable_slayer
Senior Reverser
MEMBER
대표: 215
가입 날짜: Mar 2018
게시물: 86
감사해요: 61
3주 전 · Jul 27, 2026 2:27 PM
#1

Clean C++20 string obfuscation macro that encrypts strings at compile time with zero runtime decryption overhead:

CPP
template <size_t N, uint32_t Seed>
class ObfuscatedString {
    char m_data[N];
public:
    consteval ObfuscatedString(const char(&str)[N]) {
        for (size_t i = 0; i < N; i++) {
            m_data[i] = str[i] ^ (char)((Seed + i * 7) & 0xFF);
        }
    }
    std::string Decrypt() const {
        std::string res(N - 1, '\0');
        for (size_t i = 0; i < N - 1; i++) {
            res[i] = m_data[i] ^ (char)((Seed + i * 7) & 0xFF);
        }
        return res;
    }
};

#define CRYPT_STR(s) ([]() { consteval ObfuscatedString<sizeof(s), __LINE__ * 0x5F37> x(s); return x; }().Decrypt())
ptr_arithmetic
C++ Wizard
MEMBER
대표: 162
가입 날짜: May 2018
게시물: 73
감사해요: 42
3주 전 · Jul 27, 2026 5:19 PM
#2

Using __LINE__ as entropy seed generates unique XOR keys for every single string in the codebase automatically.

ghidra_fanatic
RE Specialist
MEMBER
대표: 101
가입 날짜: Mar 2019
게시물: 16
감사해요: 14
3주 전 · Jul 28, 2026 3:49 AM
#3

Checked binary in IDA Pro: .rdata strings list is 100% scrambled bytes.