#string-literal #literals #string #hide #proc-macro #obfuscate #obfuscation

macro obfustring

Procedural macro that obfuscates string literals with RNG at compile time

1 unstable release

0.5.0 Jan 30, 2023

#2180 in Procedural macros

Download history 42/week @ 2024-07-22 151/week @ 2024-07-29 81/week @ 2024-08-05 396/week @ 2024-08-12 106/week @ 2024-08-19 122/week @ 2024-08-26 351/week @ 2024-09-02 273/week @ 2024-09-09 46/week @ 2024-09-16 57/week @ 2024-09-23 106/week @ 2024-09-30 114/week @ 2024-10-07 255/week @ 2024-10-14 177/week @ 2024-10-21 357/week @ 2024-10-28 147/week @ 2024-11-04

937 downloads per month

MIT license

9KB

Obfustring

github crates.io docs.rs license

This crate provides a obfuscation macro for string literals. This makes it easy to protect them from common reverse engineering attacks like string reference lookup in something like a debugger or hex editor.

A string literal "" is given as the input and converted into a [u8; str_size*2] array literal that is then stored inside the binary. Every character is offset by a random amount. This offset is stored alongside the original data so it can be reconstructed.

Installation

[dependencies]
obfustring = "0.5.0"



Syntax & Usage

The crate provides a obfustring!() macro that takes in a single string literal.

use obfustring::obfustring;

let obfuscated_string = obfustring!("Hello obfustring!"); // <-- Won't show up in binaries or hex editors
let generic_string = String::from("Hello regular string!"); // <-- Will show up in binaries or hex editors

println!("obfuscated_string: {}", obfuscated_string);
println!("generic_string: {}", generic_string);

Disclaimer

Note that you should never have any encryption/api keys or sensetive data hardcoded into your program. Though this macro would make it harder, it wouldn't absolutely hide it from someone looking hard enough. Stick to environment variables.



License

This project is licensed under the MIT license.

Dependencies

~2MB
~41K SLoC