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.
30 lines
911 B
30 lines
911 B
4 years ago
|
# 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.
|
||
|
|
||
|
``` c++
|
||
|
#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.
|
||
|
|
||
|
``` c++
|
||
|
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.
|