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.