$ show trailofbits/CoBRA
CoBRA is a C++ library and CLI tool for simplifying mixed Boolean-arithmetic (MBA) expressions, commonly used in software obfuscation. It ingests expressions combining arithmetic (+, -, *) with bitwise (&, |, ^, ~) and shift operators and outputs a simplified equivalent form. The core engine uses a worklist orchestrator that coordinates 36+ passes, including signature-based transforms (CoB butterfly, ANF recovery), semilinear normalization with bit partitioning, decomposition (product, polynomial, template cores), ghost residual solving, and pattern matching. An optional Z3 verifier proves full-width equivalence. The tool can be used as a standalone CLI (`cobra-cli`), as an LLVM pass for automatic deobfuscation during compilation, or as a library (`cobra::Simplify()`). The codebase is well-structured with extensive test coverage (1195+ tests) and benchmark datasets from multiple research projects. While the core is tightly coupled internally, several generic utilities (Result type, profiling stubs, math helpers) are reusable independently.
The LLM identified 3 files worth highlighting for reuse:
A generic Result<T> type similar to std::expected, but with integrated error codes, reason chains (ReasonFrame), and diagnostic fields. It is self-contained (only standard library dependencies) and used throughout the codebase for all solver outcomes. Could be extracted into any C++ project needing rich error reporting without exceptions.
A set of macros (COBRA_PROFILE_ZONE, COBRA_PROFILE_FRAME) that wrap the Tracy profiler. When COBRA_ENABLE_TRACY is off, all macros expand to no-ops with zero overhead. This pattern is isolated and could be reused in any C++ project to add optional profiling with minimal dependency.
Provides utility functions for factorial, Stirling numbers, binomial coefficients, and other combinatorial operations used in polynomial basis transforms. The functions are pure, well-tested, and have no internal dependencies beyond standard math headers. They can be extracted for any project requiring these computations.