rumba-core 1.0.0

Core library for MBA (Mixed Boolean-Arithmetic) expression simplification
Documentation

Simplification of Mixed Boolean-Arithmetic (MBA) expressions.

MBA expressions interleave bitwise operators (&, |, ^, ~) with arithmetic ones (+, -, *) to obscure an otherwise simple value. They are a common code-obfuscation primitive; rumba-core recovers the underlying expression.

Overview

  • [expr::Expr] is the expression tree. Build one directly with the standard operators (+, -, *, &, |, ^, !) over [expr::Expr::Var] and constants, or enable the parse feature to read one from a string with [parser::parse_expr].
  • [simplify::simplify_mba] reduces an expression on a given bit width. Pass a [simplify::SimplifyCache] via [simplify::simplify_mba_cached] to reuse linear solves across many calls.

Simplification is best-effort: it returns a [simplify::SolveError] or leaves the input untouched rather than aborting the process.

Example

use rumba_core::expr::{Expr, VarId};
use rumba_core::simplify::simplify_mba;

let x = Expr::Var(VarId(0));
let y = Expr::Var(VarId(1));

// (x ^ y) + 2*(x & y) is an MBA encoding of x + y.
let mba = (x.clone() ^ y.clone()) + 2u64 * (x.clone() & y.clone());

let simplified = simplify_mba(mba, 64).expect("simplification failed");

// The result is semantically equal to x + y.
assert!(simplified.sem_equal(&(x + y), 64, 1000).is_ok());

Features

  • parse — string parsing of expressions via [parser].
  • jit — JIT-compiled evaluation for faster semantic checks.

The solver's contract is best-effort: it must degrade to a SolveError (or leave the input alone) rather than abort the process. Forbid silent unwrap() and panic! in library code so every fallible spot is either handled or an explicit, message-carrying expect(). Tests may still unwrap freely.