Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

hx - compile-time string crypt

Single-header C++ string obfuscator. Your string literals are XOR-encrypted at compile time and only decrypted into a short-lived stack buffer when used. The plaintext never appears in the binary, and neither does a visible encrypted blob — the encrypted data is baked into the code as uint64 immediates, not into .rdata, so strings shows nothing.

Features

  • Encryption happens fully at compile time (constexpr).
  • No plaintext in the binary.
  • No visible encrypted string in .rdata (stored as instruction immediates).
  • Per-build random keys derived from __TIME__ / __DATE__ (no fixed magic constants).
  • Header only, no dependencies.

Requirements

  • C++17 or newer
  • MSVC / Clang / GCC
  • /O2 (or -O2) recommended so the compiler keeps the data as immediates

Usage

Include the header and wrap any string literal in hxx(...):

#include "crypt.h"
#include <iostream>
#include <string>

int main() {
    std::string url = hxx("https://example.com/api");
    std::cout << hxx("hello world") << "\n";
    std::cout << url << "\n";
}
  • hxx("text") returns a decrypted char* (valid until the end of the full expression).
  • hxx_("text") returns the raw encrypted box object if you want to hold it yourself.

Because hxx(...) gives a temporary, copy it into a std::string if you need to keep it:

std::string secret = hxx("keep me");

How it works

  1. hx::enc() XORs each 8-byte chunk of the string with a key stream at compile time.
  2. The encrypted chunks are stored in an automatic uint64 array, so the compiler emits them as mov rax, imm64 inside the function — not as a data string.
  3. dec() XORs the chunks back at runtime through a volatile pointer (which stops the optimizer from precomputing the plaintext).

Before / After

Same string, decompiled in IDA Pro.

Before — a normal string literal sits in the binary in plain sight ("Hello World!\n"):

before

After — through hxx(...): only encrypted uint64 constants and a key built at runtime from __TIME__ / __DATE__ over a 246-byte stream (% 0xF6). No plaintext, no .rdata string:

after 1

after 2

License

MIT

About

Compile-time C++ string encryption. Header-only. Encrypts string literals at build time and stores them as scattered uint64 immediates — no plaintext and no visible blobs in the binary. Per-build random keys, decrypted only into a temporary stack buffer.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages