Developer knowledge network · moderated exchange

UnreliableCode コミュニティ

開発者リサーチ、リバース エンジニアリング、コーディング コミュニティ

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.