String and Number Obfuscation
Forked from obfstr by CasualX — adds
obfnum!macro for numeric constant obfuscation.
Compiletime string and number constant obfuscation for Rust.
The string constant itself is embedded in obfuscated form and deobfuscated locally. This reference to a temporary value must be used in the same statement it was generated. See the documentation for more advanced use cases.
Examples
The obfstr! macro returns the deobfuscated string as a temporary value:
use obfstr as s;
assert_eq!;
The wide! macro provides compiletime utf16 string constants:
let expected = &;
assert_eq!;
The random! macro provides compiletime random values:
const RND: i32 = random! as i32;
assert!;
Compiletime random values are based on file!(), line!(), column!() and a fixed seed to ensure reproducibility.
This fixed seed is stored as text in the environment variable OBFANY_SEED and can be changed as desired.
The obfnum! macro obfuscates numeric constants:
let secret: u32 = obfnum!;
assert_eq!;
Always use a typed literal suffix (e.g. 0x1234_u32, -9999_i64, 3.14_f32) to ensure correctness.
Supports all primitive numeric types: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize, f32, f64.
The value is stored XOR-encrypted in the binary and decrypted at runtime.
Credits
This project is a fork of obfstr by CasualX, licensed under MIT.
Changes from upstream:
- Renamed crate to
obfany - Added
obfnum!macro for compiletime numeric constant obfuscation
License
Licensed under MIT License, see license.txt.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.