obfany 0.1.0

Compiletime string and number constant obfuscation for Rust
Documentation
  • Coverage
  • 67.86%
    19 out of 28 items documented11 out of 18 items with examples
  • Size
  • Source code size: 58.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 369.33 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jeanzuck/obfany
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jeanzuck

String and Number Obfuscation

Forked from obfstr by CasualX — adds obfnum! macro for numeric constant obfuscation.

MIT License crates.io docs.rs Build status

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 obfany::obfstr as s;
assert_eq!(s!("Hello 🌍"), "Hello 🌍");

The wide! macro provides compiletime utf16 string constants:

let expected = &['W' as u16, 'i' as u16, 'd' as u16, 'e' as u16, 0];
assert_eq!(obfany::wide!("Wide\0"), expected);

The random! macro provides compiletime random values:

const RND: i32 = obfany::random!(u8) as i32;
assert!(RND >= 0 && RND <= 255);

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 = obfany::obfnum!(0x1234_u32);
assert_eq!(secret, 0x1234_u32);

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.