🦀 rustfuscator
Rustfuscator is an obfuscation-first CLI and library for Rust codebases. It rewrites source code and exposes macros for string literals, numeric literals, control-flow noise, logging literals, identifier renaming, and derive-based encrypted fields.
Obfuscation is pragmatic: it does not make software invulnerable, but it can raise the cost of casual static analysis and reverse engineering when it is scoped and tested carefully.
Features
- CLI for files, folders, or Cargo projects.
.obfuscate.tomlconfiguration with include/exclude and per-file control-flow selection.- Compile-time string literal obfuscation:
obfuscate_string!("...")returnsObfStrobfuscate_str!("...")returns&'static str
- Lightweight integer literal obfuscation with
obfuscate_num!(...). - Control-flow injection with
obfuscate_flow!. - Optional dummy branch injection with
obfuscate_dummy_branch!and CLIdummy_branches. - Logging macro literal rewriting for
println!,eprintln!,log::*, andtracing::*. - Identifier renaming strategies:
suffix,hash, andconfuse. #[derive(Obfuscate)]for structs withString,bool, and Rust integer primitive fields.- Optional
secure_zeroizefeature for supported clear values and temporary clear buffers. - Optional
verify_literalsfeature for debug-only literal round-trip assertions.
How It Works
The CLI does not obfuscate compiled binaries directly. It parses Rust source, rewrites selected constructs, and emits Rust code that uses the library macros.
The macro layer then performs the runtime behavior needed by the transformed source, such as decrypting string literals on demand or injecting flow noise. After running the CLI, build the transformed project with Cargo as usual.
Installation
Or from a local checkout:
CLI Usage
Obfuscate a single Rust file:
Obfuscate a source folder:
Obfuscate a Cargo project:
Generate a default config:
Useful review flags:
Configuration
Example .obfuscate.toml:
[]
= true
= 4
= ["DEBUG", "LOG"]
= true
= ["**/*.rs"]
= false
= true
= ["src/main.rs"]
= true
[]
= false
= "suffix" # suffix | hash | confuse
= ["main"]
[]
= ["**/*.rs"]
= ["target/**", "tests/**"]
[]
= [
"println",
"eprintln",
"log::info",
"log::warn",
"log::error",
"tracing::info",
"tracing::warn",
]
= ["DEBUG", "TRACE", "startup ok"]
Library Usage
Add the library:
[]
= "0.3.1"
Use macros directly:
use ;
Derive Usage
use Obfuscate;
Supported derive field types are String, bool, and Rust integer primitives. Floats, containers, and custom types are intentionally out of scope.
Examples
Run the advanced macro example:
Other examples under examples/ cover basic string obfuscation, control-flow injection, derive usage, and CLI transformation targets.
Benchmarks
Benchmarks use Criterion and compare baseline code against macro-assisted code:
The benchmark suite currently covers:
- normal arithmetic vs
obfuscate_flow! - plain string literal access vs
obfuscate_string! - plain integer literal access vs
obfuscate_num!
Benchmark results are workload-specific; use them to estimate overhead for your own threat model and performance budget.
Feature Flags
[]
= { = "0.3.1", = ["secure_zeroize", "verify_literals"] }
secure_zeroize: zeroizes supported clear values and temporary clear buffers.verify_literals: enables debug-only round-trip assertions inside string literal macros.
Project Layout
rustfuscator/
├── src/ # Public facade crate
├── rust_code_obfuscator_core/ # Core macros and crypto helpers
├── obfuscator_derive/ # #[derive(Obfuscate)]
├── obfuscator_cli/ # CLI source rewriter
├── examples/ # Runnable examples
├── benches/ # Criterion benchmarks
└── tests/ # Integration tests
Disclaimer
Rustfuscator is an obfuscation tool, not a guarantee of secrecy. Combine it with normal release hardening where appropriate:
RUSTFLAGS="-C strip=debuginfo -C opt-level=z -C panic=abort"
Author Note
The first commits signed by user <user@local> are authored by Gianfranco Iaculo.
License
MIT License © 2025 Gianfranco Iaculo