droidsaw takes a DEX file or a Hermes bundle apart and puts it back together byte-for-byte. For DEX, we ran that test against every file in F-Droid — 5,767 DEX files across 3,782 apps — and recovered each one bit-identically under preservation mode. For Hermes, we ran the same test on bytecode versions v84, v96, v98, and v99.
A roundtrip like this is the kind of test that fails loudly when the model of the format has a hole. If our model had a wrong rule anywhere — a string-table offset off by one, a missed alignment requirement, a padding byte we forgot to preserve — the re-emitted bytes would diverge from the input, and the test would say where. And it isn’t a one-off check: every parsed section is walked end-to-end and tiled into typed regions, so every byte ends up classified as a parsed Entry, an inter-entry Gap, or an UnparseableTail.
droidsaw is a decompiler and security-auditing suite for mobile
apps. It walks an APK end to end — DEX, Hermes, native ELF, plus
the manifest, signing, and resource surfaces — and cross-
references the boundaries: a direct NativeModules.X.method()
call through the React Native bridge resolves to its Java
implementation as a single taint path, joined across the layers
rather than reported on either side separately. (Production
Metro bundles often emit the hoisted-closure shape instead;
visitor coverage for that lands in v1.x.) It also runs on a
standalone DEX or HBC file when an APK isn’t on hand.
Dart (Flutter), Unity IL2CPP, and iOS support are on the roadmap.
The workspace lints unwrap, expect, and panic as errors on
every non-test module — no panics so far against the adversarial
inputs we’ve come up with, though that’s the discipline floor,
not a proof of absence. 96 Kani harnesses extend
that floor with bounded-model-checked proofs on the arithmetic
and decode properties the lints can’t cover, with independent
oracles on the ones that warrant them (char::encode_utf8 for
MUTF-8 codepoint decoding; u128 for the Hermes function_get
u64 overflow).
Pure Rust. BSD-3-Clause.
What’s new here
Most Android RE tooling works per-layer: decompile the DEX, separately inspect the
manifest, run YARA over the APK manually. The cross-layer questions — does this JS
value reach Runtime.exec? does this Hermes bundle ship key material that the native
layer never zeroes? — require stitching output from several tools by hand.
droidsaw’s contributions:
Byte-exact Hermes reconstruction. Hermes is Meta’s JS engine for React Native — bytecode v40–v100, sparse public documentation. droidsaw disassembles Hermes bundles and reassembles them to bit-identical output, which implies complete coverage of the binary format: string table, bigint table, alignment, padding, and metadata layout. Every decompile output is additionally round-tripped through OXC; output that fails parse is annotated and returned, never silently dropped.
Byte-exact DEX reconstruction. 100% byte-identical round-trip on F-Droid (3782 apps / 5767 DEX files) under preservation mode. 309 files differ in 24 header bytes only — exclusively non-canonical-SHA-1 inputs from the legacy
dxtoolchain (94% are DEX v035); droidsaw recomputes correct checksums on default emit, or preserves verbatim under audit mode. The cascade is typed-attributed viaCanonicalTransform::InputChecksumNormalized. This is the correctness oracle: not a fixture comparison, not a class-count metric, but reconstruction fidelity on real APKs.Cross-layer taint across the React Native bridge. A JS
NativeModules.X.method()call resolves to its@ReactMethodimplementation in Java, and call flow follows from a JS event handler through the bridge to a native sink — represented as oneTaintFinding, not three disconnected reports. 15 taint sources × 15 sinks defined indroidsaw-common, including bridge edges that span the layers. v1 ships the record type + stitcher infrastructure; today’s HBC visitor catches directNativeModules.X.method()bridge calls but not the hoisted closure-captured shape that production Metro bundles emit — that visitor extension graduates in v1.x (see Shipped in v1.x).Completeness gauge on every parsed section. Variable-length data sections (debug_info, annotation_set, …) are walked end-to-end and tiled into typed regions — every byte is classified as a parsed Entry, an inter-entry Gap, or an UnparseableTail. Preserve-mode emit refuses with a typed error rather than silently filling gaps with zeros. The total-tiling claim is a build-time invariant, not a runtime hope.
R8 outline-helper recogniser with family-prefix attestation rates measured. R8 emits structural helpers under namespace conventions (
j$for D8 library desugar,io.flutterfor the Flutter Java bridge,h1for horizontal-merge bridges,androidxfor AAR-shipped libraries). The BlockOutlined recogniser fires on the structural shape; in mapping-less analysis the namespace prefix is the only attribution signal. Structural attestation rate = the share of classes in a family-prefix bucket whose internal shape matches the expected template (D8 desugar, Flutter bridge, etc.). Measured across the F-Droid corpus:j$,io.flutter, andh1carry 0% structural attestation — the recogniser fires liberally on the prefix shapes, but F-Droid’s open-source apps rarely ship the exact R8 outline-class template at scale, so a class arbitrarily named under those prefixes gets suppressed from analyst tooling with no in-bucket fallback.androidxretains 1.93% via the inner-class$EnumUnboxingLocalUtilitypattern that R8 preserves under minification. The structural recogniser ships indroidsaw-dex; attestation rates are not yet exposed in the runtime attestation path.Query your audit with SQL. Every
auditinvocation persists findings, credentials, taint flows, cross-layer composites, and string xrefs to a SQLite database with FTS5 full-text indexes and pre-canned views (actionable_findings,cross_layer_taint_critical,taint_critical,audit_summary,credentials,semgrep_hits,confidence_summary). No JSON-grep gymnastics:sqlite3 audit.db "SELECT * FROM actionable_findings WHERE cwe=78". The database is the API; the JSON envelope, the MCP server, and the bench harness all route through the same query layer. Re-runs of the same mode upsert by identity hash (no accumulating duplicates); cross-mode runs additively populate distinct rows.
Robustness
Adversarial inputs are the norm in malware analysis. The lint floor (described in the lead) is the broad discipline; what extends past it:
- Fuzz targets via
cargo fuzz(libFuzzer) on the DEX, Hermes, and APK parsers — every crash gets minted as a typed error case the parser then has to handle correctly. - Sanitizer passes run the parser paths under AddressSanitizer
and MemorySanitizer (via
make san-asan-ubsan/make san-msan; MSan excludes droidsaw-apk due to a yara-x/wasmtime upstream gap — ASan covers the APK crate in full). The workspace also setspanic = "abort"— a stale or miscategorised panic suppression terminates the process at runtime rather than silently passing the lint. - Arithmetic side-effects denied at the lint level — checked ops or
?-propagated errors throughout, not just on the parser paths. - Roundtrip and tiling invariants (described in the lead) hold under the fuzz corpus, not just the fixture set.
- OXC round-trip on every Hermes decompile output — the output is re-parsed through a third-party JavaScript parser, and anything OXC rejects is annotated and surfaced rather than silently dropped.
Architecture
Both decompilers follow the same pipeline:
decode → CFG → SSA (Braun) → optimize → Expr IR
→ structure → sugar → emit → validate
Deterministic IR — BTreeMap throughout, no HashMap. Typed opcode enum. Structural
try-catch (partition before recurse). Zero-failures ratchet: SEMANTIC_FAIL stays
at zero, COMPILE_FAIL decreases monotonically. Invariant tests at every stage
boundary. Cross-validated against reference disassemblers. Production APKs tested
alongside fixtures.
Formal backing
- Kani — bounded model checking on the arithmetic and decode helpers
where the statement is decidable. Examples: DEX access-flag bit-field
bounds, the MANIFEST.MF base64 positional gate, the Hermes
function_getu64-overflow guard against a u128 oracle, MUTF-8 codepoint decoding againstchar::encode_utf8. 96 harnesses across the workspace. - Lean 4 — 20 proved theorems on statements that quantify over
arbitrary input length or arbitrary CFG shape and are therefore out
of Kani’s bounded reach: AXML parser totality and acyclicity,
dominator antisymmetry and transitivity, lattice monotonicity of the
dataflow fixed point, Hermes try-catch reverse-post-order (RPO)
ordering. No
sorry, noaxiom. The Lean ↔ Rust correspondence is asserted by source comment and maintained by hand, not mechanically verified. Released as a separate workspace (droidsaw-lean); not in the Rust dependency graph.
What it finds
Patterns droidsaw has surfaced on production apps:
- Key material in the JS heap — crypto wallets shipping private-key operations in Hermes with no native boundary, no memory zeroing.
- Exported components without permission guards — activities and services reachable from any app, leaking auth tokens, OAuth codes, refresh tokens.
- Analytics SDKs receiving data they shouldn’t — session replay tools capturing sensitive screens; ad SDKs receiving health or financial signals as targeting.
- Staging infrastructure in production builds — internal endpoints, debug flags, hardcoded credentials surviving release.
- Weak signing-cert crypto — ROCA fingerprint (CVE-2017-15361, Nemec et al.
discriminator), Fermat-factorable close primes (returns
(p, q)), batch-GCD shared-prime recovery across corpus (Bernstein quasilinear), small-dWiener regime fingerprinted viae > N^0.75as a heuristic indicator; full(p, q)recovery v1.x.
A worked example on a stalkerware sample: Cerberus Anti-theft: a
reverse engineering.
Nine APKs analysed cross-version, 44 FCM commands documented; the
hidden com.lsdroid.lsp companion added to Echap’s
stalkerware-indicators
— the IOC feed consumed by MVT, Quad9, AdGuard, TinyCheck, MISP —
so consumers now see both halves of the LSP↔main IPC pair.
CVE-class detectors (APK signing + container):
- Master Key family — duplicate-ZIP-entry attack (CVE-2013-4787) + Master Key II V1-unsigned-entry-inside-v1-signed attack (Forristal / Bluebox, 2013; AOSP bug 9695860). Both surface from the ZIP last-wins walk plus the V1 manifest-binding gauge.
- Janus — DEX-prefix masquerade on v1-signed-only APKs (CVE-2017-13156); detected via the DEX-magic-bytes prefix gate inside the APK container walker.
- v2 / v3 rollback — downgrade-to-v1 attacks via signing-block
size mismatch or rollback-header mismatch (CWE-347, Improper
Verification of Cryptographic Signature); surfaced as
SIGNING_BLOCK_SIZE_MISMATCHandV1_ROLLBACK_HEADER_MISMATCH. - APK signing-block integrity —
WEAK_SIGNATUREfor off-spec algorithm IDs, plus per-AOSP-spec verifier for v1 through v4 (cryptographic gate currently v3 for v4 inputs; see Shipped in v1.x).
Shipped in v1.x
v1 ships the infrastructure for these three; the analysis coverage lands post-tag in named follow-up streams.
Cross-layer taint visitor coverage on real React Native bundles. Today’s HBC visitor catches direct
NativeModules.X.method()bridge calls. Production Metro bundles emit a hoisted shape (a wrapper-object load from the closure environment carryingNativeModulesas a property + user input arriving via the same closure capture) that the v1.x visitor extension catches. Composites fire on a synthetic fixture today; coverage on shipped RN apps graduates in v1.x.v4 signature verification. v1 parses the
.idsigsidecar and cross-checksapk_digestagainst the v3 signing block. v1.x adds Merkle-root + v4-signature verification end-to-end (currently the parser surfaces structure; the cryptographic gate defers to v3).Wiener-regime RSA full recovery. v1 fingerprints
e > N^0.75exponents as the Wiener-attack-vulnerable shape and flags them. v1.x adds continued-fraction-based(p, q)extraction so the finding ships with concrete factors.
Per-layer scope
| Layer | Status |
|---|---|
| APK container | Full. Signing: v1–v3 verified (RSA-PSS / PKCS1v1_5 / ECDSA / DSA + v3 proof-of-rotation lineage walked under parent pubkey); v4 .idsig sidecar parsed and apk_digest cross-checked against v3 (Merkle-root + v4-signature verification graduates in v1.x). CVE-class detectors: Janus (CVE-2017-13156), Master Key II (AOSP bug 9695860, Bluebox 2013), v2/v3 rollback (CWE-347), block-size mismatch. Container surface: crypto, YARA (60 rules across credential / packer / crypto / anti-analysis), SDK inventory. |
| DEX → Java | Real decompiler. 100% byte-identical roundtrip on F-Droid (5,767 DEX files across 3,782 apps) under preservation mode; the 5.4% header-cascade subset is exclusively legacy-dx-toolchain non-canonical SHA-1, typed-attributed via InputChecksumNormalized. Zero-failures ratchet on fixture set. |
| Hermes → JS | Real decompiler. Byte-exact reconstruction verified on bytecode versions v84, v96, v98, v99. OXC round-trip validated on decompile output. |
| Native ELF | Metadata, hardening flags, JNI exports, relocation counts. No disassembly. |
Capabilities
Read the code
- Decompile DEX to Java and Hermes to JavaScript. Disassemble individual functions. Diff two Hermes bundles.
- Cross-reference both directions — strings to the functions that touch them, callers to callees, types to their usage sites. “Who references this key?” is a query, not a grep.
- Recognise R8 synthetic helpers — outline classes are identified
by structural shape (
BlockOutlinedrecogniser), no ProGuard mapping required. Family-prefix labels forj$(D8 library desugar),io.flutter,h1(horizontal-merge bridges), andandroidx(with$EnumUnboxingLocalUtilityas the empirically-preserved attestation pattern). - Decompile-time string deobfuscation —
droidsaw deobf-stringsruns a target DEX method in an emulator with concrete argument sets and recovers the plaintext strings it would have computed at runtime. Defeats common XOR / Base64 / AES-with-static-key obfuscator passes that strip readable strings from the binary.
Inspect the APK container
- Container surface — signing schemes v1–v4, certificate crypto, ELF hardening flags, binary manifest, resource tables, webview assets, entropy profiles.
Audit
- Find vulnerabilities with Semgrep — droidsaw extracts decompiled source to
disk in Semgrep-ready layout;
audit --mode=semgrepinvokes Semgrep and persists hits to the findings DB. Bring your own rules (no bundled ruleset). - Identify secrets — extracts strings across every layer;
audit --mode=trufflehoginvokes TruffleHog and lands hits in thecredentialsSQLite table. - SBOM + VEX, reconstructed from the APK —
droidsaw sbom <apk>emits a CycloneDX 1.5 BOM and OpenVEX 0.2.0 envelope from what the compiled APK reveals: 50+ third-party SDK fingerprint rules (analytics / attribution / crash / auth / ads / push / runtime / payments / maps / ml), native libs by ABI with literal.rodataversion anchors (e.g.," deflate 1.2.8 Copyright 1995-2013 Mark Adler ") — consumers verify the extraction, not the string — nested JARs, DEX static-version fingerprints, Hermesnode_modules/paths. Intentionally partial — pair with build-time SBOMs where they exist. PURL + CPE 2.3 (CPE so NVD-routed scanners catchpkg:generic/<abi>/<lib>natives that PURL-only matchers skip), plus OmniBORgitoidIDs. VEX emitted standalone (trivy --vex/grype --vex) and inline as CDX 1.4+vulnerabilities[]. Two evidence rules — curatedfixed_intable and a cross-fork identity rule (LibreSSL libssl against an OpenSSL-keyed CPE →not_affected,justification: component_not_present). CVEs with no evidence emit no statement — silent rather than fabricated. - Pick the audit passes you need —
audit --mode basic|full|semgrep|trufflehogtoggles which passes run;--update-dbupserts incrementally (UNIQUE index onsignature_hash) so repeat runs against the same DB don’t duplicate findings;--no-update-dboverwrites the prior run’s rows for the chosen mode. Mix modes across runs to build a single DB with findings from every angle.
Interop
- Generate Frida hook scaffolds —
Java.use(...).method.overload(...).implementationtemplates for DEX methods that reference matched strings (overload signatures generated from the proto walker, not hand-filled); Hermes function names + bytecode offsets emitted as references for hermes-aware hooking tools. - Export parsed layers to SQLite —
droidsaw scan export <apk>dumps strings, functions, classes, and call-graph edges across HBC + DEX into a queryable DB (distinct from theauditDB covered above; this one is the parser-state surface). - Batch the corpus — NDJSON scans for fleet-scale analysis.
- Drive from an agent — MCP server exposes every command over one handshake, one schema. Large outputs stream to disk; 300 MB+ bundles do not exhaust a context window.
Repositories
- droidsaw — unified CLI, MCP server, cross-layer orchestration
- droidsaw-apk — APK container parser, signing, crypto, YARA, SBOM
- droidsaw-dex — DEX bytecode decompiler
- droidsaw-hermes — Hermes bytecode decompiler
- droidsaw-common — Finding model, graph algorithms, encoding, entropy
- droidsaw-lean — Lean 4 proofs of decompiler invariants (parser totality, dominators, lattice monotonicity, RPO ordering)
All BSD-3-Clause.
