Menu

Rust Obfuscator

Compile-safe Rust source transformation: renames local bindings with verified reference updates, and encodes strings only in type-safe String contexts. Plus real Cargo.toml, linker, and build-script configuration that produces genuinely obfuscated release binaries.

Rust Obfuscation Studio Compile-Safe
Compile-safe by design

This tool performs only transformations that cannot break compilation on valid Rust input. Identifier renaming targets local bindings, parameters, and loop variables. String encoding targets only let-bound String values (via type annotation, .to_string(), or String::from). It never touches format!, println!, const, static, &str parameters, struct fields, macro arguments, or match patterns.

Ready
Rust Source 0 lines • 0 chars
Transformed Source 0 lines • 0 chars
Transform Options (all compile-safe)
The browser cannot execute rustc. The transform performs a structural consistency check — it confirms every renamed identifier's references have been updated. Only the Local Verification tab can confirm compilation. Always run it before shipping.
Cargo.toml
[profile.release]
# Aggressive release optimizations — real binary obfuscation for Rust
opt-level = "z"
lto = "fat"
codegen-units = 1
panic = "abort"
strip = "symbols"
incremental = false
debug = false
debug-assertions = false
overflow-checks = false
rpath = false
Merge this [profile.release] section into your existing Cargo.toml. It does not add dependencies or change source. After adding it, run cargo build --release — the resulting binary will have no symbols, no unwinding tables, and no debug info.
.cargo/config.toml
# Place this file at the root of your project as .cargo/config.toml

[target.'cfg(all(target_os = "linux"))']
rustflags = [
    "-C", "link-arg=-s",
    "-C", "link-arg=-Wl,--strip-all",
    "-C", "link-arg=-Wl,--build-id=none",
]

[target.'cfg(all(target_os = "macos"))']
rustflags = [
    "-C", "link-arg=-Wl,-x",
    "-C", "link-arg=-Wl,-S",
]

[target.'cfg(all(target_os = "windows", target_env = "msvc"))']
rustflags = [
    "-C", "link-arg=/DEBUG:NONE",
    "-C", "link-arg=/OPT:REF",
    "-C", "link-arg=/OPT:ICF",
]
build.rs
// build.rs — emit per-target linker arguments for stripping.
// Add to project root and set `build = "build.rs"` in Cargo.toml [package].

use std::env;

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
    let profile = env::var("PROFILE").unwrap_or_default();

    if profile == "release" {
        match target_os.as_str() {
            "linux" | "android" => {
                println!("cargo:rustc-link-arg=-s");
                println!("cargo:rustc-link-arg=-Wl,--strip-all");
                println!("cargo:rustc-link-arg=-Wl,--build-id=none");
            }
            "macos" | "ios" => {
                println!("cargo:rustc-link-arg=-Wl,-x");
                println!("cargo:rustc-link-arg=-Wl,-S");
            }
            "windows" => {
                println!("cargo:rustc-link-arg=/DEBUG:NONE");
                println!("cargo:rustc-link-arg=/OPT:REF");
                println!("cargo:rustc-link-arg=/OPT:ICF");
            }
            _ => {}
        }
    }
}
strip-binary.sh — optional post-build strip
#!/usr/bin/env bash
# strip-binary.sh — manual post-build stripping for extra symbol removal.
# Run AFTER `cargo build --release`.

set -euo pipefail

BIN="${1:-target/release/myapp}"

if [ ! -f "$BIN" ]; then
  echo "Binary not found: $BIN" >&2
  exit 1
fi

echo "Original size: $(wc -c < "$BIN") bytes"

if command -v strip >/dev/null 2>&1; then
  strip --strip-all --remove-section=.comment --remove-section=.note "$BIN" || true
fi

if command -v llvm-strip >/dev/null 2>&1; then
  llvm-strip --strip-all "$BIN" || true
fi

if command -v objcopy >/dev/null 2>&1; then
  objcopy --remove-section=.comment --remove-section=.note.gnu.build-id "$BIN" || true
fi

echo "Final size: $(wc -c < "$BIN") bytes"
echo "Stripped: $BIN"
verify-obfuscation.sh — run this locally
#!/usr/bin/env bash
# verify-obfuscation.sh
#
# Confirms two things:
#   1. The transformed Rust source compiles successfully.
#   2. The compiled program produces identical output to the original.
#
# Place both project copies side by side:
#   ./original-project/       (unmodified source)
#   ./obfuscated-project/     (source with the obfuscated file applied)
#
# Then run: bash verify-obfuscation.sh ./original-project ./obfuscated-project

set -euo pipefail

ORIG_DIR="${1:-./original-project}"
OBF_DIR="${2:-./obfuscated-project}"
BIN_NAME="${3:-myapp}"

if [ ! -d "$ORIG_DIR" ] || [ ! -d "$OBF_DIR" ]; then
  echo "Usage: $0   [binary-name]" >&2
  exit 1
fi

echo "=== Building original ==="
(cd "$ORIG_DIR" && cargo build --release --quiet)
echo "=== Building obfuscated ==="
(cd "$OBF_DIR" && cargo build --release --quiet)

ORIG_BIN="$ORIG_DIR/target/release/$BIN_NAME"
OBF_BIN="$OBF_DIR/target/release/$BIN_NAME"

if [ ! -x "$ORIG_BIN" ]; then echo "Original binary not found: $ORIG_BIN" >&2; exit 1; fi
if [ ! -x "$OBF_BIN" ]; then echo "Obfuscated binary not found: $OBF_BIN" >&2; exit 1; fi

echo "=== Running both programs ==="
"$ORIG_BIN" > /tmp/orig.out 2>&1 || true
"$OBF_BIN"  > /tmp/obf.out  2>&1 || true

if diff -u /tmp/orig.out /tmp/obf.out; then
  echo ""
  echo "PASS: outputs are identical."
  echo ""
  echo "Binary sizes:"
  echo "  original:   $(wc -c < "$ORIG_BIN") bytes"
  echo "  obfuscated: $(wc -c < "$OBF_BIN") bytes"
  exit 0
else
  echo ""
  echo "FAIL: outputs differ."
  exit 2
fi
Complete Guide to Compile-Safe Rust Obfuscation

Rust obfuscation is surrounded by misinformation because Rust compiles to native machine code through LLVM. There is no bytecode, no interpreter, and no source shipped to end users. This means most "Rust obfuscator" tools perform transformations on source files that users never see — with zero effect on shipped binaries, and frequently with compile-breaking bugs.

This page explains what genuinely protects a Rust binary, what compile-safe source transformation does, and how to verify every transformation locally with a script this tool generates.

The Reality of Rust Obfuscation

Rust's toolchain: you write .rs source, rustc compiles it to LLVM IR, LLVM emits native machine code, the linker combines everything into a single executable, and you ship only the executable. Transformations applied to source disappear completely during compilation — LLVM does not preserve local variable names, comment text, or string literal formatting in the final binary.

Any tool claiming to "obfuscate a Rust binary" by renaming source identifiers is misleading. The compiled binary is functionally identical regardless of source-level renaming. This tool states that plainly and provides the real technique instead: build-level obfuscation.

Real Binary Obfuscation for Rust

The techniques that actually change the shipped artifact are all build-time and linker-time:

TechniqueWhat It DoesEffect on Binary
strip = "symbols"Removes symbol namesEliminates function and type names
lto = "fat"Cross-crate LTOInlines and merges code across crates
codegen-units = 1Single codegen unitMaximum inlining; smaller, more merged code
panic = "abort"Immediate abort on panicRemoves stack unwinding tables
Linker -s / --strip-allStrips at link timeRemoves symbols Cargo's own stripping might miss
O-LLVMBogus control flow, substitution, flatteningSubstantially harder to reverse

Compile-Safe Source Transformation

This tool performs the following transformations, all of which cannot produce a compile error on valid input:

Local Binding Renaming (with verified reference updates)

The tokenizer identifies let and let mut bindings, function parameters, closure parameters, and for-loop patterns. Each renamed name has every reference in the file updated consistently. A post-transform pass scans the output for any occurrence of the original name — if one is found as a bare identifier, the output is rejected.

Context-Aware String Encoding (New)

String literals are XOR-encoded with a per-build key only when they appear in a let binding whose value is unambiguously a String. Every other context is left untouched. See the next section for the exact rules.

Non-Doc Comment Removal

Line (//) and block (/* */) comments are removed. Documentation comments (/// and //!) attached to public items are preserved.

String Encoding Rules

Rust validates format strings, requires const-evaluable initializers in const and static, and infers types from context. Encoding a string without knowing its type is what breaks compilation. The tool therefore encodes strings only in these specific patterns:

Source patternEncoded?Why
let x = "...".to_string();✅ YesResult is String
let x = String::from("...");✅ YesString::from(&str) accepts either type
let x: String = "...";✅ YesExplicit type annotation proves String
let x = "..."; (no annotation, no .to_string())❌ NoCould be &str or String depending on context — cannot determine
foo("...")❌ NoCallee parameter type unknown
foo(&"...")❌ NoType is &str
format!("...", ...)❌ NoRust validates format strings at compile time
println!("...", ...) and friends❌ NoSame
const X: &str = "...";❌ NoMust be const-evaluable
static X: &str = "...";❌ NoSame
return "...";❌ NoReturn type unknown
Foo { name: "..." }❌ NoField type unknown
match x { "..." => ... }❌ NoPattern, not runtime value
#[doc = "..."] / include_str!("...")❌ NoMacro / attribute input
What this means in practice: your API key stored as const API_KEY: &str = "..."; cannot be encoded by any tool that produces valid Rust, because const requires const-evaluable expressions and the decoder is a runtime function. If you need to hide such secrets, do not store them in the source — use environment variables, a config file, or a server-side secret store.

Local Verification Workflow

The browser cannot run rustc. The tool generates a shell script that does the real verification. Copy it from the Local Verification tab and run it:

bash verify-obfuscation.sh ./original-project ./obfuscated-project myapp

The script builds both projects with cargo build --release, runs both binaries, and diffs their output. If the build fails, the transformation broke compilation. If the output differs, it broke behavior. Either way, do not ship the output.

Limitations & Legal

  • Source transformation is a mild deterrent. Not encryption, not security. Do not embed secrets in source.
  • Const and static strings remain readable. They cannot be encoded without breaking const-evaluability.
  • Symbol stripping breaks panic messages. Keep an unstripped build for debugging.
  • License compliance. Some licenses require shipping source; obfuscation does not satisfy that.
  • O-LLVM requires a locally built custom rustc. Not possible in a browser.

Related Obfuscators

Frequently Asked Questions

Will the obfuscated Rust source compile?
The transformation is designed to be compile-safe. Identifiers are renamed only for let bindings, fn parameters, closure parameters, and for-loop patterns. String literals are encoded only inside let bindings whose value is a String — either by type annotation or by .to_string()/String::from(...). Strings in format! and println!, in const and static initializers, in &str positions, in macro arguments, and in match patterns are never touched. However, the browser cannot run rustc, so final confirmation requires the local verification script.
Which strings get encoded?
Only strings bound by a let statement in a String context: let x = "...".to_string(), let x = String::from("..."), or let x: String = "...". Strings passed directly to function calls, macro arguments, return statements, match patterns, struct field initializers, and const/static items are left as-is because their type cannot be verified without a full type checker.
Why aren't format! and println! strings encoded?
Rust validates the format string in these macros at compile time. If the string is decoded at runtime, the compiler cannot see the format specifiers and rejects the program. The tool therefore never encodes strings inside these macros.
Will a const API_KEY still be readable?
Yes. const and static initializers must be const-evaluable, so a String decoder cannot be called there. If you store secrets in const items, they will remain in the source and in the compiled binary's read-only data section. Never embed real secrets in a Rust binary — use environment variables or a server-side secret store.
Is the string encoding encryption?
No. It is a reversible XOR with a per-build key stored in the source. Anyone with the source and a debugger can recover the strings in seconds. It is a mild deterrent, not cryptographic protection.
Can a browser truly obfuscate a Rust binary?
No. Rust compiles to native machine code via LLVM. Binary-level obfuscation requires compiler toolchain access. This tool performs compile-safe source transformation and generates the Cargo.toml and linker configuration that produces genuinely obfuscated binaries when you run cargo build --release locally.
What is the local verification script for?
The browser cannot run rustc. The verification script builds both your original project and the obfuscated version with cargo build --release, then diffs their program output. If the outputs match, the transformation preserved behavior for that test case.
Does the tool rename struct fields or enum variants?
No, on purpose. Field and variant names are accessed via obj.field, serialized by serde, and referenced by external code. Renaming them requires whole-project analysis and would break interop with any consumer.
Does the tool rename public functions or types?
No. Items marked pub, extern items, #[no_mangle] and #[export_name] functions, trait method names, and impl method names are preserved. Only local bindings inside function bodies are renamed.
Will renaming break macros?
No identifier inside a macro invocation is renamed. Macros are treated as opaque token streams for renaming purposes. Local variables declared outside a macro and referenced inside it are renamed consistently by the reference-update pass.
Does the tool upload my Rust code?
No. All transformation happens in your browser. Your source never leaves your device.
What actually obfuscates a Rust binary?
Enabling strip = "symbols" in the Cargo release profile, enabling LTO, setting codegen-units = 1, using panic = "abort", applying objcopy --strip-all or llvm-strip as a post-build step, and for maximum protection using obfuscator-llvm (O-LLVM) with a custom rustc toolchain.
Is the generated Cargo.toml config safe to add to my project?
Yes. The generated [profile.release] section only changes build-time optimization and stripping options. It does not add dependencies or modify source code.
What Rust editions are supported?
The tokenizer recognizes Rust 2015, 2018, and 2021 edition syntax, including async/await, const generics, impl Trait, raw strings, byte strings, and lifetimes. Nightly-only syntax may not be fully recognized.
What is obfuscator-llvm (O-LLVM)?
O-LLVM is a fork of LLVM that adds obfuscation passes such as instruction substitution, bogus control flow, and control flow flattening. Using it with Rust requires building a custom rustc that links against the modified LLVM, which cannot be done in a browser.
Does stripping symbols break debugging?
Yes. Once you strip symbols, stack traces lose function names. Keep an unstripped build in a private location for debugging.
Can I use this tool for WebAssembly Rust projects?
Partially. wasm-pack produces a .wasm file with a JavaScript wrapper. The wrapper can be obfuscated with our JavaScript Obfuscator, but the .wasm module itself needs wasm-opt and similar tooling.
Is the source transformation reversible?
Yes. Renaming local identifiers and XOR-encoding strings are both reversible. Source transformation is a mild deterrent, not encryption.
Do I need Rust installed to use this tool?
You do not need Rust to run the source transformation. You do need the Rust toolchain to compile and to run the verification script, and to benefit from the generated build configuration.
What does panic = "abort" do?
It replaces the default unwinding panic strategy with immediate process abort. This removes stack unwinding tables from the binary, reducing size and stripping metadata needed for detailed panic messages.
Is this obfuscation compliant with open-source licenses?
Only if you own the code or the license permits modification and distribution in obfuscated form. Many licenses (notably GPL) require source availability. Check your license before distributing obfuscated binaries.
How do I test that the obfuscated code behaves identically?
Use the Local Verification tab's shell script. It builds both versions with cargo build --release and diffs their output. For deeper confidence, add unit tests to your crate and run cargo test on both versions.

Conclusion

Real Rust obfuscation happens at the build configuration and linker level. This tool gives you the actual Cargo.toml, .cargo/config.toml, and build.rs snippets that produce genuinely obfuscated binaries, plus a compile-safe source transformation that renames locals and encodes strings only in type-safe contexts. It never claims compilation success on its own — instead it gives you a script that runs cargo build --release and diffs the output. Verify locally, then ship.