Compile-time `memfrob()` literal for C++20.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Avril 4199c0b3de
added \*frob
4 years ago
test added \*frob 4 years ago
.gitignore initial commit 4 years ago
Makefile added -Werror to test 4 years ago
README.md added README 4 years ago
cfrob.hpp added \*frob 4 years ago

README.md

Compile-time memfrob()

glibc has a function in string.h called memfrob() which applies ROT13 to an arbitrary byte buffer. This small C++20 header allows you to do this at compile time to trivially obscure string literals without the literal itself appearing in the binary anywhere at all.

Usage

The literals can be created and stored as a sized char array, or as a C string pointer.

#include "cfrob.hpp"

const auto easter_egg = "Something cool"_frob;
const char* c_like_easter_egg = "Something cool"_frob;

To reverse just apply ROT13 on to the string again.

auto string2 = strdup(easter_egg);
memfrob(string2, strlen(easter_egg));
// `string2` now contains the string "Something cool"
free(string2);

Test

Run make test to build and run the test that ensures the original string literal does not appear anywhere in the outputted binary.

License

Public domain.