Skip to content

Rust API

David Reed edited this page Nov 20, 2026 · 4 revisions

The obfuscation engine is not implemented yet. This page documents the intended public surface of crack-core, not current behavior. The method bodies do not exist yet, and the field set may grow as the passes land.

The workspace has two crates. crack-core is the library (the passes, the edit core, the pool and decoder format). crack-cli is the crack binary (argument parsing and the file walk). Only crack-core is meant for embedding; to run crack, use the CLI or the npm package.

FORMAT_VERSION

pub const FORMAT_VERSION: u32;

The version of the pool and decoder format crack emits. It appears in every Report. A consumer that decodes crack output checks it against the decoder it expects. Bump it when the pool layout or the emitted decoder changes so an older decoder cannot read it.

Options

pub struct Options { /* ... */ }

impl Options {
    pub fn new() -> Self;
}

How one pass is configured: the names to rename, the canary list, the source map directory, the seed, and the parallelism. The fields mirror the CLI flags and the Configuration file. The field names are not frozen; build an Options through its constructor and setters.

Obfuscator

pub struct Obfuscator { /* ... */ }

impl Obfuscator {
    pub fn new(options: Options) -> Self;
    pub fn run(&self, dirs: &[std::path::PathBuf]) -> Result<Report, Error>;
}

The entry point. run processes the directories and returns a Report or an Error. It fails closed: on the first file it cannot fully process it writes no partial output and returns an Error naming the file and the reason. Files are independent and run in parallel up to the job count. The pass is not idempotent; run it once per build.

Report

pub struct Report {
    pub format_version: u32,
    pub files_processed: usize,
    pub files_skipped: usize,
    pub duration: std::time::Duration,
    pub check: bool,
}

What a successful run returns. format_version equals FORMAT_VERSION. files_skipped counts files left untouched (a .map, an already-processed file, a vendored asset). check is true when the run wrote nothing.

Error

pub enum Error { /* ... */ }

The failure type run returns, implementing std::error::Error and Display. Every variant names the file and the reason: a parse error, a store name outside the allow-list, a proxy name across a regex escape, a wasm literal in mixed base64 alphabets, a surviving canary literal, or I/O. The variant list is not frozen; match with a wildcard arm.

How it rewrites

crack-core parses with OXC, locates edits in the AST, and splices byte ranges into the original source string. It does not reprint the AST through a code generator, so every byte it does not touch stays as the bundler emitted it. See Contributing for the build and the parity harness.

Clone this wiki locally