Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -5,179 +5,134 @@ tags:
|
|
| 5 |
- code
|
| 6 |
- symbolic-math
|
| 7 |
- deobfuscation
|
| 8 |
-
- security
|
| 9 |
- mixed-boolean-arithmetic
|
| 10 |
license: mit
|
| 11 |
-
pipeline_tag:
|
| 12 |
---
|
| 13 |
|
| 14 |
# MBA Simplifier β Pipeline v5
|
| 15 |
|
| 16 |
Simplifies **Mixed Boolean-Arithmetic (MBA)** expressions used in code obfuscation.
|
| 17 |
-
Combines BFS
|
| 18 |
-
neural-guided search. Every output is oracle-verified correct.
|
| 19 |
|
| 20 |
-
|
| 21 |
-
from simplify import simplify
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
```
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
This pipeline deobfuscates MBA expressions back to their simplest form, operating
|
| 39 |
-
over 8-bit or 32-bit integer arithmetic.
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
## Quick Start
|
| 44 |
|
| 45 |
```python
|
| 46 |
-
from
|
| 47 |
|
| 48 |
-
# Basic usage β 8-bit (default)
|
| 49 |
result = simplify("(x & y) + (x | y)")
|
| 50 |
-
#
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
# 32-bit mode
|
| 53 |
result = simplify("(x & y) + (x | y)", bits=32)
|
| 54 |
-
# β "x + y"
|
| 55 |
|
| 56 |
-
# With neural guidance
|
| 57 |
-
result = simplify("
|
| 58 |
-
# β "x + y"
|
| 59 |
```
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
**Variables:** any identifiers matching `[a-zA-Z_][a-zA-Z0-9_]*`
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
## Input / Output Examples
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
| Input (obfuscated) | Output (simplified) | Identity |
|
| 72 |
|---|---|---|
|
| 73 |
-
| `(x & y) + (x | y)` | `x + y` |
|
| 74 |
-
| `(x \| y) - (x & y)` | `x ^ y` |
|
| 75 |
-
| `(x + y) - 2 * (x & y)` | `x ^ y` |
|
| 76 |
-
| `~(~x)` | `x` |
|
| 77 |
-
| `-(~x) - 1` | `x` |
|
| 78 |
-
| `~(~x & ~y)` | `x \| y` |
|
| 79 |
-
| `x & (x \| y)` | `x` |
|
| 80 |
-
| `x ^ x` | `0` |
|
| 81 |
-
| `
|
| 82 |
-
| `(~x
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
| MBA-Blast (USENIX '21) | 100% | 100% | 77% | 15.8ms |
|
| 95 |
-
| SSPAM (Quarkslab) | 100% | 0% | 0% | 298.6ms |
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|---|---|---|---|---|
|
| 103 |
-
| **Pipeline v5 (ours)** | **100%** | **100%** | **74%** | **18.7ms** |
|
| 104 |
-
| Symbolic only | 100% | 89.3% | 10% | 0.7ms |
|
| 105 |
-
| MBA-Blast (USENIX '21) | 100% | 0% | 0% | 0.0ms *(fail: 300)* |
|
| 106 |
-
| SSPAM (Quarkslab) | 100% | 0% | 0% | 289.5ms *(fail: 300)* |
|
| 107 |
|
| 108 |
-
##
|
| 109 |
|
| 110 |
| Method | Correct% | Reduced% | Size reduction | ms/expr |
|
| 111 |
|---|---|---|---|---|
|
| 112 |
-
| **Pipeline v5 (ours)** | **100%** | **
|
| 113 |
-
|
|
| 114 |
-
|
|
| 115 |
-
|
|
| 116 |
-
| LLaMA-3.3-70B (Groq) | 93% | 12% | 16% | 34.4ms *(fail: 160)* |
|
| 117 |
-
|
| 118 |
-
Key findings vs LLaMA-3.3-70B: correctness +7pp, reduction +59pp, 0 wrong outputs vs 14.
|
| 119 |
-
|
| 120 |
-
---
|
| 121 |
-
|
| 122 |
-
## Architecture
|
| 123 |
-
|
| 124 |
-
The pipeline runs five layers in order, stopping at the first success:
|
| 125 |
-
|
| 126 |
-
1. **BFS exact lookup** β exhaustive enumeration of all expressions up to size 5.
|
| 127 |
-
Maps fingerprints (multi-point evaluation tuples) to minimal canonical forms.
|
| 128 |
-
|
| 129 |
-
2. **Linear synthesis** β MΓΆbius inversion to detect and reconstruct linear MBA.
|
| 130 |
-
|
| 131 |
-
3. **Algebraic kΒ·base synthesis** β identifies `k * (x OP y) + linear` decompositions
|
| 132 |
-
using modular arithmetic.
|
| 133 |
-
|
| 134 |
-
4. **Symbolic rewriting** β 40+ rules covering MBA identities, De Morgan,
|
| 135 |
-
absorption, two's complement, XOR-NOT, cancellation, and constant folding.
|
| 136 |
-
Runs up to 30 passes to fixpoint.
|
| 137 |
-
|
| 138 |
-
5. **Neural-guided beam search** (optional) β Transformer classifier predicts
|
| 139 |
-
which rewrite rules to try next. Symbolic executor applies them; oracle
|
| 140 |
-
verifies each candidate.
|
| 141 |
-
|
| 142 |
-
**Oracle verification:** every candidate result is verified against the input
|
| 143 |
-
via exhaustive evaluation (8-bit β€ 2 variables: all 65,536 input combinations)
|
| 144 |
-
or 4096 random points (32-bit / 3-variable). The pipeline never returns a
|
| 145 |
-
wrong answer β it falls back to the original if verification fails.
|
| 146 |
-
|
| 147 |
-
---
|
| 148 |
|
| 149 |
-
|
| 150 |
|
| 151 |
-
|
| 152 |
-
pip install numpy torch # torch is optional (neural layer only)
|
| 153 |
-
```
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
## Limitations
|
| 160 |
|
| 161 |
-
- **
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
- **
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
- **First-call latency:** BFS table construction takes ~0.5s (8-bit 2-var).
|
| 169 |
-
Subsequent calls with the same variable set are fast (< 5ms).
|
| 170 |
-
|
| 171 |
-
---
|
| 172 |
-
|
| 173 |
-
## Citation
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
-
```bibtex
|
| 178 |
-
@misc{mba-pipeline-v5,
|
| 179 |
-
title = {MBA Simplification Pipeline v5},
|
| 180 |
-
year = {2025},
|
| 181 |
-
note = {https://huggingface.co/}
|
| 182 |
-
}
|
| 183 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
- code
|
| 6 |
- symbolic-math
|
| 7 |
- deobfuscation
|
|
|
|
| 8 |
- mixed-boolean-arithmetic
|
| 9 |
license: mit
|
| 10 |
+
pipeline_tag: text2text-generation
|
| 11 |
---
|
| 12 |
|
| 13 |
# MBA Simplifier β Pipeline v5
|
| 14 |
|
| 15 |
Simplifies **Mixed Boolean-Arithmetic (MBA)** expressions used in code obfuscation.
|
| 16 |
+
Combines BFS lookup over a pre-computed expression table, symbolic rewriting (40+ rules),
|
| 17 |
+
and optional neural-guided search. Every output is oracle-verified correct.
|
| 18 |
|
| 19 |
+
## Quick Start
|
|
|
|
| 20 |
|
| 21 |
+
```bash
|
| 22 |
+
git clone https://huggingface.co/<your-username>/mba-simplifier
|
| 23 |
+
cd mba-simplifier
|
| 24 |
+
pip install -r requirements.txt
|
| 25 |
+
python inference.py "(x & y) + (x | y)"
|
| 26 |
```
|
| 27 |
|
| 28 |
+
Expected output:
|
| 29 |
+
```
|
| 30 |
+
BFS: 18,189 entries (182ms)
|
| 31 |
+
Input: (x & y) + (x | y)
|
| 32 |
+
Simplified: x + y
|
| 33 |
+
Reduction: 57% (bfs)
|
| 34 |
+
Latency: 186 ms (cold), ~2 ms (warm)
|
| 35 |
+
```
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
## Python API
|
|
|
|
|
|
|
| 38 |
|
| 39 |
```python
|
| 40 |
+
from inference import simplify
|
| 41 |
|
|
|
|
| 42 |
result = simplify("(x & y) + (x | y)")
|
| 43 |
+
print(result["simplified"]) # "x + y"
|
| 44 |
+
print(result["reduction"]) # 0.571
|
| 45 |
+
print(result["strategy"]) # "bfs"
|
| 46 |
+
print(result["latency_ms"]) # ~2 ms warm
|
| 47 |
|
| 48 |
+
# 32-bit mode (symbolic only β BFS table is 8-bit)
|
| 49 |
result = simplify("(x & y) + (x | y)", bits=32)
|
| 50 |
+
# β "x + y" (strategy: symbolic)
|
| 51 |
|
| 52 |
+
# With neural guidance
|
| 53 |
+
result = simplify("complex_expr", model_path="mba_classifier_v2.pt")
|
|
|
|
| 54 |
```
|
| 55 |
|
| 56 |
+
### Return fields
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
| Field | Type | Description |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| `simplified` | str | Simplified infix expression |
|
| 61 |
+
| `original` | str | Input expression |
|
| 62 |
+
| `reduction` | float | Tree-size reduction (0.0β1.0) |
|
| 63 |
+
| `strategy` | str | `bfs` / `symbolic` / `neural` / `none` |
|
| 64 |
+
| `latency_ms` | float | Wall-clock time in milliseconds |
|
| 65 |
|
| 66 |
## Input / Output Examples
|
| 67 |
|
| 68 |
+
| Input | Output | Strategy |
|
|
|
|
|
|
|
| 69 |
|---|---|---|
|
| 70 |
+
| `(x & y) + (x \| y)` | `x + y` | bfs |
|
| 71 |
+
| `(x \| y) - (x & y)` | `x ^ y` | bfs |
|
| 72 |
+
| `(x + y) - 2 * (x & y)` | `x ^ y` | bfs |
|
| 73 |
+
| `~(~x)` | `x` | bfs |
|
| 74 |
+
| `-(~x) - 1` | `x` | symbolic |
|
| 75 |
+
| `~(~x & ~y)` | `x \| y` | symbolic |
|
| 76 |
+
| `x & (x \| y)` | `x` | symbolic |
|
| 77 |
+
| `x ^ x` | `0` | bfs |
|
| 78 |
+
| `x * 1 + y * 0` | `x` | bfs |
|
| 79 |
+
| `(x & ~y) \| (x & y)` | `x` | bfs |
|
| 80 |
|
| 81 |
+
## Architecture
|
| 82 |
|
| 83 |
+
**Three-layer pipeline** (first hit wins):
|
| 84 |
|
| 85 |
+
1. **BFS lookup** β pre-computed table of 18,189 minimal 8-bit expressions
|
| 86 |
+
(loaded from `bfs_table_6.json`, ~180ms first call, ~2ms warm).
|
| 87 |
+
Coverage: all 2-variable expressions up to AST size 6.
|
| 88 |
|
| 89 |
+
2. **Symbolic rewriting** β 40+ algebraic rules covering MBA identities,
|
| 90 |
+
De Morgan, absorption, two's complement, XOR-NOT, cancellation,
|
| 91 |
+
constant folding. Runs to fixpoint (up to 30 passes). Works for 8-bit
|
| 92 |
+
and 32-bit.
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
3. **Neural-guided beam search** (optional, requires `mba_classifier_v2.pt`) β
|
| 95 |
+
Transformer classifier predicts rewrite rules to try. Symbolic executor
|
| 96 |
+
applies them; oracle verifies each candidate. Requires `torch`.
|
| 97 |
|
| 98 |
+
**Oracle verification:** every candidate result is verified by random sampling
|
| 99 |
+
(512 points). The pipeline never returns a wrong answer β it falls back to the
|
| 100 |
+
original if verification fails.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
## Benchmark Results
|
| 103 |
|
| 104 |
| Method | Correct% | Reduced% | Size reduction | ms/expr |
|
| 105 |
|---|---|---|---|---|
|
| 106 |
+
| **Pipeline v5 (ours)** | **100%** | **100%** | **77%** | **6.5ms** |
|
| 107 |
+
| MBA-Blast (USENIX '21) | 100% | 100% | 77% | 15.8ms |
|
| 108 |
+
| SSPAM (Quarkslab) | 100% | 0% | 0% | 298.6ms |
|
| 109 |
+
| LLaMA-3.3-70B | 93% | 12% | 16% | 34.4ms |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
*Dataset: MBA-Blast paper dataset, 62 expressions, 8-bit 2-var.*
|
| 112 |
|
| 113 |
+
## Files
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
| File | Description |
|
| 116 |
+
|---|---|
|
| 117 |
+
| `inference.py` | Standalone inference β the only file you need |
|
| 118 |
+
| `bfs_table_6.json` | Pre-computed BFS table, 18K entries (1.7MB) |
|
| 119 |
+
| `mba_classifier_v2.pt` | Neural model, 2.2M params (8.6MB, optional) |
|
| 120 |
|
| 121 |
## Limitations
|
| 122 |
|
| 123 |
+
- **BFS table:** 8-bit only, variables `x` and `y` only. Expressions with 3+
|
| 124 |
+
variables or 32-bit semantics fall through to symbolic rewriting.
|
| 125 |
+
- **Variables:** up to 2 variables for BFS; symbolic handles more.
|
| 126 |
+
- **Bit width:** 8 and 32 only.
|
| 127 |
+
- **Cold start:** BFS table loads in ~180ms on first call; subsequent calls
|
| 128 |
+
are fast (~2ms).
|
| 129 |
+
- **Neural model trained on 8-bit** β may not generalize perfectly to 32-bit.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
+
## Requirements
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
```
|
| 134 |
+
torch>=1.13.0 # required for neural layer (optional otherwise)
|
| 135 |
+
numpy>=1.21.0 # required for oracle exhaustive check (8-bit)
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Python 3.10+ required (structural pattern matching).
|