Macro obfstr::obfstr[][src]

macro_rules! obfstr {
    ($buf:ident <- $s:expr) => { ... };
    ($buf:ident <- L$s:expr) => { ... };
    ($s:expr) => { ... };
    (L$s:expr) => { ... };
    ($(let $name:ident = $s:expr;)*) => { ... };
    ($(let $name:ident = L$s:expr;)*) => { ... };
}

Compiletime string constant obfuscation.

The purpose of the obfuscation is to make it difficult to discover the original strings with automated analysis. String obfuscation is not intended to hinder a dedicated reverse engineer from discovering the original string. This should not be used to hide secrets in client binaries and the author disclaims any responsibility for any damages resulting from ignoring this warning.

The obfstr! macro returns the deobfuscated string as a temporary &str value and must be consumed in the same statement it was used:

use obfstr::obfstr;

const HELLO_WORLD: &str = "Hello 🌍";
assert_eq!(obfstr!(HELLO_WORLD), HELLO_WORLD);

To reuse the deobfuscated string in the current scope it must be assigned to a local variable:

use obfstr::obfstr;

obfstr! {
	let s = "Hello 🌍";
}
assert_eq!(s, "Hello 🌍");

To return an obfuscated string from a function pass a buffer. Panics if the buffer is too small:

use obfstr::obfstr;

fn helper(buf: &mut [u8]) -> &str {
	obfstr!(buf <- "hello")
}

let mut buf = [0u8; 16];
assert_eq!(helper(&mut buf), "hello");

The string constants can be prefixed with L to get an UTF-16 equivalent obfuscated string as &[u16; LEN].