This repository provides a compile-time string encryption mechanism based on xor bitwise operations using mathematical operations at compile-time in order to make the strings challenging to decompile.
Users can easily encrypt their strings using the crystr
macro provided in the header.
The repository includes an example demonstrating the usage of crystr
to decrypt strings.
To use all its potential it needs RTTI OFF (Run-Time Type Information under C/C++ -> Language (/GR-))
It's recommended, but not necessarily, to disable the optimization under C/C++ -> Optimization -> "Optimization" and "Whole Program Optimization"
- The xor key is generated by mathematical operations based on a uniqueid that is different every time the program is compiled and for each encrypted string.
- The uniqueid is an hash based on the date, time and a counter which increases every time a string encrypts:
const_hash(__DATE__ __TIME__) + __COUNTER__
. - Every character of the string is encrypted with a different xor key based on the index of the character inside the string.
- It is possible to choose between virtual and inline functions to decrypt the string.
- If using the virtual implementation it works well with
crycall
(see the repo). - All the variables used to retrieve the xor key are thread_local, meaning they're stored as
(NtCurrentTeb()->ThreadLocalStoragePointer + TlsIndex)->x_var
, making it more challenging to decompile and not ready-pastable from decompiler tools such as ida or ghidra. - The string is never copied but instead it's being written on, in order to prevent unwanted decrypted copies of the string in memory.
- The decrypted string can be re-encrypted at any time using the built-in
encrypt
function. - The decrypted/encrypted string can be removed from memory at any time using the built-in
clear
function. - The string will show as never referenced in most common decompiler tools such as ida or ghidra see (How it shows).
- Compatible with both char[] and wchar_t[].
- Supports C++20 and higher versions.
include/
: Contains thecrystr.hpp
header file providing the compile-time string encryption mechanism.src/
: Holds the examplemain.cpp
file showcasing the usage of thecrystr
encryption.LICENSE
: Licensing information for the provided code.README.md
: Documentation explaining how to use thecrystr
encryption and example usage.
The repository includes an example demonstrating the usage of the crystr
macro:
//#include "crycall.hpp" // see https://github.com/Android1337/crycall for an all-potential virtual implementation
#include "crystr.hpp"
int main() {
auto encrypted_str = crystr("Hello, this is an encrypted string!");
printf("Decrypted String: %s", encrypted_str.decrypt());
encrypted_str.clear();
return 0;
}