Measure the toolkit on a real Flutter target and correct what it claimed

Ran the scripts against a real Flutter AOT / multi-dex / 36-.so APK (Dart 3.6.0,
com.tingfeng.tool) and recorded what each one actually did. Two of them were wrong
in the direction that reads as a target finding, one Coverage claim overstated what
ships, and four documentation statements were false.

Fixed:

  dart_pprefs.py decoded only the general-purpose register file, so `ldr dN,[x27,#imm]`
  (0xFD400000) was never matched and every double constant read from the object pool
  was dropped -- 302 pool offsets and 1802 sites on this sample, one of them with 150
  references that would have been reported as zero. The documented advice is to count
  references before editing a shared constant, so a one-sided quiet gap here produces
  exactly the wrong decision. Now covers both register files; a purpose-written
  arbiter agrees with it to 0/0 across .text, against 0/302 before.

Documented but deliberately not fixed, because a fix would not have been run:

  elf_plt.py misses the last PLT stub slot (`off < fsz - 16`), which on libloader.so
  turned a real, called import (dl_iterate_phdr) into "not a resolved stub".
  find_refs.py advertises dex-directory input but iter_files() accepts only .smali,
  so it answers "no references" with exit 0 for input it never read.
  so_constpatch.py's rebuild drops the zip `extra` field and destroys 4 KB alignment.
  Each has its root cause and fix sketch recorded.

Documentation corrections in dart-aot.md:

  blutter's asm/ does contain full instruction listings with pool annotations -- the
  file said to ignore it, and it is the richest artifact in the chain.
  The first build costs ~78 s, not "tens of minutes"; MSVC 19.34 suffices, not VS 2022.
  The file-PP offset mapping is not recoverable from the binary (4241 shared strings,
  4237 distinct deltas), so a snapshot-decoding front end is a dependency, now stated.
  Documented aotopsy as the no-toolchain route, and the trap that its version label is
  a structural profile name (it says 3.6.2 for a 3.6.0 snapshot).

Coverage now separates what was measured from what is inferred, names blutter/aotopsy
as a prerequisite instead of implying the pool decodes itself, lists the scripts this
pass did not run, and says plainly that the packer / VMP / integrity-check scenarios
were not exercised at all.

Added hand-off points for JNI, dex-observed hardening, and the existing native boundary
documents, plus docs/verification-jiongnew/ -- the evidence record, including the four
gate outputs verbatim. No second skill: the gap is one front-end dependency, not a
subject area, and relocating Flutter docs would not have supplied it.
This commit is contained in:
inliver233 committed 2026-09-20 04:59:38 +08:00
1 parent 46812ec9a4
commit e193f425ba
10 files changed
+1565 -32

No files matched your search

+80 -3
View File
@@ -73,11 +73,33 @@ vocabulary and a set of reassuring numbers.
- The native layer: `.so` hosts, tamper-triggered self-termination, forged ELF structure, and
neutralising a terminate path without freezing the process (`native-and-so.md`,
`native-tamper-and-suicide.md`).
- Flutter / Dart AOT: pinning the engine version, decoding the object pool, locating and patching
business logic inside `libapp.so` (`dart-aot.md`).
- Flutter / Dart AOT: analysing and patching `libapp.so` **given a snapshot dump** — pool-reference
counting, disassembly windows, caller indexing, patch-site choice (`dart-aot.md`). Measured on a
real Dart 3.6.0 build: `dart_disasm.py` decoded identically to capstone (32/32 and 96/96), the
caller index re-derived independently with a symmetric difference of 0, and a specific business
logic site was located end to end. **The snapshot dump is a dependency, not a detail** — see the
next section.
- Runtime analysis with Frida, server-side API probing, feature-scoped TLS failures, update and
forced-upgrade neutralisation, and the verification discipline everything above rests on.
**Dependencies this skill does not ship — name them before the workflow starts:**
- **Dart AOT analysis needs a snapshot dump.** `dart-aot.md`'s workflow begins at `pp.txt`; producing
it requires a snapshot container resolver that this skill does not contain and cannot synthesize.
`dart_pool_strings.py` reports **file** offsets while `pp.txt` and `dart_pprefs.py` speak in **pool**
offsets, and the mapping between those two spaces is not a constant: over the 4,241 strings present
in both, a measured run found 4,237 distinct deltas. Ship a pinned front end (aotopsy — pure Go, no
toolchain) or build blutter (~80 s, needs a C++ toolchain). **Say which one you are using and why,
because the two report different Dart version labels for the same binary.** Do not describe the
object pool as something this skill decodes on its own.
**How strong these claims are:** the Measured mechanisms below were established by running the
scripts against a real target during the verification pass recorded in
`docs/verification-jiongnew/`. The rest are **inferred** — documented from experience, but the
repository carries no fixture, log or sample that reproduces them (its own `long-task-discipline.md`
reserves *observed* for a claim with an exact command and output behind it). Treat the distinction as
load-bearing rather than cosmetic, and label your own results the same way.
**Not covered — say so rather than improvise:**
- **Unity / IL2CPP logic recovery.** `framework-runtimes.md` identifies the runtime and establishes
@@ -93,6 +115,24 @@ vocabulary and a set of reassuring numbers.
cost and often concludes "switch to static"; it is not a catalogue of evasion for every detector
you might meet.
**Not exercised by the verification pass — do not read silence as support:** the packer, code
virtualization, custom-linker, integrity-check-redirection and tamper-triggered-suicide scenarios
were **not run** against the verification target, because that target has none of those features (no
packer, no integrity checker, ordinary application class) and its unmodified build already fails to
start, which removes the repack-and-regress loop those scenarios need. Nothing in
`docs/verification-jiongnew/` is evidence either way about them. If you use those documents, the
claims are still on the inferred footing described above.
**Scripts this pass did not run** — so they carry no measurement at all, and any conclusion drawn
from them should be labelled accordingly: `native_crash.py`, `apk_diff.py`, `snap.py`,
`grab_crash.py`, `install_test.py`, `repack.py`, `dex_patch_bytes.py`, `dex_find_insn.py`,
`dex_check_verifier.py`, `dex_classdiff.py`, `dex_strpatch.py`, `patch_smali.py`, `smtool.py`,
`datastore_inject.py`, `probe_api.py`, `run_probe.py`, `tls_check.py`, `usb_net_proxy.py`,
`devsh.py`, and the `dexpatch/` java rewriter. Their absence from the record is not a verdict on
them. Note in particular that `grab_crash.py` claims to recover stacks hidden by a crash-reporter
SDK — the exact situation the verification target presented — and was not tried, so that claim
remains **unverified** and the pass used a purpose-written Frida probe instead.
**The fallback, as an instruction:** if the target does not match that list, or no symptom-index row
matches, **stop and classify before choosing a branch.** Answer the thirteen questions first. If the
shape still does not fit — an unknown runtime, a mechanism you cannot name — say exactly that, and
@@ -100,6 +140,41 @@ propose the cheapest experiment that would identify it, rather than taking the c
route and applying it anyway. A wrong branch here does not fail loudly: it produces an artifact that
builds, runs, and does the wrong thing.
## Hand-off points — where this skill ends and another view begins
Three boundaries that are easy to walk into without noticing. Each names what the other side owns,
rather than restating it, because two copies of the same advice drift apart.
**1. JNI — a Java `native` declaration and its implementation are two different views of one function.**
This skill reads the Java side (dex) and the native side (`.so`) with different tools, so the join is
where analyses go wrong.
| Form | What you see | How to find it |
|---|---|---|
| Static linkage | symbol `Java_<pkg>_<Class>_<method>` in `.dynsym` | search the dynamic symbol table. Under R8 the class name is a short name, so the symbol deforms with it and a search for the readable original finds nothing |
| Dynamic registration | **nothing** in the symbol table — binding happens at runtime | find `RegisterNatives` call sites, or hook it to read the binding table. Obfuscated targets prefer this, and a symbol search fails **silently** on it |
| Native → Java callbacks | native code pulling data back through Java | follow `FindClass` / `GetMethodID` / `CallObjectMethod` |
`FindClass`/`RegisterNatives` in a `.so` tell you a JNI boundary exists even when no
`Java_*` symbol does. **Strength note:** the three rows above are documented behaviour, not results
from the verification pass, which did not trace a JNI boundary end to end; `FlutterJNI.loadLibrary`
appearing in a dex is the closest it came. Treat them as a map, not as a measurement.
**2. Hardening — a dex-side packer observation is a native-side implementation question.** If the dex
turns out to be a shell, the logic is behind a loader, and the analysis moves to the `.so` that
performs the unpacking. `packers.md` owns the dex-side identification; the native deep dive belongs on
the other side of this boundary. **Not exercised by the verification pass** — that target had no
packer, so this pointer carries no measurement.
**3. The existing native boundaries — read native anomalies from the APK side, not from inside.**
`native-and-so.md` and `native-tamper-and-suicide.md` are deliberately scoped to what you can conclude
*from the APK side*: a repacked build that dies instantly with a null-looking fault, a Java-layer
check that reports success while the process dies, a terminate path you made not-return. That
judgement belongs here, because it is about deciding whether your *patch* caused the death. Deep
native work — restoring a symbol, rebuilding a call graph, reversing an OLLVM function — is a
different activity with a different toolchain. Point across rather than duplicating: if you need the
latter, say so instead of extending these two files into it.
## Symptom index — a matching row is a stop signal
You arrive at a symptom, not at a file name. Each row below is a failure that has already been paid
@@ -111,7 +186,9 @@ unread in this repository.
| What you observe | Load first |
|---|---|
| A repackaged/re-signed build **dies before your code runs**; `SIGSEGV`, all registers zero, `pc=0`, `fault addr` near `0x0` | `native-tamper-and-suicide.md` (deliberate crash), then `code-virtualization-and-custom-linkers.md` |
| **No packer** (Application is the app's own, dex readable) **and it still dies** | `code-virtualization-and-custom-linkers.md` |
| **No packer** (Application is the app's own, dex readable) **and it still dies** | `code-virtualization-and-custom-linkers.md` §a loader is still a possibility; but if the same build also dies on a *second, unrelated* device you are looking at an ordinary startup fault, not a hardened one |
| The app dies at startup on **every** device, packed or not, **and there is no tombstone** while `crash_dump` reports `already traced` and logcat says `exited cleanly (0)` | the target's launch section in the verification record under `docs/verification-jiongnew/` — a bundled crash reporter (Sentry NDK) has taken the signal handlers, so the platform's own evidence trail is gone. Frida spawn-gating is the recovery route; it needs a working frida-server, which a disguised one may not be |
| A `FORTIFY: pthread_mutex_lock called on a destroyed mutex` abort in a Flutter app, on the **main** thread, before the first frame completes | `dart-aot.md` — check `libapp.so` is actually being loaded; Flutter's engine bootstrap is the usual place a native lifecycle fault surfaces |
| Log says a **Java-layer** signature/integrity check **passed**, yet the process dies | `code-virtualization-and-custom-linkers.md` §a Java-layer "signature killer" is a decoy |
| Deleting a library fixes validation but yields `UnsatisfiedLinkError: dlopen failed: library "X" not found` | `code-virtualization-and-custom-linkers.md` §the deadlock that eats hours |
| Whole classes appear as bare `native` declarations with no body | `code-virtualization-and-custom-linkers.md` |
+82 -19
View File
@@ -26,37 +26,77 @@ engine build id in `libflutter.so`'s version string.
## 2. Get a decompiler that matches that version
**blutter** is the practical choice for Android `libapp.so` (arm64). It reconstructs the object pool
and per-class declarations. It is a *source tree you build*, not a binary you download — and its
prebuilt outputs only cover the Dart versions someone already built.
You need a tool that resolves the snapshot container — something that turns `libapp.so` into named
functions, class layouts and, above all, a **pool listing with `pp+0x…` offsets**. Everything in §4
onward consumes that listing; without it the workflow cannot start, and no script in this skill can
produce it (see §4 for why the mapping is not recoverable from the binary alone).
The version question is the first obstacle, and it has a clean answer:
Two routes exist. Pick deliberately, because their version reporting differs.
**Route A — aotopsy: no toolchain, run it now.** A single static binary (pure Go) that parses the
snapshot binary format directly, with no Dart VM and no SDK compile. On a real Dart 3.6.0
`libapp.so` the full pipeline ran out of the box: 30,586 functions, 6,133 class layouts, 39,202 pool
entries (38,274 resolved), 175,120 call edges with 95.7% of indirect sites annotated, plus
`functions.jsonl`, `call_edges.jsonl`, `classes.jsonl`, `string_refs.jsonl`,
`dispatch_table.jsonl` and an annotated `asm/` tree. It also supports x86_64, which blutter does not.
Its `doctor` subcommand reports a Dart version that is a **structural profile label, not the SDK
version**: on the sample above it printed `3.6.2` while the engine banner, the snapshot hash and a
byte search all said `3.6.0`, and no `3.6.2` byte sequence existed in either `.so`. That matters only
if you feed the number to a VM-compiling tool — use §1's banner for that. Its own README states the
detection is structure-based, so expect the label to name the newest matching profile rather than the
compiler's version.
**Route B — blutter: full fidelity, needs a build.** It embeds a matching Dart VM and deserializes
through the VM's own code paths, which yields the canonical `pp.txt` in the `pp+0x…` space. It is a
*source tree you build*, not a binary you download: its `bin/` is gitignored and it publishes no
release artifacts, so there is nothing prebuilt to fetch for a given Dart version.
- blutter's git HEAD typically supports newer Dart than its shipped `dartsdk/` directory.
- When the target's version is missing, blutter fetches it itself: it sparse-clones
`dart-lang/sdk` at that version tag (only `runtime`, `tools`, `third_party/double-conversion`),
generates a source list, and builds a `dartvm` static library for the target ABI.
- That build needs a real toolchain: `cmake` (>=3.20 is fine, including 4.x), `ninja`, `git`, and a
C++ compiler with C++20 `<format>` support (VS 2022 on Windows, gcc>=13 / clang>=16 elsewhere).
A `vcvars64`-style environment must be active before the build, and `CMakeLists` in the tree pins
`cmake_minimum_required(3.20)`.
- Budget **tens of minutes** for the first build of a new version and run it as a background job;
the compiler log is enormous (per-file include trees), so read only its tail.
- That build needs `cmake` (>=3.20 is fine, including 4.x), `ninja`, `git`, and a C++ compiler with
C++20 `<format>` support. The documented VS 2022 requirement is **over-strict** — MSVC 19.34
(VS 17.4.3, Nov 2022) compiles and runs the `std::format` path, measured. A `vcvars64`-style
environment must be active, and `CMakeLists` pins `cmake_minimum_required(3.20)`.
- Budget a **couple of minutes**, not "tens of minutes": the whole pipeline (clone, `init_env_win.py`,
sparse SDK clone, cmake, nja, link) measured **≈78 s** wall clock. It uses a unity build via
`dartvm_create_srclist.py`, which is why it is fast. The compiler log is enormous (per-file include
trees), so read only its tail.
- **If the freshly built binary faults immediately** with `0xC0000005` and no output at all, do not
conclude anything about the sample. Relink it (`ninja` in
`build/blutter_dartvm<ver>_<os>_<arch>`) and try again; on the sample above the fault never
reproduced after a relink — including for the unchanged binary — and three subsequent runs each
completed in ~5.9 s. **One retry, then a relink, before you blame the target.**
Outputs of interest:
Outputs of interest (blutter):
| Output | What it gives you | What it does *not* give |
|---|---|---|
| `pp.txt` | every object-pool entry with its `pp+0x…` offset: strings, types, closures, fields, stubs | who references what |
| `objs.txt` | reconstructed object shapes with type annotations | code |
| `asm/` | per-class declarations | **instructions — there are none here** |
| `asm/` | class layouts **and function bodies with full instruction listings**, pool annotations and resolved call targets | a pseudocode-level view |
| `ida_script/`, `blutter_frida.js` | symbol/annotation helpers | a finished analysis |
> `asm/` having one file per (obfuscated) class invites the assumption that it holds disassembly.
> It does not. Do not plan around it.
> `asm/` is the richest artifact in the chain. It is one file per **library URI** (mirroring the
> package path), not per class as its name suggests, and it carries annotated disassembly such as:
>
> ```
> // 0x923b3c: r0 = LinkedHashMap.from()
> // 0x923b3c: bl #0x60165c ; [dart:collection] LinkedHashMap::LinkedHashMap.from
> ```
>
> An earlier revision of this file claimed `asm/` contained no instructions and told the reader to
> ignore it. That was wrong and cost real time — plan around `asm/` as your primary annotated
> disassembly source.
**`product` builds carry no debug info.** Expect `no-code_comments`, no function names, and
obfuscated identifiers. That is normal; the strings still survive (see §7).
obfuscated identifiers. That is normal; the strings still survive (see §7). Note this is a *format*
floor, not a tooling gap: the Dart compiler drops field names outside debug builds, so roughly
97-99% of instance field names are simply absent, and local/captured variable names are gone
entirely. Accessor-based recovery (`get:`/`set:` still carry the name) recovers part of the field
picture; the rest should be rendered as unknown rather than guessed.
## 3. The object pool is the whole game
@@ -72,6 +112,13 @@ Two offset spaces exist and they are **not the same number** — mixing them was
Keep the mapping explicit in your notes. When a tool reports "this string is at X", state which
space X is in.
**There is no constant between the two spaces — do not go looking for one.** The relationship is a
property of the *reconstructed* pool, not of the file, so it cannot be computed from `libapp.so`
alone. Measured over the 4,241 strings that appear in both the string table and `pp.txt`, there were
**4,237 distinct deltas** (range −1,361,429 to +277,654). A string recovered by file offset therefore
does not lead to its pool offset, which is exactly why §2 insists on a snapshot-decoding front end:
it is what gives you the `pp+0x…` space in the first place.
## 4. Build your own reference index (blutter will not give you this)
`pp.txt` tells you what is in the pool. To *find the code that uses it* you need pool-offset →
@@ -84,10 +131,26 @@ python dart_pprefs.py --lookup pp_refs.json 0x1d1a8 0xc9d0
**Do not build this index with a full-capstone pass.** Decoding every instruction of a multi-MB
`.text` with `detail=True` and querying `regs_access()` per instruction costs minutes of CPU and
1–2 GB of peak memory, and on a 16 GB host it presents as a hang with no progress output. Only three
encodings can read the pool, so decode them from the raw 32-bit words instead — the shipped script
does exactly that and finishes in seconds. The same argument applies to building a call graph
(§9): decode `B`/`BL` arithmetically.
1–2 GB of peak memory, and on a 16 GB host it presents as a hang with no progress output. Only a
handful of encodings can read the pool, so decode them from the raw 32-bit words instead — the
shipped script does exactly that and finishes in seconds.
**But do not fall back to a linear capstone sweep either.** A Dart AOT `.text` begins with snapshot
metadata, not instructions — on a real `libapp.so` the section started at `0x4a0000` while the first
Dart function prologue (`stp x29, x30, [sp, #-imm]!`) was at `0x4b143c`. A linear sweep starting at
offset 0 dies on that metadata and returns **zero instructions**, which looks exactly like "this
library has no code". If you need capstone here, start at a known function address, or use
`skipdata=True`, and treat an implausibly small count as a decoding problem before you treat it as a
property of the file.
The same mask-based argument applies to building a call graph (§9): decode `B`/`BL` arithmetically
rather than by sweeping.
**A live example of why the index's completeness matters:** after this file's advice to "count the
references before editing a shared constant", one pool offset measured `[0 refs]` with the shipped
script and `[79 refs]` once a missing load family was added to the scanner. A one-sided quiet gap in
the scan reads as "nothing uses this", which is the answer that gets a shared constant edited
carelessly. If a count looks surprisingly low, suspect the scanner before believing the pool.
## 5. What the registers mean
+22 -9
View File
@@ -18,8 +18,16 @@ seconds, and a flat memory profile.
Recognised forms (AArch64, little endian), with x27 = pool base:
add xD, x27, #imm12, lsl #12 -> xD = x27 + (imm12 << 12)
ldr xD, [xN, #imm12 * 8] -> 64-bit or 32-bit variant
ldur xD, [xN, #simm9] -> 64-bit or 32-bit variant
ldr XD, [xN, #imm12 * size] -> GP register file, size from bits 31-30
ldr DD, [xN, #imm12 * size] -> SIMD&FP register file (bit 26 set)
ldur XD/DD, [xN, #simm9] -> unscaled variant, both files
Both register files must be covered. Restricting the LDR form to the GP words
(0xF94/0xB94) silently drops `ldr dN, [x27, #imm]` (0xFD400000), which is how every
*double* constant in the pool is read -- an entire class of references disappears from
the index. On a real Dart 3.6.0 libapp.so that was 302 pool offsets and 1,802 sites lost
(measured, see the verification record); one of them had 150 reference sites that would
all have been reported as zero.
A reference is either a direct load whose base is x27, or a load consuming the register an
ADD just derived from x27. The compiler emits that pair back to back, so a small window
@@ -93,16 +101,21 @@ def scan(text_addr, blob, window):
pending[w & 0x1F] = [imm << 12, i]
continue
ldr64 = w & 0xFFC00000 == 0xF9400000
ldr32 = w & 0xFFC00000 == 0xB9400000
ldur64 = w & 0xFFE00C00 == 0xF8400000
ldur32 = w & 0xFFE00C00 == 0xB8400000
# LDR (immediate) / LDUR across BOTH register files. Bits 31-30 give the access
# size and therefore the immediate scale; bit 26 selects the SIMD&FP file.
# Matching only the GP words (0xF94/0xB94) drops `ldr dN, [x27, #imm]`
# (0xFD400000) and with it every double constant read from the pool.
ldr_scale = {0xF9400000: 3, 0xB9400000: 2, 0x79400000: 1, 0x39400000: 0,
0xFD400000: 3, 0xBD400000: 2, 0x7D400000: 1, 0x3DC00000: 4,
}.get(w & 0xFFC00000)
ldur = (w & 0xFFE00C00) in (0xF8400000, 0xB8400000, 0x78400000, 0x38400000,
0xFC400000, 0xBC400000, 0x7C400000, 0x3C400000)
if ldr64 or ldr32 or ldur64 or ldur32:
if ldr_scale is not None or ldur:
rn = (w >> 5) & 0x1F
rd = w & 0x1F
if ldr64 or ldr32:
disp = ((w >> 10) & 0xFFF) << 3
if ldr_scale is not None:
disp = ((w >> 10) & 0xFFF) << ldr_scale
else:
disp = sx((w >> 12) & 0x1FF, 9)
if rn == POOL_REG: