Repository navigation
Description
Problem
Dart AOT does not maintain a stable ABI. Across minor Dart and Flutter releases, the VM changes snapshot magic hashes, Class IDs (CIDs), struct field offsets, and occasionally the underlying clustered serialization algorithms and reference encoding formats.
Attempting to address this by releasing a full flutterdec binary per Flutter/Dart version is unmaintainable:
- Release explosion: Rebuilding and maintaining 100+ full decompiler binaries across release matrices.
- Maintenance overhead: Bug fixes in ARM64 disassembly, IR generation, CFG structuring, or pseudocode lifting would require backporting to dozens of version branches.
- Misalignment with tool architecture: >90% of
flutterdec(instruction decoding, LLIR, CFG structuring, expression lifters, quality gates, and export script emitters) is Dart-version-agnostic.
Conversely, relying exclusively on static layout tables (data/dart-profiles.json) only solves identification and static field offsets; it cannot deserialize snapshots when cluster encoding formats or serializer logic evolve in new Dart VM generations.
Proposed Solution
Maintain a single, unified flutterdec core binary and decouple snapshot parsing into independently versioned parser adapters keyed by snapshot hash.
[Target Binary (libapp.so)]
│
├──> flutterdec Loader (Extracts 32-byte Snapshot Hash)
│
├──> Exact Adapter Resolution (`dart_adapter_<hash>`)
│ ├── Exact Hash Match --> Executes dedicated parser backend (Serwalker / r2flutter / compiled parser)
│ └── Unmapped / Beta --> Verified fallback or graceful degradation to instruction carving
│
└──> ProgramModel JSON (Schema v3)
│
└──> Unified flutterdec Core Engine (Disasm -> IR -> CFG -> Decompiler)
Key Components
-
Strict Core / Adapter Contract (
ProgramModelSchema v3):- Keep the adapter boundary as a strictly validated JSON contract (
schemas/adapter.schema.json). - The core consumes
ProgramModel(libraries,classes,functions,object_pool,pool_geometry) without embedding Dart VM version-specific C++ headers.
- Keep the adapter boundary as a strictly validated JSON contract (
-
CI-Driven Adapter & Profile Harvesting:
- Implement automated CI jobs tracking the official Dart SDK repository.
- For each new Dart release/tag:
- Extract the 32-byte snapshot hash, CIDs, and struct layout constants into
data/dart-profiles.json. - Build and package the corresponding lightweight parser adapter artifact.
- Extract the 32-byte snapshot hash, CIDs, and struct layout constants into
- Publish signed adapter artifacts that can be installed via CLI:
flutterdec adapter install --dart-hash <HASH>
-
Safe Fallback & Graceful Degradation Policy:
- Exact match by default: Require exact snapshot hash matching for high-confidence deserialization.
- Opt-in family compatibility: Allow experimental fallback to a tested family profile only when strict invariant checks pass (e.g., valid entry VAs, bounded pool indices, non-corrupted string tables).
- Graceful fallback: If a snapshot format is unknown or unsupported, degrade cleanly to instruction stream analysis (
isolate_instructions), function prologue recovery, and dispatch table call detection (sel<offset>) rather than failing fatally or emitting plausible-but-hallucinated metadata.
Alternatives Considered
- One full
flutterdecbinary per Flutter version:- Trade-off: High release maintenance burden, broken UX, duplicated build artifacts for components that never change between Dart versions.
- Monolithic in-core Rust deserializer:
- Trade-off: Heavy maintenance burden to mirror Dart VM C++ changes in Rust; high risk of silent deserialization breakage when VM serialization internals shift.
Scope and Risks
- Affected crates/modules:
crates/flutterdec-adapter: Adapter registry management, artifact verification, and manifest resolution.adapters/: Reference adapter templates and native backend integrations (Serwalker / r2flutter / blutter).data/dart-profiles.json: Continued profile updates for static identification.- CI / GitHub Actions: Automated scraping and build pipelines for Dart SDK tags.
- Expected impact on performance/quality:
- Zero performance regression on the core disassembly/decompilation pipeline.
- Faster onboarding of new Flutter/Dart versions without binary rebuilds.
- Eliminates false-positive metadata by enforcing strict hash matching and schema validation.
- Test strategy:
- Acceptance tests verifying that fixtures from at least two distinct Dart snapshot families produce valid Schema v3
ProgramModeloutputs. - Test verifying unknown snapshot hashes take the safe fallback path without fabricating metadata.
- Negative test suite ensuring corrupt or mismatched adapter artifacts fail validation gracefully on checksum, snapshot hash, and schema checks.
- Determinism & regression test ensuring existing decompilation golden outputs remain unchanged.
- Acceptance tests verifying that fixtures from at least two distinct Dart snapshot families produce valid Schema v3
Proposed Next Steps
- Formalize the adapter distribution manifest schema (version, snapshot_hash, schema_version, os/arch, checksum).
- Set up automated CI workflows to track new Dart SDK releases and produce layout profiles / adapters.
- Validate Serwalker integration as a primary native snapshot parser backend emitting Schema v3
ProgramModel.
Activity
caverav commentedon Aug 27, 2026
cc @kalixtez
caverav commentedon Aug 28, 2026
Recomendation
This issue identifies the correct architectural boundary: keep one version-independent
flutterdeccore and isolate Dart snapshot parsing behind an adapter boundary.One important refinement: the exact snapshot hash must remain the compatibility key, but it should not automatically define a separate parser implementation or executable. Parser code should be versioned by snapshot grammar family. Layout constants and other data should be versioned by profile. Exact hash records should provide the compatibility evidence connecting them.
The target architecture should be:
Unknown identities must use an explicit machine-code-only fallback. They must never select a parser by proximity, Dart semantic version, filename, or heuristic hash matching.
1. Compatibility identity
The registry should match an exact identity containing:
FullAOT;The Dart snapshot hash is an MD5 digest represented as 32 hexadecimal characters. It is distinct from the snapshot magic number and from the Dart semantic version.
dart_versionandflutter_versionshould remain informational metadata. They must not determine parser compatibility.Dart generates this hash from VM snapshot serializer sources, and the VM performs exact snapshot-version equality checks when loading a snapshot:
A changed hash means that compatibility cannot be assumed. It does not prove that the serialization grammar changed. Conversely, an unchanged or reused profile is not enough to authorize parsing without an exact registry record.
2. Separate parser families, profiles, and compatibility records
These concepts should remain independent.
Parser family
A parser family owns behavior that depends on serialized snapshot grammar:
ReadAllocandReadFill;One parser family may support multiple exact snapshot identities, but only after real fixtures and invariant checks prove that the implementation remains valid.
Data profile
A profile contains data-only layout information:
Profiles should be independently updateable and content-addressed. They should not be compiled into the core with
include_str!; adding or correcting a profile should not require rebuilding the main decompiler.Compatibility record
Every supported hash should have an exact registry record containing:
Multiple exact records may point to the same parser artifact and profile. A new hash therefore does not automatically require a new executable.
The registry is the authority. Adapter output must not be allowed to declare itself authoritative merely by returning a matching hash or an
adapter_kindstring.3. ProgramModel contract
The current Schema v3 contract is too weak for this boundary. Provenance, capabilities, unavailable values, and semantic validation change the meaning of the model, not just its JSON shape.
Because this project is still pre-1.0, a clean ProgramModel v4 cutover is preferable to permanently accepting v2, v3, and v4.
ProgramModel v4 should include:
Placeholder strings must not masquerade as semantic values. For example, an unresolved class, library, owner, or name should be represented as unavailable with a diagnostic, not as an apparent exact name such as
<unresolved ...>.Likewise, heuristic pool information must not be assigned
confidence: 1.0. Use typed provenance such asexact,derived, andheuristic. Numeric confidence should only be added if it has a defined and calibrated meaning.JSON Schema should be generated from canonical Rust DTOs. The schema validates shape; Rust validation must enforce semantic invariants.
Required invariants include:
4. Adapter protocol
A full JSON-RPC protocol is unnecessary for the initial one-process-per-analysis design.
Start with protocol v1:
The host should create private input/output directories for every invocation.
The protocol should not allow an adapter to choose its own compatibility record. The host resolves the exact registry entry first and passes that decision to the adapter.
Add JSON-RPC later only if long-lived adapters, streaming, remote workers, or concurrent calls become real requirements.
Native subprocesses should be the first execution format. In-process shared libraries reduce startup overhead but allow parser bugs to crash or compromise the main process. WASM may be useful later for distributing third-party adapters, but it does not solve grammar classification or compatibility admission and should not block the native design.
5. Adapter containment and artifact verification
Before executing an adapter, the host should verify:
The execution boundary should provide:
Checksums provide integrity, not publisher authenticity. Automatic remote installation should wait until the registry and artifacts support signing, rollback protection, and freeze protection through TUF, Sigstore, or an equivalent mechanism.
Initial distribution should be local/bundled and install-only. Do not add automatic network installation before the trust model is complete.
6. Honest fallback behavior
Unknown or unsupported snapshot identities should not require a fake hash-named adapter.
The fallback may provide:
The fallback must mark these unavailable unless independently recovered:
It must not synthesize values such as:
merely to satisfy a non-empty model check.
This fallback is a useful product behavior, not an adapter failure. It lets unknown versions remain analyzable without emitting plausible but untrusted metadata.
7. Serwalker integration
The current Serwalker work is a good first parser candidate. It already demonstrates several useful properties:
However, it should not be merged with its current core integration shape.
Required changes:
flutterdec-coredependency on the Serwalker crate.AdapterBackend::Internal.Internalfor machine-code-only fallback.The parser must also preserve stream alignment across every snapshot section. In particular, root parsing must consume the initial-field-table and shared-initial-field-table counts and references before continuing to the dispatch table, even if those tables are discarded by the current model.
The object-store layer should remain format-oriented and return references or domain-neutral values. Conversion into
LibraryInfo,ClassInfo, and other ProgramModel types belongs in the model producer layer. A resolver that returnsResult<()>while claiming to resolve object-store state should be replaced with a real state-producing API.Serwalker should become the first external adapter artifact, not define the generic host contract.
8. Other parser backends
r2fluttercan be useful as:Its fingerprint mode must never provide authoritative metadata for an unknown hash.
Blutter can be useful as:
Neither backend should be selected from a substring in
adapter_kind. Backend authority must come from the verified registry record and provenance fields.9. Landing order
The work should land as stacked changes.
PR 1: Semantic contract
Start from
main:SnapshotIdentity;adapter_kind.PR 2: Adapter host and registry
Add:
Do not add automatic network installation yet.
PR 3: Serwalker adapter
After the first two contracts stabilize:
Internal;PR #74 can temporarily target the foundation branch as a stacked PR, but the merge order should remain contract, host/registry, then Serwalker. Building the foundation directly on the current Serwalker branch would mix generic architecture with parser-specific implementation and make the core contract depend on one parser.
PR 4: Grammar-family proof
Add a second exact snapshot identity.
For that identity:
Never infer family compatibility from Dart version proximity.
PR 5: CI and distribution
For every Dart stable or beta candidate:
CI should automate SDK acquisition, identity extraction, profile generation, comparison, and publication. It should not attempt general-purpose C++-to-Rust parser translation; Dart serialization logic is procedural and conditional, not a stable declarative schema.
10. Acceptance gates
Issue #96 should not be considered complete until all of these behaviors are covered:
Final decision
The recommended architecture is:
Reject:
flutterdecbinary per Dart or Flutter version;Recommended first implementation priority:
kalixtez commentedon Aug 28, 2026
Small things to consider:
• There might never be a chance for us to implement a JSON-RPC IPC model for adapters, given the task is not complex enough. Subprocess spawning works and I think will work fine for as long as the project lives.
• For now, we don't really need to use the snapshot kind to key a future profile rwgistry. We assume from the beginning that we are gonna be receiving a FullAOT binary. The other proposed components of the composite key, snapshot and target arch, are very valid and indeed should be implemented in my opinion.
• It is possible don't need to take into consideration alignment details when it comes to specifying a data profile. Dart doesn't insert padding or forces alignment constraints during serialization with the exception of the boundaries between snapshot section such as the clustered stream and the ROData image, where the output stream is aligned to image header-sized values.
fix(serwalker): Implemented reviewer observations: kept lossy strings…