8000 GitHub - gmh5225/crystr: Compile-Time String Encryption for C++20
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ crystr Public
forked from android1337/crystr

Compile-Time String Encryption for C++20

License

Notifications You must be signed in to change notification settings

gmh5225/crystr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crystr | Compile-Time String Encryption for C++20

Description

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"

Key Aspects

  • 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.

How it shows

Look here

Repository Structure

  • include/: Contains the crystr.hpp header file providing the compile-time string encryption mechanism.
  • src/: Holds the example main.cpp file showcasing the usage of the crystr encryption.
  • LICENSE: Licensing information for the provided code.
  • README.md: Documentation explaining how to use the crystr encryption and example usage.

Usage Example

The repository includes an example demonstrating the usage of the crystr macro:

main.cpp

//#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;
}

About

Compile-Time String Encryption for C++20

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%
0