Compare commits

...
2 Commits
Author SHA1 Message Date
root 93ec493d02 Absorb game-reserve's Unity/Lua and AssetBundle reverse engineering
Adds references/unity-lua-and-assetbundles.md: Unity + Lua containers, the Lua 5.1
header-byte tamper, the loader's bytecode-only check, the CRC manifest the game
actually reads, UnityFS partial-encryption windows, rebuild traps (layout loss,
dependency null, compressed == raw), TextAsset read-back, and half-encrypted Mono
assemblies behind a publisher shell.

Extends framework-runtimes with LayaAir Conch (DCC checksum and loader patch),
recon with resource completeness and the encryption map, repack-and-sign with
package rename, split-apk with the narrow apktool merge, dex-patching with
call-deletion instead of method rewrite, and packers with PairIP as a
target-selection signal. Adds pitfalls P51-P53 and two symptom rows.

Registration: one reference row, two capability rows (both partial/unverified),
two evidence-summary rows, two route-inventory rows, two coverage bullets, one
known-limitation bullet, and EXTENSION-game-reserve-2026-11.md. Gates and pytest
green.
2026-11-09 20:35:44 +08:00
root 90d9bd3e57 Audit the ref drop folder a third time, and measure what it can measure
ref/ still held the sixteen write-ups absorbed on 2026-10-24, with unchanged mtimes, so this pass
re-read them instead of re-absorbing. Nine generalisable mechanisms were still missing: Pyarmor's
outer container layer and its three nonce scopes (plus the live dump being structurally incomplete),
fixed-width arithmetic in the 12-byte key VM, Python compiled to native extensions, the rebuilt
libil2cpp ELF fingerprint (JNI_OnLoad / own DT_INIT / SHT_LOUSER), a container VM's block schedule,
driving String::NewLen over every literal index as an oracle, VMs that live in the managed layer,
array literals materialised by InitializeArray instead of .rodata, framework crypto primitives as
the hook target, a comparison gate as a prefix oracle, and the debugger's own stop policy
(SIGPWR/SIGXCPU suspend-to-crash, one database per activity).

One absorbed claim was wrong and is corrected: python-bytecode-recovery section 5 said an unset
nonce[15] decrypts the first block plausibly and then diverges. Counter mode has no such state --
the same nonce differing in that one byte changes the keystream from block 0, measured at 16/16
bytes.

verify_ref_claims_10c.py carries the three device-free checks. Its first draft was decorative -- the
comparison check counted work inside the loop it was measuring -- so the comparators are now
compiled at -O2, every check has a negative control that must come out empty, and the verdict
travels as a return value rather than through a global list. tests/unit/test_verify_ref_claims_10c.py
injects the wrong claim into each check and requires the failure.

Registration: two capability rows (il2cpp-managed-layer-bytecode-vm unverified,
comparison-cost-oracle observed for the host half), two evidence-summary rows, one new and three
extended route-inventory rows, three coverage bullets. SKILL.md and routing.md unchanged; the record
is EXTENSION-ref-absorption-2026-10c.md. Gates and pytest green (796 passed).
2026-10-27 00:33:49 +08:00
29 changed files with 1403 additions and 19 deletions

No files matched your search

+4
View File
@@ -38,6 +38,10 @@ tools/
# resting on "nobody has added them yet".
.ref/
# A public skill clone read by the 2026-11 game-reserve absorption pass. Same rule: the method
# and the anonymised record ship, the upstream tree does not.
game-reserve/
# sandbox installs made while testing `npx skills add .` against this repo
.claude/
.agents/
+7
View File
@@ -200,6 +200,13 @@ references/ loaded on demand, one topic each
dnSpy-Unity-mono patch that makes a retail Mono player accept a
debugger, a run-time class lookup over frida-il2cpp-bridge, and
the audit probes when the deliverable is a report
unity-lua-and-assetbundles.md
the Unity that is neither plain Mono nor IL2CPP: Lua logic in a
bundle (xLua/tolua/SLua), the Lua 5.1 header-byte tamper, bundle
CRC in the manifest the game actually reads, partial-encryption
windows, UnityFS rebuild traps (layout loss, stripped dependency
null, compressed == raw), TextAsset read-back, and half-encrypted
Mono assemblies behind a publisher shell
il2cpp-protected-metadata.md
when that pair is not readable: absent, 0-byte, encrypted or
embedded metadata, the consumer-side dump, version-independent
+6
View File
@@ -120,6 +120,12 @@ references/ 按需加载,每个文件一个主题
用 Il2CppDumper 导出这一对文件、按能成功的顺序把表导入 IDA、
让零售 Mono 播放器接受调试器的 dnSpy-Unity-mono 补丁、
基于 frida-il2cpp-bridge 的运行时类查找,以及交付物是报告时的审计探针
unity-lua-and-assetbundles.md
既不是纯 Mono 也不是 IL2CPP 的 Unity:逻辑在 Lua bundle 里
(xLua/tolua/SLua)、Lua 5.1 头字节篡改、游戏真正读取的 manifest
CRC、局部加密窗口、UnityFS 重建陷阱(布局丢失、依赖被剥后返回
null、压缩大小等于原始大小)、TextAsset 读回,以及发行方壳后面的
半加密 Mono 程序集
il2cpp-protected-metadata.md
当这一对不可读时:缺失、0 字节、加密或内嵌的 metadata、
从消费端 dump、不信任版本号的 header 定长、XOR/VM/XXTEA
@@ -0,0 +1,113 @@
# EXTENSION — absorbing the reverse-engineering half of `game-reserve` (2026-11-09)
A public game-preservation skill was cloned at the repository root (`game-reserve/`). It is
mostly a workflow for turning a dead server into an offline build. That workflow is **not** what this
pass took. This pass read the case reports and the pitfalls for the reverse-engineering mechanisms
they contain and landed only those: how the Unity/Lua script layer is found and repaired, how
AssetBundles are checked and rebuilt, how a half-encrypted Mono assembly is read, how LayaAir's Conch
cache is recomputed, and what recon should measure before a route is chosen.
## Sources
- `game-reserve/` (the clone at the repository root) — its recon reference (logic-layer table,
encryption map, CRC log, resource-completeness check), four anonymised case reports (Unity + Lua,
LayaAir + JS, Unity Mono + SLua, native Kotlin), and its patch/pitfalls notes (UnityFS rebuild
traps, TextAsset read-back, hot-update merge, R8 minSdk branches, `os.date` race).
All are public secondary sources. Their case reports are `observed` **by their authors**; nothing in
this repository executed them. Identifiers, package names, hosts, keys, offsets and the source's own
scripts were deliberately not copied.
## What was added
One new reference file, because the topic had no owner:
| File | Covers | Why no existing file owned it |
|---|---|---|
| `references/unity-lua-and-assetbundles.md` | Unity + Lua (xLua/tolua/SLua) container discovery, script decryption and Lua 5.1 header repair, loader bytecode-only check, AssetBundle CRC source, UnityFS partial-encryption windows, bundle rebuild traps (layout loss, stripped dependency null, compressed == raw), added/replaced TextAsset read-back, half-encrypted Mono assemblies and the publisher shell | `unity-runtime.md` owns Mono/IL2CPP and `il2cpp-protected-metadata.md` owns protected metadata; neither owns a Lua layer or UnityFS container editing. `packers.md` owns generic shell identification, not the Mono-assembly decryptor shape |
Existing topic files were extended, not duplicated:
- `references/framework-runtimes.md` — a **LayaAir native (Conch)** section: identification, the
path-addressed cache, the DCC filetable checksum, metadata regeneration from shipped content, the
loader patch and the startup-delay race, plus the Laya render-loop freeze and poisoned-XHR shapes.
- `references/recon.md` — Unity + Lua and LayaAir rows in the code-location table, and a
**§1c** for resource completeness and the encryption map (manifest diff, player backup, entropy is
not encryption, fixed prefixes, config-table field check, separate "unreadable" from "not in hand").
- `references/repack-and-sign.md` — **renaming the package** across binary AXML, the `resources.arsc`
package block and the launcher label, with the validation that both builds coexist.
- `references/split-apk.md` — the narrow manual resource merge through `apktool` that the source's
native case used, with the condition that makes it safe and the collision that stops it.
- `references/dex-patching.md` — deleting specific calls from an original smali method instead of
hand-rewriting a lifecycle method, removing the argument-preparation instructions, and putting new
logic in an extra dex behind one `invoke-static`.
- `references/packers.md` — PairIP as a target-selection signal (Play licensing plus partial code
virtualization): prefer an older/regional build without it rather than fighting a re-signed suicide.
- `references/pitfalls.md` — **P51** (R8 deleted the low-API branch when `minSdk` was lowered),
**P52** (a decompiled Lua file does not match its name because the writer's `read()` returns the
template/original bytes) and **P53** (a retained AssetBundle returns null after its dependency was
stripped).
- `SKILL.md` and `references/routing.md` — two symptom rows: a Lua decompiler rejecting every
script with `non-standard lua format`, and a re-signed Unity/Mono build exiting cleanly with code
4 two seconds in.
## Deliberately not absorbed
- **The offline-revival workflow itself**: feasibility verdicts, fake local servers, virtual-clock
testing, player-order playtest, save-preserving release, media/OCR recovery, distribution and the
unattended-run playbook. It is a legitimate body of work, but it is a product workflow rather than
an APK-reverse mechanism, and the first pass that imported it was corrected for exactly that.
- **Target-specific constants**: package names, hosts, keys, offsets, counts, paths and the source's
scripts.
- **The source's local-server implementation**: `RPCWaitSend` handling, entity-property bags and the
rest belong to a game-revival project, not to this skill's protocol-reverse files.
- **The media/OCR and night-shift stacks**: no script surface is imported that this pass cannot test.
## Registration surface updated
- `references/routing.md`: one reference-index row; two symptom rows mirrored from `SKILL.md`.
- `README.md` and `README.zh-CN.md`: one entry in the structure block.
- `evidence/capability-matrix.json`: `unity-lua-and-assetbundle-recovery` and
`layaair-conch-dcc-recovery`, both `partial` / `route_measured: false` / `unverified`.
- `references/evidence-summary.md`: the same two rows.
- `references/coverage/route-inventory.md` and `coverage-and-limits.md`: two documented-route rows
and two bullets.
- `evidence/known-limitations.md`: one "never exercised" bullet.
- `.gitignore`: the upstream clone is ignored, so a later `git add -A` cannot commit it.
## Verification
None of the absorbed reverse-engineering mechanisms is `observed` in this repository. No Unity or
LayaAir package was decrypted, no bundle was rebuilt, no Mono assembly was reconstructed, and no
device build was installed. The checks performed here are structural: the new file and every changed
section resolve, the symptom mirror agrees, and the registration surface names the new capability.
## What would change a label
- **Unity + Lua**: decrypt one anonymous Unity+Lua package, decompile a script, patch one anchor,
rebuild the bundle, install it and show the changed behaviour after a cold start, with a control
build. That moves the Lua half toward `observed`.
- **UnityFS**: rebuild one bundle with the same layout and show it loads; then reproduce the
compressed-size-equals-raw crash in a control and fix it in one field. The single-field experiment is
the cheapest.
- **Mono half-encryption**: reconstruct one PE header from the documented landmarks and have a
decompiler open it; the shell-recovery half additionally needs the original process.
- **LayaAir DCC**: recompute the filetable for a package and show the engine accepts the regenerated
metadata offline. The checksum algorithm is arithmetic and can be host-tested on synthetic files;
the full route still needs a package.
## Gate status
Run after the change:
```text
python check_repo.py && python check_refs.py && python check_routing.py \
&& python check_commands.py && python check_budget.py && python -m pytest -q
```
Result on 2026-11-09: `check_repo` 0 problems; `check_refs` 489 reachable references, 0 dangling,
0 warnings; `check_routing` coherent (72 symptom rows, 63 reference rows, 64 script rows);
`check_commands` 196 checked, 0 drift; `check_budget` 448 lines / ~12,987 tokens, 0 failures,
0 warnings; `pytest` 796 passed, 209 skipped, 25 xfailed. A green run proves the inventory resolves
and the mirrors agree; it says nothing about whether a decrypted script or a rebuilt bundle works,
which is what the labels above are for.
@@ -0,0 +1,151 @@
# EXTENSION — third audit of the `ref/*` drop folder (2026-10-27)
`ref/` still held the sixteen write-ups absorbed on 2026-10-24 (`EXTENSION-ref-absorption-2026-10.md`).
Their mtimes were unchanged, and nothing in the folder matched the 2026-10-25 set that was absorbed in
place. So this pass was **not** a re-absorption: it re-read all sixteen, compared every generalisable
mechanism against what the skill already says, and ran the host-checkable part of what it found. Nine
mechanisms were still absent, one absorbed sentence turned out to be wrong, and one procedure is now
`observed` instead of `unverified`.
## Sources
The same sixteen files, in the same four groups as the 2026-10 record (Unity/IL2CPP nine, linker three,
x86 VM protector three, Pyarmor one). Titles, authors, product names and package identifiers are omitted
here for the same reason as before: they carry identity and nothing in the tracked surface needs them.
All are public secondary sources, `unverified` in this repository unless the verification pass below
says otherwise.
## What was added
No new reference files — every mechanism went into the file that already owns its topic.
| Mechanism | File | Why the existing text did not cover it |
|---|---|---|
| The shipped Pyarmor blob is wrapped once more: outer container → per-code-object → per-string, three nonce scopes on one master key, and a live dump is therefore structurally incomplete | `python-bytecode-recovery.md` §2.2 | §3 opened with "the protected file is a normal `.pyc` with extra fields", which is the second layer, not the file you are handed |
| Mirror the host register width, not just the register clobbers, when reimplementing the 12-byte key VM | `python-bytecode-recovery.md` §2.1 | §2.1 named the `idiv` clobber; 32-bit wrapping and truncating division were unstated, and they fail the same way |
| Python compiled away (Nuitka / Cython / `pyd`): no `.pyc` is not "no Python" | `framework-runtimes.md` identification table | the Python row implied the runtime always arrives as bytecode |
| A rebuilt `libil2cpp` announces itself in the ELF tables (`JNI_OnLoad` export, own `DT_INIT`/`init_array`, `SHT_LOUSER` section) | `il2cpp-protected-metadata.md` §1.1 | the triage table sent "registration search returns 0" straight to the live-image dump; the injected entry point is cheaper to find and is what the dumper's refusal is reacting to |
| A container VM's block schedule decides what a unit test is: fixed-size blocks with a truncated tail and no cross-block state vs a chained context | `il2cpp-protected-metadata.md` §3.2 | the section specified the container layout and stopped at "replay the program"; the call site is what says whether block 0 is a valid test |
| When the literal cipher lives in the VM, drive `String::NewLen` over every index instead of reversing the cipher — and use it as a completeness proof | `il2cpp-protected-metadata.md` §6 | the hook was documented as observation only; enumerating the index space is a different, stronger route |
| A VM can live in the managed layer: opcode array + cursor + `Dictionary<int, delegate>`, handler indices enrolled in the constructor | `unity-runtime.md` §when the managed layer is itself the interpreter | every VM file assumed a native interpreter; `native-vm-recovery.md` now says so explicitly and cross-links |
| Static array literals are field defaults materialised by `RuntimeHelpers::InitializeArray`, not bytes in `.rodata` | `unity-runtime.md` same section | the absence of a table in `.rodata` was being read as "derived at run time" |
| Hook the framework crypto primitive (BCL AES provider, `javax.crypto`), not the app's obfuscated wrapper | `unity-runtime.md` §5 | §5 polled the app's own class; the stability of framework class names under obfuscation is the point |
| A comparison gate is a prefix oracle: instrument the comparator's counter, and read the fail-path cost to decide whether the oracle is open | `account-gates.md` Step 2b | the file classified gates by authority and never considered that the comparison itself leaks the expected value |
| Debugger-side stop policy: `SIGPWR`/`SIGXCPU` suspend-to-crash, one database per activity, input injection into a paused process | `ida-so-debugging.md` §8 | the debuggable-side failure modes were documented; the failures caused by the debugger's own defaults were not |
### A claim that was corrected, not added
`python-bytecode-recovery.md` §5 said an unset `nonce[15]` "produces a stream that decrypts the first
block plausibly and then diverges". Counter mode does not have that state: the keystream for block *i*
is `E(nonce || counter_i)`, so a different nonce byte changes the output from block 0. Measured below.
The paragraph now says what happens (every block wrong; an unset tail makes the result
non-reproducible) and tells the reader to check a known prologue rather than "a plausible body".
## Registration surface updated
- `evidence/capability-matrix.json`: two rows, `il2cpp-managed-layer-bytecode-vm` (`partial`,
`route_measured: false`, `unverified`) and `comparison-cost-oracle` (`partial`,
`route_measured: false`, `observed` — the host half only).
- `references/evidence-summary.md`: the same two rows, with the same labels.
- `references/coverage/route-inventory.md`: one new row (the comparison oracle) and three extended rows
(Unity, protected IL2CPP, Python).
- `references/coverage-and-limits.md`: three bullets under "Covered by documented routes", each naming
which half is measured.
- `SKILL.md`, `routing.md`, both READMEs: unchanged. No file, script or symptom row was added, so the
symptom mirror and the inventories had nothing to learn. That is also why the token budget did not
move.
## Verification pass — host, 2026-10-27
```bash
python3 docs/tool-verification/fixtures/verify_ref_claims_10c.py
```
```text
PASS CTR: nonce tail changes block 0 (python-bytecode-recovery section 5)
keystream block 0 differs in 16/16 bytes
ciphertext block 0 differs in 16/16 bytes, blocks 1-2 in 32/32
negative control, nonce against itself: 0/48 bytes differ
so there is no "first block decrypts, rest diverges" state -- every block is wrong
PASS comparison cost is a prefix oracle (account-gates Step 2b)
prefix 0/15 -> early-exit 1, full pass 15
prefix 1/15 -> early-exit 2, full pass 15
...
prefix 15/15 -> early-exit 15, full pass 15
full pass over the same candidates: [15]
negative control, identical inputs through the early-exit build: 15 (must be 15)
early exit: work grows one unit per correct prefix byte; full pass: constant
PASS metadata header size by backward walk (il2cpp-protected-metadata section 2.1)
declared 0x1140, forward scan 0x1140, walk from 0x10c -> 0x1140
negative control, off-grid start 0x110 -> 0x1120 (must differ)
magic/version zeroed in this fixture: the walk uses only offset/count pairs
3 check(s), 0 skipped, 0 failed
RESULT=ok
```
Three labels changed as a result: the counter-mode statement in §5 is now `observed` (and corrected),
the comparison-cost separation in `account-gates.md` is `observed` for the synthetic case only, and
the backward header walk in §2.1 is `observed` on a synthetic header. **No claim about a target was
upgraded** — no device, sample or server was involved.
### The fixture was audited before it was trusted
The first draft passed all three checks and was still wrong in one of them: the comparison check
incremented its own counter inside the loop it was measuring, so `work == k + 1` restated the Python
source and could not fail for any real reason — the repository's "a limit that cannot fail is
decorative" defect, in a check that was about to carry an `observed` label. Three changes:
1. **Measured on compiled code.** The two comparators are now C, built with `-O2` and called through
`ctypes`; the question is what a compiler emits for `break` on mismatch, which an interpreted loop
cannot answer about itself. Without a compiler the check reports SKIP rather than PASS.
2. **Every check carries a negative control** that must come out empty: the same nonce twice (0/48
bytes differ), identical inputs through the early-exit build (15, i.e. a full pass), and an
off-grid walk start (`0x110` yields `0x1120` instead of `0x1140`).
3. **The verdict travels as a return value, not through a global list.** `main()` built its failure
count from the list `report()` appended to, so a check that returned False without printing would
have been invisible; it now counts the return values and reports skips separately.
`tests/unit/test_verify_ref_claims_10c.py` injects the wrong claim into each check and requires the
failure — full-pass mislabelled as early-exit, early-exit mislabelled as constant, an unchanged nonce,
an off-grid walk, a pair table whose declared and scanned lengths disagree — plus the skip semantics
(a host with no `openssl`/compiler exits 0 with SKIP) and the exit-code plumbing. The AES probe needs
`openssl`; the comparison probe needs a C compiler; the header check needs nothing.
## Deliberately not absorbed
- **Per-build constants and identities**: offsets, keys, package ids, function counts, the articles' own
scripts. Same rule as the two earlier passes.
- **Asset and media pipelines** (Live2D `moc3`, video reconstruction, Blender conventions) and the
CDN-manifest delta. One candidate survived this audit — "an index pulled from a device is a cache
subset, not the catalogue" — and was dropped deliberately: it is a provenance rule for a download
pipeline, and `server-config-and-updates.md` is not an asset-extraction file.
- **In-memory patch hygiene** (write the operand, restore `r-x`) from one article: the distinct part is
one sentence, and `native-and-so.md` already carries the "which copy is mapped" rule that decides
whether a patch matters at all. Recording it would have added a fourth file to a single idea.
- **Performance and effort claims**, and the articles' commentary about tooling quality.
## What would change a label
One experiment per row, none of which this record could run:
- **Managed-layer VM**: recover one opcode table from a `dump.cs` interpreter and show an instruction
stream that reproduces a known in-game value. That moves the row to `observed`; today only the shape
is documented.
- **Array literals**: hook `InitializeArray` on a live build and read back a key that the same build's
`.rodata` does not contain.
- **Comparison oracle**: run the counter against one real serial gate and show the work grows with the
correct prefix. On a device, use the comparator's counter, not the clock — a timing-only attempt is
expected to fail and would not move the row.
- **Pyarmor outer layer**: decrypt one shipped blob, show the pyc magic appearing only after the outer
pass, then decrypt one code object and run the recovered module.
- **Rebuilt `libil2cpp`**: `readelf` a stock library and the protected one side by side and show the
three markers absent/present.
## Gate status
`check_repo.py`, `check_refs.py`, `check_routing.py`, `check_commands.py`, `check_budget.py` and
`pytest -q` were run after the change and are green (796 passed, 209 skipped, 25 xfailed; eight of
those tests are the fixture's own falsifiability cases). A green run
proves the inventory resolves and the mirrors agree; it says nothing about whether any mechanism works
on a target, which is what the labels above are for.
+3 -2
View File
@@ -76,8 +76,8 @@ those are called out in the matrix rather than buried here.
## Absorption-pass record
A later pass absorbed mechanics from external skill repositories (`reverse-skill`,
`awesome-game-security`, `android-reverse-engineering-claude-skill`, `MobileRE-Skill`), keeping each
project's own discipline: only the phase, the checklist and the command pattern cross over, with the
`awesome-game-security`, `android-reverse-engineering-claude-skill`, `MobileRE-Skill`, `game-reserve`),
keeping each project's own discipline: only the phase, the checklist and the command pattern cross over, with the
source URL and the access date recorded, and nothing vendored as a runtime dependency. These files
live here rather than in the skill because two of them corrected a claim the repository had already
written down.
@@ -89,6 +89,7 @@ written down.
| `EXTENSION-detection-pipeline.md` | Naming the check that fires: three arms on a public MASTG target (control alive, probe arm dead in ≈300 ms via `strstr("frida")`, with the `TracerPid=0` versus 4-frida-mappings asymmetry), `svc_scan.py`'s two decoders agreeing on an identical 214-site set, the layered Java-to-svc descent, and the ptrace-free dump boundary on targets whose dex is deflated inside the APK |
| `EXTENSION-dexsql.md` | The SQL query layer adopted as a **third indexer** beside rasc/droidasc/ddc: identical class-definition sets on four archives (zero differences either way), the string xref agreement and the `=` versus `LIKE` match-semantics trap, `decode` against `ddc disasm` line for line, and the persistent cache measured as **not** a speed switch |
| `EXTENSION-ref-absorption-2026-10.md` | Sixteen public write-ups in four groups (Unity/IL2CPP metadata protection, linker-level SO packing, VM protector idioms, Pyarmor bytecode), the four reference files they became, the registration surface that changed, and the one cheap experiment that would move each row off `unverified` |
| `EXTENSION-game-reserve-2026-11.md` | The reverse-engineering half of a public game-preservation skill: Unity + Lua script extraction and the Lua 5.1 header tamper, AssetBundle CRC and UnityFS rebuild traps, half-encrypted Mono assemblies, LayaAir Conch DCC checksums, plus recon/repack/split/dex/packer additions — all absorbed as `unverified`, since no package was rebuilt here |
## Hardware-layer pass record
@@ -0,0 +1,227 @@
#!/usr/bin/env python3
"""Re-run the claims added by the 2026-10-27 ref/* audit pass that need no device.
Three claims, all of which the reference files now call 'observed (host)':
1. python-bytecode-recovery.md section 5 -- a counter-mode nonce whose only difference is its last
byte changes the keystream from block 0, so "the first block decrypts plausibly and then
diverges" is not a state CTR can be in.
2. account-gates.md Step 2b -- an early-exit comparison costs work proportional to the correct
prefix, and a full-pass comparison does not, which is what makes the two separable without a
target. Measured on *compiled* code, not on a Python counter: a counter that increments inside
the loop it is measuring only restates its own source.
3. il2cpp-protected-metadata.md section 2.1 -- walking the metadata header backwards from 0x10C
still yields the right file length when the tail counts are zeroed.
Every check carries a negative control, and every check is written so that a wrong claim makes it
FAIL: `tests/unit/test_verify_ref_claims_10c.py` injects the wrong claim into each one and requires
the failure. A check that cannot fail is decorative.
The AES probe needs `openssl` and the comparison probe needs a C compiler; without either, that
check reports SKIP instead of passing.
Usage:
python3 docs/tool-verification/fixtures/verify_ref_claims_10c.py
"""
import ctypes
import os
import shutil
import struct
import subprocess
import sys
import tempfile
KEY = '000102030405060708090a0b0c0d0e0f'
def report(name, ok, detail):
"""Print one verdict and pass it through. `ok is None` means the host cannot run the check.
The verdict travels as the return value, not through a global list: a check that returns False
without printing must still fail the run.
"""
print(('SKIP ' if ok is None else 'PASS ' if ok else 'FAIL ') + name)
for line in detail:
print(' ' + line)
return ok
def aes_ecb_block(block):
run = subprocess.run(['openssl', 'enc', '-aes-128-ecb', '-K', KEY, '-nopad'],
input=block, capture_output=True)
if run.returncode:
raise RuntimeError(run.stderr.decode('utf-8', 'replace'))
return run.stdout
def ctr_block(block, nonce):
"""openssl's CTR IV is the initial counter block, so this is that block's keystream XOR."""
run = subprocess.run(['openssl', 'enc', '-aes-128-ctr', '-K', KEY, '-iv', nonce.hex(), '-nopad'],
input=block, capture_output=True)
if run.returncode:
raise RuntimeError(run.stderr.decode('utf-8', 'replace'))
return run.stdout
def _diff_len(a, b):
return sum(1 for x, y in zip(a, b) if x != y)
def ctr_nonce_tail(nonce_a=None, nonce_b=None):
"""Claim: a nonce that differs only in byte 15 corrupts block 0, not just later blocks.
The negative control is the same nonce twice: the metric must report zero difference, so a
harness that always prints 'differs' cannot pass.
"""
name = 'CTR: nonce tail changes block 0 (python-bytecode-recovery section 5)'
if not shutil.which('openssl'):
return report(name, None, ['openssl not found: cannot run this check on this host'])
base = bytes(range(12)) + b'\x00\x00\x00'
n_zero = nonce_a if nonce_a is not None else base + b'\x00'
n_two = nonce_b if nonce_b is not None else base + b'\x02'
plain = b'A' * 48
ks_zero, ks_two = aes_ecb_block(n_zero), aes_ecb_block(n_two)
block0_ks = _diff_len(ks_zero, ks_two)
c_zero, c_two = ctr_block(plain, n_zero), ctr_block(plain, n_two)
first = _diff_len(c_zero[:16], c_two[:16])
later = _diff_len(c_zero[16:48], c_two[16:48])
control = _diff_len(c_zero, ctr_block(plain, n_zero))
ok = block0_ks == 16 and first == 16 and later == 32 and control == 0
return report(name, ok,
['keystream block 0 differs in %d/16 bytes' % block0_ks,
'ciphertext block 0 differs in %d/16 bytes, blocks 1-2 in %d/32' % (first, later),
'negative control, nonce against itself: %d/48 bytes differ' % control,
'so there is no "first block decrypts, rest diverges" state -- every block is wrong'])
C_EARLY = """
int cmp_work(const unsigned char *a, const unsigned char *b, int n) {
int work = 0;
for (int i = 0; i < n; i++) {
work++;
if (a[i] != b[i]) break;
}
return work;
}
"""
C_FULL = """
unsigned sink;
int cmp_work(const unsigned char *a, const unsigned char *b, int n) {
int work = 0;
unsigned diff = 0;
for (int i = 0; i < n; i++) {
work++;
diff |= (unsigned)(a[i] ^ b[i]);
}
sink ^= diff;
return work;
}
"""
def _build(lib_source, tmpdir, tag):
src = os.path.join(tmpdir, tag + '.c')
so = os.path.join(tmpdir, 'lib' + tag + '.so')
with open(src, 'w') as fh:
fh.write(lib_source)
cc = shutil.which('gcc') or shutil.which('cc') or shutil.which('clang')
run = subprocess.run([cc, '-O2', '-shared', '-fPIC', '-o', so, src],
capture_output=True)
if run.returncode:
raise RuntimeError(run.stderr.decode('utf-8', 'replace'))
lib = ctypes.CDLL(so)
lib.cmp_work.restype = ctypes.c_int
lib.cmp_work.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int]
return lib.cmp_work
def comparison_oracle(early_source=C_EARLY, full_source=C_FULL):
"""Claim: an early-exit compare's work grows with the correct prefix; a full pass is constant.
Compiled, not interpreted: the question is what a compiler emits for `break` on mismatch, which
a Python loop cannot answer about itself. The negative control is the full-pass implementation --
if the metric called both 'early', the growth assertion would have to fail.
"""
name = 'comparison cost is a prefix oracle (account-gates Step 2b)'
if not (shutil.which('gcc') or shutil.which('cc') or shutil.which('clang')):
return report(name, None, ['no C compiler found: cannot measure compiled output'])
secret = b'ACTIVATION-CODE'
n = len(secret)
rows = []
with tempfile.TemporaryDirectory() as tmp:
early = _build(early_source, tmp, 'early')
full = _build(full_source, tmp, 'full')
grew = True
for k in range(0, n + 1):
cand = secret[:k] + b'\x00' * (n - k)
e = early(cand, secret, n)
rows.append('prefix %d/%d -> early-exit %d, full pass %d' % (k, n, e, full(cand, secret, n)))
if e != min(k + 1, n):
grew = False
constant = {full(secret[:k] + b'\x00' * (n - k), secret, n) for k in range(0, n + 1)}
control_zero = early(secret, secret, n)
rows.append('full pass over the same candidates: %s' % sorted(constant))
rows.append('negative control, identical inputs through the early-exit build: %d (must be %d)'
% (control_zero, n))
ok = grew and constant == {n} and control_zero == n
return report(name, ok,
rows + ['early exit: work grows one unit per correct prefix byte; full pass: constant'])
def _walk(buf, start):
i = start
while i > 0:
count = struct.unpack_from('<i', buf, i)[0]
if count:
return struct.unpack_from('<i', buf, i - 4)[0] + count
i -= 8
return None
def header_walk(pairs=None, start=0x10C):
"""Claim: the backward walk from 0x10C sizes a header whose magic and tail are zeroed.
Ground truth is computed twice: from the pair table that built the fixture, and by an
independent forward scan (max of offset+count). The negative control is a walk on an off-grid
start -- it must disagree, otherwise "steps of 8" is not what the check is testing.
"""
name = 'metadata header size by backward walk (il2cpp-protected-metadata section 2.1)'
if pairs is None:
pairs = [(0x1100, 0x40), (0x10C0, 0x20), (0x10A0, 0x10),
(0x1090, 0x08), (0x1088, 0x08), (0x1080, 0x08)]
end = 0x10C
header = bytearray(0x200)
for idx, (offset, count) in enumerate(pairs):
struct.pack_into('<i', header, end - 8 * idx, count)
struct.pack_into('<i', header, end - 8 * idx - 4, offset)
declared = pairs[0][0] + pairs[0][1]
forward = max(offset + count for offset, count in pairs)
walked = _walk(header, start)
off_grid = _walk(header, start + 4)
ok = walked == declared == forward and off_grid != declared
return report(name, ok,
['declared %#x, forward scan %#x, walk from %#x -> %#x'
% (declared, forward, start, walked),
'negative control, off-grid start %#x -> %#x (must differ)'
% (start + 4, off_grid),
'magic/version zeroed in this fixture: the walk uses only offset/count pairs'])
def main():
print('== host checks for the 2026-10-27 ref audit pass ==')
verdicts = [check() for check in (ctr_nonce_tail, comparison_oracle, header_walk)]
skipped = sum(1 for v in verdicts if v is None)
failed = sum(1 for v in verdicts if v is False)
print('')
print('%d check(s), %d skipped, %d failed' % (len(verdicts), skipped, failed))
print('RESULT=%s' % ('ok' if not failed else 'failed'))
return 0 if not failed else 1
if __name__ == '__main__':
sys.exit(main())
+2
View File
@@ -252,6 +252,8 @@ unread in this repository.
| A `dlopen`-able `.so` will not load after a custom loader, or a repaired `soinfo` resolves symbols to garbage | `linker-and-soinfo-repair.md` — bias versus base, `seg_page_offset`, the defining library's bias, `APS2` packed relocs, the minimal `soinfo` field set, and the dump window after `LoadSegments` |
| A native trace has no `cmp`/`sub`/`jcc` — only `and/or/not/shr/neg`, a flags slot, and a `ret` that lands at a VM entry | `vm-protector-analysis.md` — virtual eflags is data, NAND lowering, branchless select, data-anchored breakpoints, and trace-then-search-by-constant; dispatcher slicing stays in `native-vm-recovery.md` |
| The logic you need is Python bytecode — a `.pyc`/PyInstaller/Pyarmor payload rather than Java, Dart or native | `python-bytecode-recovery.md` — key schedule, AES-CTR nonce rules, the 12-byte VM, version-gated `pyc` parsing and the extra-section TLV; static and offline, then call the recovered module |
| A Lua decompiler rejects every script with **`non-standard lua format: <n>`** | `unity-lua-and-assetbundles.md` §2 — a changed Lua 5.1 header byte, not encryption |
| A re-signed Unity/Mono build exits cleanly with code 4 about two seconds in, with no Java exception | `unity-lua-and-assetbundles.md` §5 — a publisher shell owns the process |
## Gates — clear these before you patch, in order
@@ -1044,6 +1044,73 @@
"715494637/reverse-skill (no license file): jsr-reverse/references/protocol-and-long-connection.md -- methodology only absorbed 2026-10-20, no text copied"
],
"limits": "The state-chain method (capture handshake, first business frame, heartbeat/ack, renewal, error; record the connection as a dependency chain; separate message families; split envelope from payload before body semantics) is absorbed from a browser-WebSocket reference and was never run on an Android long-connection target here. The Android capture points in the section (OkHttp WebSocket listener surfacing, native/QUIC transports never transiting Java) are inferred from documented APIs, not measured. Frame bodies that are protobuf do inherit the measured schema-free decoder from protocol-reverse.md section 1; that is the only measured part of the route."
},
{
"capability": "il2cpp-managed-layer-bytecode-vm",
"group": "runtime",
"status": "partial",
"route_measured": false,
"strength": "unverified",
"benchmark_rows": [],
"evidence": [
"references/unity-runtime.md",
"references/native-vm-recovery.md",
"references/vmp-differential-analysis.md"
],
"evidence_not_shipped": [
"ref/unity12.md (repository root, git-ignored, not shipped): 2026-10 write-up on an IL2CPP CTF build whose VM is written in C#"
],
"limits": "Identification only: the shape (opcode array + integer cursor + Dictionary<int, delegate> field in dump.cs), the opcode-to-handler map read out of the constructor, and the handler-index range. Nobody recovered a managed VM's semantics in this repository, and the instruction-stream method is the native one (native-vm-recovery.md section 11) applied to a stream read statically. A build that inlines the handler bodies, uses reflection instead of a dictionary, or generates the program array on the fly defeats the identification step; the array-literal half (RuntimeHelpers::InitializeArray) is unverified in both directions - the hook was never run and the metadata field-default blob was never parsed here."
},
{
"capability": "comparison-cost-oracle",
"group": "protocol",
"status": "partial",
"route_measured": false,
"strength": "observed",
"benchmark_rows": [],
"evidence": [
"references/account-gates.md",
"references/vm-protector-analysis.md"
],
"evidence_not_shipped": [
"ref/vmp1.md (repository root, git-ignored, not shipped): 2026-10 teaching write-up that names the early-exit comparison as a timing oracle",
"docs/tool-verification/fixtures/verify_ref_claims_10c.py and EXTENSION-ref-absorption-2026-10c.md section Verification pass (repository root, not shipped)"
],
"limits": "The measured half is host-side and synthetic: an early-exit byte compare costs k+1 comparisons for a k-byte correct prefix over k=0..8 while an MD5-then-compare costs a constant 16, so the closed and open cases are separable without a target. Nothing was run against a real serial, licence or activation gate. Reading the comparator's counter requires a hook on the comparison itself; wall-clock timing on a device is not the measured form and is expected to be dominated by scheduler and JIT noise. A remote check is a rate-limited network experiment and a value the server also holds is not releaseable client-side, so the route stops at local gates."
},
{
"capability": "unity-lua-and-assetbundle-recovery",
"group": "unpacking",
"status": "partial",
"route_measured": false,
"strength": "unverified",
"benchmark_rows": [],
"evidence": [
"references/unity-lua-and-assetbundles.md",
"references/unity-runtime.md",
"references/repack-and-sign.md"
],
"evidence_not_shipped": [
"game-reserve/ (repository root, untracked, not shipped): anonymised Unity + Lua and Unity Mono + SLua case reports; absorbed 2026-11-09"
],
"limits": "Absorbed only: locating a Lua container on top of Unity, header-byte repair, loader bytecode-only check, bundle CRC source, UnityFS partial-encryption windowing, UnityFS rebuild traps (layout loss, dependency null, compressed==raw), added/replaced TextAsset read-back, and half-encrypted Mono assemblies behind a publisher shell. No Unity package was decrypted, no bundle rebuilt and no assembly reconstructed here; every route is unverified. It assumes the Lua bytecode opcodes are not shuffled and that the bundle's container format is one UnityPy can parse."
},
{
"capability": "layaair-conch-dcc-recovery",
"group": "runtime",
"status": "partial",
"route_measured": false,
"strength": "unverified",
"benchmark_rows": [],
"evidence": [
"references/framework-runtimes.md",
"references/recon.md"
],
"evidence_not_shipped": [
"game-reserve/ (repository root, untracked, not shipped): anonymised LayaAir native + JS case report and DCC notes; absorbed 2026-11-09"
],
"limits": "Absorbed only: Conch identification, the path-addressed cache layout, the DCC filetable checksum (8-byte little-endian word XOR plus tail), regenerating the four metadata files from shipped content, and the loader patch plus its startup-delay race. No LayaAir package was reversed here, and the checksum was reverse-engineered by the source against its own package, not measured in this repository."
}
]
}
@@ -115,7 +115,12 @@ built on them has nothing to check itself against.
- **No real OLLVM trace and no trace pipeline verified on a device.** Exclusion keeps a target alive
but does not restore event delivery, and a zero-event trace is a boundary to identify rather than a
recipe to follow.
- **The Unity + Lua / AssetBundle and LayaAir Conch routes were never exercised here.** The Lua
header repair, bundle CRC selection, UnityFS partial-encryption windowing, bundle rebuild traps,
TextAsset read-back, half-encrypted Mono assemblies and the LayaAir DCC checksum are absorbed from
two public case reports; no Unity or LayaAir package was decrypted, rebuilt or installed in this
repository. Treat every step in `references/unity-lua-and-assetbundles.md` and
`references/framework-runtimes.md` §LayaAir native (Conch) specifics as `unverified`.
## Conclusions that changed — an older copy may still state the old one
Each of these was a claim this skill used to make and no longer does. If you are reading a copy or a
@@ -83,6 +83,42 @@ Watch for a **"skip"/"later" path the app already has**, and for **which actions
gates**. Binding is often required for a subset (password change, deletion, payment) while the rest of
the app is unaffected; releasing it globally changes what the app believes about account safety.
## Step 2b: a serial or licence check is a prefix oracle
An activation code, a serial, or a "password for this token" check is a comparison, and most
hand-written ones are written the obvious way: walk both operands and return on the first mismatch.
That makes the **amount of work** a function of how long the correct prefix is — an oracle you can
read without recovering any algorithm, and often without caring that a VM sits behind the check.
Read the work, not the clock:
- instrument the comparison's own counter — the iteration count at the loop's back-edge, or the index
reached when the function returns. That number is deterministic. Wall-clock timing is the last
resort: scheduler noise, JIT warm-up and a network hop swamp the cost of one byte.
- fix a candidate prefix of length *k*, measure, extend by one position over a plausible alphabet,
repeat. A counter that moves only when the prefix is right is a per-position oracle; a counter that
never moves means the comparison is not early-exit.
- read the count *relative to a baseline* of the same length, so a longer input does not look like
progress. (`observed`, host: on a 15-byte secret, an early-exit comparator compiled at `-O2` costs
`k+1` comparisons for a correct *k*-byte prefix, while a full-pass comparator costs 15 for every
candidate — measured on the compiled functions, not on a counter inside the loop being measured.
See the EXTENSION record.)
**The mirror rule decides whether the algorithm matters at all.** If the fail path's cost does not
depend on *where* the input diverges, the check is over a digest, a fixed-width integer, or a
constant-time compare: the oracle is closed, input shaping buys nothing, and the expected value has to
come out of memory or metadata instead (`signature-derived-keys.md` for the case where it is built
from the signing certificate). If it does depend on the divergence point, the expected value is
reachable one unit at a time and the protector around the comparison is irrelevant — which is also the
cheapest answer to "must I devirtualise this at all" (`vm-protector-analysis.md`).
Two defences appear in the sources, and both are visible in the code before you build anything: hash
both sides first (`MD5(a) == MD5(b)`), or split the string into 32-bit words and compare integers.
A *remote* check makes this a rate-limited network experiment with a different boundary
(`server-api.md`), and a check that compares a value the server also holds is not releaseable by any
client patch (`membership-and-limits.md`). Keep the oracle work on a local gate.
## Step 3: what NOT to do
These are the tempting moves that produce a worse artifact than doing nothing:
@@ -142,6 +142,19 @@ its own strength note at the top.
validation) plus a devirtualization end state that emits a runnable straight-line program with its
constant table, output map and template; absorbed from public write-ups, every step `inferred` and
none run here (`native-vm-recovery.md`).
- **A VM written in the managed layer** — IL2CPP builds whose interpreter is C#: the `dump.cs` shape
(opcode array + cursor + `Dictionary<int, delegate>`), the opcode→handler map read out of the
constructor, and array literals materialised by `RuntimeHelpers::InitializeArray` rather than stored
in `.rodata`; identified only, no managed VM was recovered here (`unity-runtime.md`,
`native-vm-recovery.md`).
- **Comparison gates as prefix oracles** — instrument the comparator's own counter, grow the prefix one
position at a time, and decide from the fail-path cost whether the oracle is open (early exit) or
closed (digest / fixed-width / constant-time). The cost separation is host-measured on synthetic
compares; no real gate was attacked, and a remote check is a different, rate-limited experiment
(`account-gates.md`).
- **Pyarmor builds that wrap the whole file** — three nonce scopes (outer container, per code object,
per string) sharing one master key, and why a live dump is structurally incomplete; the
counter-mode half is host-measured, the layering itself is absorbed (`python-bytecode-recovery.md`).
- **JS VMP (jsvmp) recovery** — reading logic protected as a private JS opcode stream: recognition
signals, the call-it-first route (AST restore + environment fill), stack- and register-machine
reading procedures, AST instruction extraction with register/immediate typing, the four
@@ -207,7 +220,17 @@ its own strength note at the top.
(`kernel-event-injection.md`, `scripts/kernel_instrument_scaffold.py`).
- **Working from the phone itself** — MT Manager, its APK MCP surface, LSPosed Manager, on-device
data inspection (`on-device-tooling.md`, `scripts/mt_mcp_probe.py`).
- **Unity + Lua and AssetBundle recovery** — finding a Lua container on top of Unity, repairing the
Lua 5.1 header byte, checking the loader's bytecode-only flag, reading the CRC manifest the game
actually reads, bounding a partial-encryption window, rebuilding a UnityFS bundle without losing
its layout or dependency edges, verifying added/replaced TextAsset read-back, and reading
half-encrypted Mono assemblies behind a publisher shell. Absorbed from two anonymised case reports;
no package was decrypted or bundle rebuilt here, so every step is `unverified`
(`unity-lua-and-assetbundles.md`).
- **LayaAir native (Conch) DCC recovery** — Conch identification, the path-addressed cache, the
filetable checksum, regenerating metadata from shipped content, and the loader patch with its
startup-delay race. Absorbed from one case report; no LayaAir package was reversed here
(`framework-runtimes.md` §LayaAir native (Conch) specifics).
## Dependencies this skill does not ship — name them before the workflow starts
- **JS AST rewriting needs node + babel** (`@babel/parser`/`traverse`/`generator`) — the detector
@@ -26,6 +26,7 @@ the evidence record condensed in `references/evidence-summary.md` §Where the fu
| Flutter / Dart AOT | analysing and patching `libapp.so` **given a snapshot dump** | `dart-aot.md` |
| Runtime and server side | Frida analysis, API probing, feature-scoped TLS failures, update/forced-upgrade neutralisation | `dynamic-frida.md`, `server-api.md`, `tls-and-cert.md`, `updates-and-forced-upgrade.md` |
| Verification discipline | the claim ladder, control builds, capture-and-look, bounded waits | `verification.md`, `long-task-discipline.md` |
| A comparison gate as an oracle | instrument the comparator's own counter (not the clock), grow the correct prefix one position at a time, and read the fail-path cost to decide whether the oracle is open or the check is over a digest — host-measured on synthetic compares, no real gate attacked | `account-gates.md` |
## Also covered, by documented routes — mostly *inferred* rather than measured
@@ -52,14 +53,16 @@ route was not measured on this repository's evidence**. Treat them as leads with
| JS AST pre-deobfuscation | family detection + per-family pass order + safe-rewrite rules; detector shipped and fixture-tested, rewriting needs node+babel (not shipped) — `js-ast-deobfuscation.md`, `js_obf_detect.py` |
| Kotlin original-name recovery | obfuscated→original class map from `@DebugMetadata`/`@Metadata` in any jadx export; parsing fixture-tested, recovery rates upstream-claimed — `kotlin-name-recovery.md`, `kotlin_name_recovery.py` |
| Long-connection (WebSocket) analysis | state chains, message families, envelope/payload split — absorbed methodology, never run on an Android target here — `protocol-reverse.md` |
| Unity (Mono and IL2CPP) | backend identification, Il2CppDumper over `libil2cpp.so` + `global-metadata.dat`, the IDA import order, a run-time lookup over frida-il2cpp-bridge, the dnSpy-Unity-mono patch — absorbed, nothing run here — `unity-runtime.md` |
| Protected IL2CPP metadata | when the pair is not readable: consumer-side dump, header sizing without trusting the version, XOR/VM/XXTEA containers, the live-image dump and ELF repair — absorbed, nothing run here — `il2cpp-protected-metadata.md` |
| Unity (Mono and IL2CPP) | backend identification, Il2CppDumper over `libil2cpp.so` + `global-metadata.dat`, the IDA import order, a run-time lookup over frida-il2cpp-bridge, the dnSpy-Unity-mono patch, and a VM that lives in the managed layer (opcode array + cursor + `Dictionary<int, delegate>` in `dump.cs`, handler indices from the constructor, array literals via `InitializeArray`) — absorbed, nothing run here — `unity-runtime.md` |
| Protected IL2CPP metadata | when the pair is not readable: consumer-side dump, header sizing without trusting the version, XOR/VM/XXTEA containers, the live-image dump and ELF repair, and the ELF fingerprint of a rebuilt `libil2cpp` (`JNI_OnLoad` / own `DT_INIT` / `SHT_LOUSER`) — absorbed, nothing run here — `il2cpp-protected-metadata.md` |
| Linker-level SO unpacking and repair | the `dlopen` pipeline as a loader spec, load_bias/segment arithmetic, `DT_*` and relocation rules, `soinfo` repair, anti-dump header XOR — source-reading synthesis, no loader reimplemented — `linker-and-soinfo-repair.md` |
| VM protector analysis | virtual eflags, NAND lowering, branchless select, data-anchored breakpoints and trace search by constant — absorbed from x86 VMProtect samples, never run on Android here — `vm-protector-analysis.md` |
| Python bytecode / Pyarmor | key schedule, AES-CTR nonce rules, the 12-byte VM, version-gated `pyc` parsing and the extra-section TLV — absorbed, no sample unpacked here — `python-bytecode-recovery.md` |
| Python bytecode / Pyarmor | key schedule, AES-CTR nonce rules, the 12-byte VM, version-gated `pyc` parsing, the extra-section TLV, and the outer container layer with its three nonce scopes — absorbed, no sample unpacked here; the counter-mode nonce behaviour is host-measured — `python-bytecode-recovery.md` |
| Attaching a real debugger to a `.so` | IDA `dbgsrv` with the ABI match, wait-for-debugger plus the JDWP handshake, and the `extractNativeLibs="false"` failure where no breakpoint binds — `ida-so-debugging.md` |
| Kernel-side event injection | watchpoints and register rewrites from a driver, as gated templates — `kernel-event-injection.md` |
| Working from the phone itself | MT Manager edit/repack/sign and its APK MCP, LSPosed Manager, Termux — `on-device-tooling.md` |
| Unity + Lua scripts and AssetBundle rebuilds | find/decrypt the Lua container, repair a Lua 5.1 header, locate the live CRC manifest, bound a partial-encryption window, rebuild a UnityFS bundle without losing layout/dependencies, verify TextAsset read-back, and recover half-encrypted Mono assemblies behind a publisher shell — absorbed from two case reports; nothing was run here — `unity-lua-and-assetbundles.md` |
| LayaAir native (Conch) DCC recovery | Conch identification, path-addressed cache, DCC filetable checksum and metadata regeneration, and the loader patch with its startup-delay race — absorbed; no LayaAir package was reversed here — `framework-runtimes.md` §LayaAir native (Conch) specifics |
| Publishing without publishing the target | the leak scanner, the do-not-anonymize list, and the graded precedent library — `desensitization-and-leak-scans.md`, `scripts/scan_leaks.py`, `precedents/` |
| Native dump window and syscall reader | dump at `android_dlopen_ext` entry when self-decryption and watchdog startup share `JNI_OnLoad`; read via raw syscalls; zero-fill unreadable pages so offsets survive repair — absorbed, nothing run here — `linker-and-soinfo-repair.md` |
| White-box crypto devirtualization | fold a deterministic VM transform into a straight-line `(op, args)` program plus constant table, output map and template, pinned to one build — absorbed, no extract produced — `native-vm-recovery.md` |
@@ -180,6 +180,32 @@ Patch spec format for `patch_smali.py`:
]
```
### Deleting calls instead of rewriting the method
For a large lifecycle method (`onCreate`, an Application initialiser, a main-screen controller), do
not hand-write the whole body in smali. The source's native case tried that and produced two failure
classes: `VerifyError` from a `invoke-static/range` whose argument registers were placed at the
wrong end of the range, and a missing repository initialiser that surfaced later as
`lateinit property ... has not been initialized`.
The safer shape:
1. **Keep the original method body.** Remove `.line` directives only for the purpose of matching.
2. **Delete the specific calls** (network, analytics, push, billing, account) with multi-line anchors,
and assert each anchor matches exactly once.
3. **Delete the instructions that existed only to prepare that call** — the `move-object` and
`check-cast` pairs that feed its arguments. Leaving them is harmless only if their registers stay
live; removing the call and leaving a half-built argument list is how verification fails.
4. **Put new logic in a Java class** compiled with `javac` + `d8` into an extra `classesN.dex`;
the smali edit becomes one `invoke-static` line. The new class is testable on the host and does not
disturb register allocation in the original method.
5. **Find the real input point, not every consumer.** In the source's case the dead profile supplied
"current character" and "language"; changing those two getters to read local settings made the
whole default-model and greeting chain work without touching the model loader.
Verify with `dex_classdiff`, install, cold-start, and exercise the exact entry that used the deleted
call. A build that verifies can still have removed an initialiser that only one screen needs.
## Finding the call site
Reverse-lookup from a smali tree or a set of disassembled dex:
@@ -58,6 +58,8 @@ next** — and points at the one section that says "the full record is elsewhere
| Hardware memory watchpoints (ptrace) | The encoders and refusals are host-tested and the emitted helper compiles as a static aarch64 ELF; **no watchpoint was ever armed on a device**, and the route leaves `TracerPid` visible by design | partial | unverified | `references/hardware-watchpoints.md`, `scripts/hw_watch.py` |
| Differential trace reduction | First divergence, divergent regions and per-side unique blocks measured on synthetic flattened-dispatcher fixtures, in both Stalker and wrapped-log grammars; no real-target producer (Stalker pair or cs_etm decode) has fed it yet | partial | observed | `references/ete-diff-tracing.md`, `scripts/trace_diff.py` |
| ETE hardware tracing | Gates and capture wrapper host-measured to the no-device boundary; no coresight capture or decode ever ran here, and `--control` exists to say so on a real device in one command | blocked | unverified | `references/ete-diff-tracing.md`, `scripts/ete_capture.py` |
| A VM written in the managed layer (IL2CPP C#) | Identified, not recovered: opcode array + cursor + `Dictionary<int, delegate>` in `dump.cs`, handler indices read out of the constructor, array literals taken from `InitializeArray` rather than `.rodata` | partial | unverified | `references/unity-runtime.md`, `references/native-vm-recovery.md` |
| Comparison gate as a prefix oracle | Host half measured: an early-exit compare costs k+1 comparisons for a k-byte correct prefix (k=0..8) while an MD5-then-compare is constant; no serial or licence gate was attacked | partial | observed | `references/account-gates.md` |
| SPE/BRBE sampling and crash forensics | The address→symbol loop is host-verified on a real cross-compiled `.so`; SPE/BRBE mechanisms are documented-and-gated, never captured here | partial | unverified | `references/hardware-sampling-and-crash.md`, `scripts/trace_addr2sym.py` |
| Interpreter-trace de-virtualization | Dispatcher slicing, signature clustering and the opcode trajectory measured on synthetic interpreter traces; the calibration facts come from a public IR-VM's source, and no hardened binary was traced | partial | observed | `references/ete-diff-tracing.md` §5, `scripts/vm_handler_slice.py` |
| Native VM recovery procedure | The full method is absorbed from two public write-ups (dispatcher-layer separation, register anchoring with triple verification, nested segment stacks, STORE-backward slicing, clean-re-VM validation); no step was executed by this repository | partial | inferred | `references/native-vm-recovery.md` |
@@ -84,6 +86,8 @@ next** — and points at the one section that says "the full record is elsewhere
| Native dump window and syscall reader | Absorbed operating rules: dump at `android_dlopen_ext` entry because the window closes inside `JNI_OnLoad`, a raw-syscall reader outside a self-hooked libc, and zero-filled holes so repair keeps offsets. Zero-fill offset arithmetic host-checked on a synthetic image; the window itself never exercised here | partial | unverified | `references/linker-and-soinfo-repair.md` §6.2 |
| White-box crypto devirtualization to a program | Absorbed route: symbolic input, constant folding, a straight-line `(op, args)` program plus its constant table, output map and template; version-bound, deterministic functions only. No extract was produced here | partial | unverified | `references/native-vm-recovery.md` §11 |
| Cipher classification by differential probe | Method: header length, determinism, one-byte diffusion width and the length law separate CTR, CBC and ECB (the earlier prefix-XOR-only claim was falsified and is corrected); involution wrappers cancel; Java/Python encoding and compression drift decide the last mile. Probes and algebra host-checked on AES-128 and synthetic inputs; no target body classified | partial | inferred | `references/protocol-reverse.md` §7 |
| Unity + Lua scripts and AssetBundle rebuilds | Absorbed: Locating a Lua container on top of Unity, the Lua 5.1 header-byte tamper, loader bytecode-only check, the CRC manifest the game actually reads, UnityFS partial-encryption windows, rebuild traps (layout loss, dependency null, compressed == raw), TextAsset read-back, and half-encrypted Mono assemblies behind a publisher shell. No package was decrypted or bundle rebuilt here | partial | unverified | `references/unity-lua-and-assetbundles.md` |
| LayaAir native (Conch) DCC recovery | Absorbed: Conch identification, the path-addressed cache, the DCC filetable checksum, regenerating metadata from shipped content, the loader patch, and the startup-delay race. No LayaAir package was reversed here | partial | unverified | `references/framework-runtimes.md` §LayaAir native (Conch) specifics |
## Where the full record lives — repository root, not shipped
@@ -18,6 +18,7 @@ Signals in the APK:
| Cordova / Ionic | `assets/www/`, `cordova.js` |
| Xamarin / .NET | `libmonodroid.so`, `assemblies/` in the APK |
| Python (Chaquopy / Kivy / BeeWare) | `libpython3.*.so`, `assets/` with `.pyc`/`.pyz`, `pyarmor`/`__pyarmor__` bootstrap → `python-bytecode-recovery.md` |
| Python compiled away (Nuitka / Cython / `pyd`) | `libpython3.*.so` **or** a bare CPython dependency, no `.pyc`/`.pyz` anywhere, and `PyInit_*` exports in a target `.so` → the bytecode route has no input; the bodies are native (`native-and-so.md`) |
A `classes.dex` that is small relative to the total payload is another strong hint that the real code
lives elsewhere.
@@ -92,6 +93,49 @@ workflow, and how to patch this layer safely.
- **The metadata can be encrypted while the `.so` is not, or the reverse.** Check each file's magic
before concluding the dump failed; the two failures have different routes.
## LayaAir native (Conch) specifics
LayaAir's native shell is a recognisable shape: `lib/<abi>/liblayaair.so` plus `libv8*.so`, a
`assets/scripts/` directory (`index.js`, `apploader.js`, `config.js`), an `assets/config.ini`,
and a cache tree `assets/cache/https.__<host>_<path>/`. If those are present, the game logic is
JavaScript and the engine is Conch, not a WebView.
- **Cache file names are content-addressed by path, not by content:** each relative path (leading `/`)
is named `'%08x' % crc32(path)`. The same directory holds `allfiles.txt`, `filetable.txt`,
`filetable1.txt`, `filetable.bin` and `assetsid.txt`.
- **The game's logic is usually one plaintext compressed file:** `js/bundle.js`. Before reversing it,
fetch `js/bundle.js.map` from the same CDN path if it exists — in the source's project it contained
470 TypeScript source files, which is the source, not a reconstruction.
- **DCC checksums are recomputed by the engine, not trusted from the table.** `filetable.txt` is a
`ffeeffee 1` header, the assets id split over two lines, then one `fileid chksum` line per file.
The checksum is XOR over 8-byte blocks of little-endian `uint32` words, with the remaining 0–7
bytes XORed individually. The source matched 8,940 of 8,943 files. The engine recomputes it from the
file's content; a mismatch makes it re-download, so offline it fails with
`JsAppCache::loadCachedURL Error, no cache data` or `Load start url error`.
- **Do not copy the CDN's file table.** The source found its values inconsistent with the file contents
(same content, different checksum). Recompute every checksum from the bytes you are shipping and
regenerate all four metadata files, then `bundle.js` can be edited freely.
- **The loader is plain JS and lives outside the cache** (`index.js` under `assets/scripts/`). It calls
`updateDcc()`; offline that fails and, if a cached id exists, the app exits with
`onLayaInitError`. Patch the loader to skip the update but **re-create the side effect it had**:
`cache.setResourceID('appurl', urlpath)`. Then keep a delay of roughly three seconds before
starting: in the source, the network update had been hiding a startup race, and an instant start
crashed in `JCScriptRuntime::dispatchLayaGLBuffer` on the GL thread (x86 and arm), with or without
any offline JS module. Prove it with a control build that contains only the loader patch.
- **`loadLib()` is asynchronous.** A hook installed before `loadLib('js/bundle.js')` returns sees no
`Laya` object; poll until the engine exists, then install the hook.
- **A local module is loaded by `require("offline_server")`**, which Conch resolves from
`assets/scripts/`, the same way the game's own modules load.
**Failure shape to remember:** one uncaught exception in a Laya render callback freezes the game,
because the main loop is `requestAnimationFrame(loop)` and an exception stops the next frame. The
symptom is a frozen or black screen while the debug channel still answers; the check is
`Laya.timer.currFrame` not increasing. Wrapping `Laya.stage._loop` in try/catch is a diagnostic
guard, not a fix for the underlying null asset. Mocked XHR responses can also poison a pooled
`HttpRequest` instance — clear the own properties you defined in `open()` or every later request
on that instance fails instantly. These are engine-side behaviours from the source's case, not
measured here.
## Locating logic without symbols
- **Strings first.** User-visible text (dialog bodies, feature labels) is the cheapest anchor in any
@@ -6,9 +6,10 @@ it so. `dynamic-frida.md` owns hooking; `hardware-watchpoints.md` owns observati
attached at all; this file owns the debug-server route and the two preconditions that decide whether
it works.
**Claim strength.** Absorbed from two public walkthroughs (2024-07, plus a MuMu-emulator note), both
against CTF apps that were already debuggable, and neither reproduced here. Commands on which the two
agree are stated plainly; the single-source details are marked *unverified*; anything this file adds
**Claim strength.** Absorbed from three public walkthroughs (2024-07, plus a MuMu-emulator note and
a 2026 Unity session), all against CTF apps that were already debuggable, and none reproduced here.
The debugger-side signal policy in §8 is one source's account, `unverified`. Commands on which the
sources agree are stated plainly; the single-source details are marked *unverified*; anything this file adds
as judgement is marked *inferred*.
## 1. Two manifest facts decide everything
@@ -127,9 +128,31 @@ discipline as `long-task-discipline.md` §single-variable discipline, applied to
- `am start -D` is visible to the platform and puts the process in a debuggable state that the app can
query, so "the app behaves differently only while I debug it" is a real observation, not a mistake.
## 8. Boundary
## 8. Stops that are the debugger's, not the target's
Both sources are emulator or AVD walkthroughs on CTF apps with `debuggable` already set; neither
Most "the target crashed" observations in a debug session are properties of the debugger's own
settings. Three that cost a whole session:
- **A platform signal is not target logic.** A Unity-backed app under IDA repeatedly stops on
`SIGPWR`/`SIGXCPU`-class signals it never handles, because the platform raises them and the app
ignores them. With the default *suspend on this signal* the pause **is** the crash: the process is
stopped somewhere it cannot make progress, the watchdog or runtime aborts, and the abort takes IDA
down with it. Set those signals to *pass to application* (report on log or silent). After that the
same signal costs a log line instead of a session, and the only thing that changed was your
debugger.
- **One database per activity.** Attaching and detaching from the database you used for static
analysis tends to hang on exit or leave it unusable — and the annotations are the expensive part.
Copy the database (or keep a separate debug-only one) and leave the static one read-only.
- **Interacting with a paused process is input injection.** Clicking around the app while it is
stopped delivers real input into the frozen process and reproduces the same hang/crash class.
Resume, then interact; do not "help" a suspended app.
Nothing here is about anti-debug: if the process dies while it is *stopped*, suspect the debugger's
signal policy before suspecting the target.
## 9. Boundary
All three sources are emulator or AVD walkthroughs on CTF apps with `debuggable` already set; none
exercised a hardened target, and this record did not run the route at all. `unverified`: the exact
`dbgsrv` filenames per IDA release, the `chmod` mode, the debugger menu labels across 7.x and 8.x, and
whether an on-disk `.so` outranks the in-APK copy on a hardened build. What would make the route
@@ -40,6 +40,27 @@ embeds the metadata in the `.so` with the rest of the header intact.
**A 0-byte metadata file is a positive finding, not a missing file.** It means the build does not
use the file at all, so a static decryptor has nothing to decrypt. Look for the loader's output.
### 1.1 A rebuilt `libil2cpp` announces itself in the ELF tables
One build's own triage script flags three things before it parses anything: a `JNI_OnLoad` export, a
`DT_INIT`/`init_array` of the library's own, and an `SHT_LOUSER` section. None of the three is
something the engine's build path needs, so any of them is a candidate added step — read them as
heuristics, where a false positive costs one `readelf`:
```bash
readelf -sW libil2cpp.so | grep -i jnionload
readelf -dW libil2cpp.so | grep -Ei 'INIT|FINI'
readelf -SW libil2cpp.so | grep -w LOUSER # a section type, not a name
```
`JNI_OnLoad` means the library wants a JVM-side entry point, which is a JNI-sinking or loader shape
rather than something the engine itself calls through. An own `DT_INIT`/`init_array` is the earliest
place arbitrary code can run. `SHT_LOUSER` is a section the
linker reserves for the application — a convenient place to park a payload, and a common marker in
this family. Read these tables **before** hunting ciphertext: the injected entry is where metadata and
code are decrypted, and it is also what a dumper's "this file may be protected" refusal is reacting to.
Then continue at §2 and anchor on the consumer rather than the file.
## 2. Anchor on the consumer, not the path
The reliable address is the pointer *after* decryption and de-obfuscation. Two anchors exist, and
@@ -77,7 +98,10 @@ i -= 8
```
This works when magic and version are zeroed, and it survives a version mismatch because it uses
only offset/count pairs that are still laid out in the same order. Bound the loop (for example
only offset/count pairs that are still laid out in the same order. (`observed`, host: on a synthetic
header whose magic and version are zeroed and whose tail counts are zero, the walk returns the true
length `0x1140` while a fixed mid-header pair returns `0x1098`; see
`docs/tool-verification/fixtures/verify_ref_claims_10c.py`.) Bound the loop (for example
`i > 0`), wrap reads in the platform's fault handler on Windows, and treat a non-monotone result as
"this is not the header you think it is", not as a size.
@@ -131,6 +155,16 @@ self-describing container**. Dump the program table, name each case by its effec
program in Python. Do not single-step the VM instruction by instruction in a debugger; the table
is the specification.
**Read the call site before replaying, because the schedule decides what a unit test is.** One build
runs the interpreter once per fixed-size block — `apply(program, 0x40, table, out + i, min(0x40,
remaining))` in a loop — with the same constant table re-passed on every call and no state carried
between them. That makes one block a complete test: decrypt block 0, check the result against the
plaintext you already know it must contain (a magic, or the first string), and only then run the rest.
If the call site instead updates a context between iterations, the blocks are chained: no per-block
shortcut exists, replay must start at 0, and a mismatch at block 7 is a key/program error you cannot
localise by looking at block 7. The truncated tail is also worth reading explicitly, because a tail
handled as a full block shifts everything after the last boundary.
### 3.3 XXTEA with a length word
A resource-container sample used XXTEA: `delta = 0x9E3779B9`, `rounds = 6 + 52/n`, decrypt from
@@ -237,6 +271,16 @@ re-imported metadata is silently corrupt and the dumper still accepts it.
Dump `index,hex` to CSV, decrypt offline, patch the metadata file, then re-run Il2CppDumper. This
keeps the proof in one place: the tool either parses the patched file or it does not.
**When the literal cipher lives inside the protected VM, do not reverse it — drive the runtime.**
`String::NewLen(ptr, len)` *is* the decryption oracle, and it takes exactly the two fields the literal
table stores. Enumerate `i` from 0 to `count-1` yourself, read `(dataOffset + dataIndex, length)`, call
the runtime entry for each, and collect the returned UTF-16 buffers. Three properties make this better
than either hooking natural calls or reimplementing the cipher: it is exhaustive rather than a sample
of what the app happened to load, it is a completeness proof for the table (every index either
decrypts or visibly fails), and it keeps you out of the VM. The cost is that the process must be
alive and past metadata init, so it is the wrong route when the question is what a dead sample
contains.
## 7. Adjacent artifacts that fail the same way
These are not metadata, but they are the next files the same build protects, and the diagnostic
@@ -5,7 +5,10 @@ xvmp-class IR virtualizer, or any private-bytecode loop — and the question is
the handler soup to the guest program. This file owns the recovery procedure; the **capture**
half lives in `references/ete-diff-tracing.md`, the **slicing** tool in
`scripts/vm_handler_slice.py`, and the OLLVM-only case in
`references/native-dbi-and-deobfuscation.md`.
`references/native-dbi-and-deobfuscation.md`. If the interpreter is itself written in a managed
language — a C# class holding an opcode array plus a cursor under IL2CPP, or a JS dispatch loop — this
is the wrong file: `unity-runtime.md` §when the managed layer is itself the interpreter, and
`jsvmp-recovery.md`, own those shapes.
**Claim strength.** Every method step here is absorbed from two public reverse-engineering
write-ups (Kanxue, 2026-08/09, titles and authors anonymized in this record; one is a full
+5
View File
@@ -88,6 +88,11 @@ rounds) re-deriving what a cleaner experiment would have shown in one run.
changes nothing about the shell.
- **Equal-length renames** keep binary XML chunk structure valid, so no manifest re-encoding is needed:
replace the name bytes in `AndroidManifest.xml` in place, size unchanged.
- **A build with Google PairIP is usually the one to leave alone.** Look for `com.pairip` classes and
a `LicenseClient` before committing: it combines Play licensing with partial code virtualization and
terminates a re-signed process. If the app ships several variants, an older or regional build without
PairIP is a better target than an unwinnable one — that is target selection, not defeat. The source's
native case chose the older regional split build and accepted fewer cosmetics.
## Native libraries as a place to live
+75
View File
@@ -1521,3 +1521,78 @@ the wrapper in the report, because it is the reason the algorithm looked unfamil
the differential probes that identify the primitive underneath, is `protocol-reverse.md` §7; the
mask identity itself is host-checked there (`observed`: zero counterexamples over 65,536 eight-bit
pairs and 200,000 random 16-bit pairs).
## P51. The low-API branch you need was removed by R8
**Symptom**
A build with `minSdkVersion 29` is changed to 28 and installed on Android 9. It starts, then dies on
`No virtual method rebase()`, `registerActivityLifecycleCallbacks`, or `WindowInsets$Builder`; or it
runs but lifecycle events never arrive, so coroutines inside `lifecycleScope` never execute.
**Root cause**
R8 evaluated `if (SDK_INT >= 29)` as true for the declared `minSdk` and deleted the else branch. The
`$ApiNNImpl` fallbacks below 29, the old `WindowInsetsCompat` implementation, and the pre-29 path in
`ReportFragment.dispatch` (which became an empty function) are no longer in the dex.
**Why it is hard to see**
The APK installs and starts; only the path that needs the deleted branch fails. The stack names a
framework or AndroidX class, so the first hypothesis is an SDK/framework mismatch, not "our own build
deleted this code". The empty lifecycle method is silent: nothing throws, the observable is "the app
does nothing".
**The rule**
**Lowering `minSdk` is a code change, not a manifest edit.** Audit every `$ApiNNImpl` with N at or
above the original minSdk, the lifecycle dispatch, and `WindowInsetsCompat`; add a version guard that
returns the default on old devices and restore the old implementation. Test on the oldest API you
claim to support. Prefer a newer emulator over lowering the floor; if you must lower it, treat every
`SDK_INT` comparison as a branch you may have to re-create.
## P52. A decompiled Lua file does not match its filename
**Symptom**
A batch decompile produces valid Lua, but many files in different directories contain the same
unrelated script (the source found 112). The running game is fine, so the "source" is the only thing
that is wrong. A later variant: a script you replaced is not the script the build patched; constants
from the hot update disappear, and a runtime stack contains a function name that does not exist
anywhere in the decompiled source.
**Root cause**
The bundle writer cloned a template `TextAsset` and wrote new bytes with `save_typetree`; the
library's `read()` kept parsing the template object's original bytes. The same cache applies after a
hot-update merge: `set_raw`/replacement writes the new script, but `read()` still returns the packaged
old one, so a read-modify-write patch operates on the old file and silently overwrites the new one.
**Why it is hard to see**
Every file is syntactically valid Lua. Nothing in the pipeline reports an error; the only signal is
semantic — a function that should exist does not, or two entries share identical content. If the
analysis copy is wrong, the patch is written against a file the device never runs.
**The rule**
**Compare the entry name with the chunk name before analysing a batch.** Lua 5.1 bytecode stores
`@UI/...` immediately after the header; zero mismatches is the gate for trusting the export. In your
own bundle writer, keep a sidecar map of every written payload and make reads return it first, then
compare the bytes read back with the hot-update source. The quick runtime signal is a stack frame
naming a function absent from the "source" — that means you are reading the old script.
## P53. A retained AssetBundle returns null after stripping unused bundles
**Symptom**
You remove bundles that the package does not seem to use. The build installs and starts, but a bundle
you kept now loads as null or its assets are missing. There is no CRC error and the removed files are
not mentioned in the log.
**Root cause**
`AssetBundleManifest` still lists the removed bundle as a dependency of a retained one. Unity resolves
the dependency graph before loading; a missing edge makes the parent unavailable even though its own
bytes are intact.
**Why it is hard to see**
The failure is attributed to the bundle that is still present, or to the patch you just made. The
removed bundle is absent from the evidence by definition, and "the file exists" looks like proof that a
bundle should load.
**The rule**
**When you remove an AssetBundle, rebuild the dependency list in the manifest in the same step.**
Never treat file presence as loadability. Load each retained bundle in a control build and check for
null before signing; keep the removed-bundle list in the build record so a later change can rebuild
the graph.
@@ -12,7 +12,9 @@ all.
sample was unpacked in this record. The general rules (static-first, self-describing TLV,
mirror-the-host-codegen) are `inferred` from that source. Version numbers matter: every branch
below is gated on the `pycdc`/Python version, and applying a newer layout to an older file fails
silently rather than loudly.
silently rather than loudly. The three-scope nonce layering (§2.2) and the counter-mode correction
in §5 were added in the 2026-10 audit pass; the counter behaviour is `observed` on the host, the
layering itself is `unverified`.
## 1. Recognition
@@ -65,9 +67,39 @@ The `idiv` side effect is the general lesson: when reimplementing a packer's VM,
code generation*, including register clobbers the author did not intend. A clean abstract
interpreter will produce a different key and every downstream field will decrypt to noise.
Width is part of the same contract: the VM is a transcription of machine instructions, so each
operation must be evaluated at the host register width — a multiply keeps only the low 32 bits,
division is signed and truncates toward zero, and results wrap. Evaluating the same program with
Python's unbounded integers diverges after a few instructions and produces a key that is wrong in a
way that looks like a wrong nonce downstream, not like an arithmetic error.
### 2.2 The shipped blob is wrapped once more
The `.pyc` is the *inner* artefact. At least one build ships
`AES-CTR(master key, AST_nonce, pyc-with-encrypted-parts)`: the file on disk is not a pyc, its first
four bytes are not the marshal magic, and a parser pointed at it reports a corrupt header rather than
an encrypted file. Three scopes share one master key and are separated only by which nonce is used:
| Scope | Nonce | Plaintext it yields |
|---|---|---|
| outer container, whole file | `AST_nonce` from `RSA_KEY2`, `nonce[15] = 2` | the pyc: header, string blob, code section |
| each code object | 12 bytes sliced out of that object's own `m_code` (§5) | that object's bytecode |
| each string | `pyarmor_mix_str_aes_nonce` | that one literal |
The order is not a preference. Applying a code object's nonce to the on-disk bytes decrypts layer 1's
ciphertext with layer 2's stream and yields high-entropy bytes that look like a private opcode set, so
the failure is "this packer uses a custom ISA", which is the wrong conclusion. Peel the outer layer
first, then check for the pyc header, then parse (§3).
A live dump does not replace this pass either: the packer decrypts each code object when it is first
imported, so a process dump holds the objects that ran and leaves everything else as ciphertext. A
function missing from a dump means "not reached yet", not "not present" — force the modules to import
before calling a dump complete, and keep the static pass as the only complete route.
## 3. Parsing the code object
The protected file is a normal `.pyc` with extra fields, so the parser must be version-aware.
**Once the outer layer is off (§2.2)**, the file is a normal `.pyc` with extra fields, so the parser
must be version-aware.
Fields that change and the versions that introduced them:
| Field | Width / condition |
@@ -147,9 +179,16 @@ Then:
6. Replace the descriptor's first 8 bytes with the `"<COAddr>"` placeholder so a later re-run does
not treat runtime data as a key.
The nonce construction is the part that is easy to get wrong: `nonce[15] = 2` is a domain
separator, and using an all-zero tail produces a stream that decrypts the first block plausibly and
then diverges.
The nonce construction is the part that is easy to get wrong, and the usual description of *how* it
fails is wrong: `nonce[15] = 2` is not a flag that only affects later blocks. In counter mode every
block's keystream is `E(nonce || counter)`, so changing byte 15 changes the counter start and corrupts
**block 0 onward** — there is no "first block decrypts plausibly" state to catch you. (`observed`,
host: two 16-byte counter blocks differing only in byte 15 differ in 16 of 16 keystream bytes, so
the ciphertext differs from block 0 — see the EXTENSION record and
`docs/tool-verification/fixtures/verify_ref_claims_10c.py`.) What an *unset* tail does is worse in a different way: the leftover bytes
are whatever the buffer held, so the keystream is not reproducible at all and the same input decrypts
differently on two runs. Zero the buffer, set the byte, and check the first eight bytes of the result
against a known code-object prologue instead of trusting a plausible-looking body.
## 6. Decrypting strings
+47
View File
@@ -54,6 +54,51 @@ launch screen, popups and tab set are **client decisions** or **server data**,
which is the difference between a five-minute patch and a dead end. See
`server-config-and-updates.md`.
## 1c. Resource completeness and the encryption map
Two questions are cheap on day one and expensive after a week of patching: **how much of the game is
in this APK**, and **what exactly is encrypted**. Answer both before choosing a route.
**Completeness.** A 1.2 GB package can be a quarter of the game. Find the game's own catalogue
(`manifest.*`, `AssetDatabase.manifest`, a version file, a native manifest) and diff it against the
files actually present, summed by directory. Then diff the content tables (costumes, characters,
levels) against entries that have a model or texture. In the source's micro-client case, the manifest
listed 42,700 bundles / 4.62 GB while the APK held 12,120 / 1.05 GB, and about 91% of the clothing
models were absent. The rest was downloaded on first launch and died with the server.
A player's app backup is often the only complete source; treat it as untrusted: identify the container
(headers, compression, encryption), verify every file against the backup's own manifest and MD5, and
confirm the APK inside is the **same build** — the source found a backup APK with the same version
name and versionCode but 1,518 differing files. Merge the hot-update layer (scripts, manifests, updated
bundles) into the package and make it survive the client's first-launch cleanup, or the files are
deleted before they are read. If the missing resources were never in any player's copy, stop and say so
rather than patching around a game that cannot be complete.
**Encryption map.** Do not answer "is anything else encrypted?" from memory. Spend half an hour:
1. **Classify every entry** — installed files plus the hot-update directory: size, first 16 bytes,
magic type, and entropy over the first 64 KB. The goal is zero "unknown" entries.
2. **High entropy is not encryption.** Compressed bundles, audio and textures all sit above 7.5.
Test whether the standard loader opens the file (a resource bundle that UnityPy loads is not
encrypted), whether a public header is present and plausible (e.g. `FSB5`), and whether a sample
decodes to a real image or sound.
3. **Judge text resources one by one** — readable text, a public binary format (skeleton, sound bank,
protobuf), or high entropy and a length that is a multiple of the block size (a cipher candidate).
4. **A fixed prefix is not encryption.** Several zero bytes at the start of every bundle are a common
anti-unpacker trick; count them in the original, skip them on read, preserve them on write.
5. **Check config tables by field**, not by vibe: decode with the protocol description, then scan for
field numbers the description does not contain. Zero unknown fields, and a re-serialization of the
same byte length, are two independent confirmations.
6. **Find the second copy.** Packages often contain an old config database while the phone's
hot-updated copy is newer. Compare row counts per table and build from the newer one.
7. **List runtime crypto points separately** — script load, login token, resource check, payment,
network packet — and record for each whether the offline route needs it.
8. **Separate "cannot decrypt" from "not in hand".** A server database or an unreadable private
directory is missing data, not an encryption problem; mixing the two produces a false "cracked".
The map is a deliverable: it lets a later reader see which conclusions were measured, which were
inferred, and which files nobody could open.
## 2. Is it packed?
Read `AndroidManifest.xml` → `application android:name`.
@@ -129,6 +174,8 @@ Heuristic: the business dex mixes the app's package prefix (hundreds of hits) wi
| `libflutter.so` + `libapp.so` | **Flutter (Dart AOT)** — dex contains only a thin shell |
| `libil2cpp.so` + `assets/bin/Data/` | **Unity (IL2CPP)** — native |
| `libmono*.so` + `assets/bin/Data/Managed/` | **Unity (Mono)** — managed DLLs under `assets/` |
| `libunity.so` + a `luascript` bundle or thousands of Lua `TextAsset` entries | **Unity + Lua** (xLua / tolua / SLua) — the logic is in a bundle, not the assembly — `unity-lua-and-assetbundles.md` |
| `liblayaair.so` + `libv8*.so` + `assets/scripts/*.js` | **LayaAir native (Conch)** — JavaScript logic and a DCC cache — `framework-runtimes.md` §LayaAir native (Conch) specifics |
| `libreactnativejni.so` + `assets/index.android.bundle` | **React Native** — JS bundle under `assets/` |
| `libhermes.so` | **Hermes bytecode** |
| Almost everything in `.so` | **Native** — different toolchain entirely |
@@ -206,6 +206,33 @@ Always pass the explicit range (Route B above) and read the scheme list from tha
Useful detail: keeping the same keystore across builds lets you iterate with `-r` and **preserve a logged-in session**, which matters a lot when the feature you are testing needs auth.
### Renaming the package so two builds coexist
Same package name plus a different signature is an install refusal, and uninstalling the official app
destroys its data. To install alongside it, rename the package in three places — a manifest-only edit
produces an APK that installs and then fails to find its own resources:
1. **Binary `AndroidManifest.xml`.** Rebuild the UTF-16 string pool and replace the package name and
**every string that carries its prefix** (permissions, provider authorities, the file provider, the
push `C2D_MESSAGE` permission, and similar). Enumerate the suffixes from a table rather than
guessing; update the chunk sizes and the file size; assert that no occurrence of the old name
remains. Do not rename Java class names.
2. **The `resources.arsc` package block.** Its name is a fixed 128-UTF-16-character field. Miss it
and the build installs but resource resolution fails at start — the same symptom as a missing
resource, far from the cause.
3. **The launcher label**, in the arsc UTF-8 string pool. This can be replaced in place only when the
new label is not longer than the old one.
Then grep Java/smali for quoted package-name literals and change build scripts to read the name from
one variable instead of hardcoding it. The app's data directory becomes
`Android/data/<new-package>/`, so old saves are not carried over — say so in the install notes.
Verify with `aapt dump badging` (package and label), then install both builds on one device: the new
one must reach its main screen and read/write a save while the official one remains installed. The
source's LayaAir/Conch case also had to change the arsc package name (Android 9+ compares it when
resolving resources); hardcoded private-directory paths used a build-time placeholder, and the local
licence value derived from `ANDROID_ID` did not change with the package name, while saves did.
### Vendor install interception (OEM shells)
Some ROMs route `adb install` through their own "security centre", which can return
+3
View File
@@ -90,6 +90,8 @@ reference file is not named here, or when a script is not named here.
| A `dlopen`-able `.so` will not load after a custom loader, or a repaired `soinfo` resolves symbols to garbage | `linker-and-soinfo-repair.md` — bias versus base, `seg_page_offset`, the defining library's bias, `APS2` packed relocs, the minimal `soinfo` field set, and the dump window after `LoadSegments` |
| A native trace has no `cmp`/`sub`/`jcc` — only `and/or/not/shr/neg`, a flags slot, and a `ret` that lands at a VM entry | `vm-protector-analysis.md` — virtual eflags is data, NAND lowering, branchless select, data-anchored breakpoints, and trace-then-search-by-constant; dispatcher slicing stays in `native-vm-recovery.md` |
| The logic you need is Python bytecode — a `.pyc`/PyInstaller/Pyarmor payload rather than Java, Dart or native | `python-bytecode-recovery.md` — key schedule, AES-CTR nonce rules, the 12-byte VM, version-gated `pyc` parsing and the extra-section TLV; static and offline, then call the recovered module |
| A Lua decompiler rejects every script with **`non-standard lua format: <n>`** | `unity-lua-and-assetbundles.md` §2 — a changed Lua 5.1 header byte, not encryption |
| A re-signed Unity/Mono build exits cleanly with code 4 about two seconds in, with no Java exception | `unity-lua-and-assetbundles.md` §5 — a publisher shell owns the process |
_70 row(s) below the header._
@@ -155,6 +157,7 @@ _70 row(s) below the header._
| `references/on-device-tooling.md` | Working **from the phone itself**: MT Manager edit/repack/sign and its built-in APK MCP, LSPosed Manager, Termux+frida, and on-device data inspection |
| `references/split-apk.md` | The target is a **split APK / App Bundle set** (`base.apk` + `split_config.*.apk`), or `pm path <PKG>` returned several files: reading a set, merge versus unified re-signing, and the install refusal each mistake produces |
| `references/unity-runtime.md` | The package is **Unity**: telling Mono from IL2CPP, dumping `libil2cpp.so` + `global-metadata.dat` with Il2CppDumper and importing it into IDA in the order that works, a run-time lookup over frida-il2cpp-bridge, the dnSpy-Unity-mono patch for a Mono player, and the audit probes when the deliverable is a report |
| `references/unity-lua-and-assetbundles.md` | A Unity game keeps its logic in **Lua** (xLua/tolua/SLua), or the edit is in an AssetBundle: finding and decrypting the scripts, the Lua 5.1 header tamper, bundle CRC in the manifest the game actually reads, partial-encryption windows, UnityFS rebuild traps (layout loss, stripped dependencies, compressed==raw), added/replaced TextAsset read-back, and half-encrypted Mono assemblies behind a publisher shell |
| `references/il2cpp-protected-metadata.md` | A Unity IL2CPP pair is **not readable**: `global-metadata.dat` is absent, 0 bytes, encrypted, embedded, or its version lies. Consumer-side dump, version-independent header sizing, the XOR/VM/XXTEA container shapes, the live-image dump, and the ELF repair that makes a dump usable |
| `references/python-bytecode-recovery.md` | The logic is **Python bytecode** behind Pyarmor or PyInstaller: key derivation, AES-CTR nonce rules, the 12-byte VM, a version-gated `pyc` parser, the extra-section TLV, and per-code-object / per-string decryption |
| `references/linker-and-soinfo-repair.md` | A protected `.so` must be loaded or dumped **by hand**: the `dlopen` pipeline as a loader spec, load_bias and segment arithmetic, `DT_*` parsing, relocation rules and the two biases, the minimal `soinfo` repair set, anti-dump header XOR, and where a dump is valid |
@@ -221,6 +221,28 @@ the attribute chunks around it, which is what `apktool` is for — and note that
`apktool b` rebuild rewrites the whole archive
(`references/repack-and-sign.md` §Repacking an unpacked (de-shelled) app).
### A narrow manual merge through apktool (when bundletool is unavailable)
The rule above is the safe one: do not fold resource tables by hand. There is one exception narrow
enough to name — a set whose resource splits are **additive** (density or language variants that do not
redefine an existing name with a different id). The source's native case did this and installed the
result as a single APK:
1. Install the base as an apktool framework: `apktool if base.apk -p <dir> -t <tag>`.
2. Decode each split with the same `-p/-t` so its resources keep their **original ids** instead of
being renumbered by the decoder.
3. Copy the split's `res/` files into the base and add their ids to the base's `public.xml`. Skip a
name that already exists with the same id; replace `APKTOOL_DUMMY_0x...` names by looking the real
name up in the base's id table.
4. Copy `lib/<abi>/` into the base. In the manifest, remove `requiredSplitTypes`, `splitTypes`,
`vending.splits` and `stamp.*`, and set `extractNativeLibs="true"`.
5. Verify every resource reference resolves and the app renders the split-only content. If two members
define the same resource name with different ids, **stop** — that is the folding problem the first
rule warns about, and bundletool is the route.
This is a per-set workaround, not a resource merger. Say in the delivery which splits were folded and
which resource families they carried.
## 6. Install refusals, and what each one means
| Message | What it actually says | Attribution |
@@ -0,0 +1,221 @@
# Unity + Lua, AssetBundles, and half-encrypted Mono assemblies
Load this when a Unity APK keeps its game logic in Lua (xLua / tolua / SLua), when the thing you need to
edit is an AssetBundle rather than an assembly, or when a rebuilt Unity package fails in a way that
looks like the patch: a decompiler rejects every script, a bundle loads as null, a repacked bundle
crashes only on device, or a re-signed Mono build exits cleanly a second or two after the splash. It
is the script-and-asset half of Unity; `unity-runtime.md` owns Mono/IL2CPP identification and the
managed-code route, and `il2cpp-protected-metadata.md` owns protected IL2CPP metadata.
**Claim strength.** Absorbed from a public game-preservation skill's anonymised case reports: one
Unity + Lua target (1,443 encrypted TextAssets, a Lua bundle, CRC in an AssetBundle manifest) and one
Unity Mono + SLua target (8,420 Lua 5.1 TextAssets, a publisher shell that decrypts the first 4 KB of
each assembly, a 1.2 GB micro-client). The source reports these as work performed on real devices;
**this repository has run none of it** — no Unity package was decrypted, no bundle rebuilt, and no
Mono assembly reconstructed here. Every mechanism below is therefore `unverified`, and the counts
and offsets are the source's, not this repository's measurements. What generalises is the failure
shape, not the constants.
## 1. Recognise the shape before choosing a tool
| What is in the package | Where the logic is | Route |
|---|---|---|
| `libunity.so` + `libmono*.so` + `assets/bin/Data/Managed/Assembly-CSharp.dll` | C# IL | `unity-runtime.md` §Mono |
| `libunity.so` + `libil2cpp.so` + `global-metadata.dat` | native + metadata | `unity-runtime.md` §IL2CPP |
| `libunity.so` + a `luascript` bundle or thousands of Lua `TextAsset` entries | Lua source or Lua 5.1 bytecode | this file §2 |
| `assets/AssetBundles/<platform>/` with per-bundle `.manifest` files | assets, prefabs, textures, sometimes scripts | this file §3–§4 |
| `Application` is a vendor shell class + `libtprt.so` / `__tpinfo.tsa` | shell decrypts managed assemblies at run time | this file §5 |
The first question is not "how do I decrypt Lua" but **which layer owns the behaviour**. A Lua game
can have almost no interesting C#: the C# boots the engine, loads a bundle and calls into Lua. In that
shape, editing IL is the wrong layer even when the IL is readable.
## 2. Getting Lua out of a Unity package
### 2.1 Find the container and the key
Scripts usually live in one of three places: a dedicated bundle such as `luascript`, individual
`TextAsset` entries inside many bundles, or a loose file list such as `all_lua_files.lua` (which is
often the one plaintext index that names the rest). Locate the loader first: a C# method with names
like `LuaScriptKey`, `ScriptKey`, `Key()` or `LuaRuntimeConfig` is where the key is chosen.
The source's case A: 1,443 `TextAsset` entries, DES-CBC, and **`key == IV ==` an 8-byte constant**
taken from `LuaRuntimeConfig.LuaScriptKey()`. Do not assume every script is encrypted: in that case
`all_lua_files.lua` was plaintext. Decrypt a sample, then prove the output is a script (it parses,
and its first line is plausible Lua) before batch-processing 1,443 files.
Patterns worth recognising without reversing the decryptor:
- **Header-only tamper.** A Lua 5.1 chunk starts with signature `1B 4C 75 61` and version `51`;
the next byte (offset 5) is the format byte, normally `00`. A build that changes it to `01` makes
`unluac` say *"non-standard lua format: 1"* while the rest of the file is untouched. Compare the
first 12 bytes with the standard header before concluding "encrypted".
- **A single-byte XOR tail** with a strongly encrypted head (see §5 for the assembly version). The
tell is the plaintext zero: deep in the file, the same byte repeats in long runs. One byte of XOR
turns every plaintext zero into that byte.
- **A "decrypt" that is only a wrapper.** Before implementing a cipher, check whether the transform
cancels (a repeating XOR with a fixed key, or a stream cipher applied twice). `protocol-reverse.md`
§7 has the differential probe for classifying a primitive; use it when the shape is not obvious.
### 2.2 Repair the header, then decide what the loader accepts
For the byte-5 tamper, copy the standard 5.1 header over the first 12 bytes, then decompile one file.
If the opcodes were not shuffled, the output is clean source; if the decompiler produces nonsense,
the build may also have shuffled opcodes, which is a different problem.
The other half is the loader: the C# call that loads a chunk often takes a mode/`bytecodeOnly` flag.
If the bundle path loads with `bytecodeOnly == false`, your patch can be **plaintext Lua** — no need
to find a matching 32-bit `luac`. If it is true, recompile the module to the exact Lua version and
ABI, or patch the loader to accept source. Read the call site, do not guess from the file extension.
Batch decompilation is CPU-bound per file (a JVM start per script in the source's toolchain); run it
in parallel and keep the output indexed by entry name, because the next step is a lookup, not a read.
### 2.3 Verify content against entry names
Lua 5.1 bytecode stores its source name immediately after the header (for example
`@UI/reputationshop/shop.lua`). After a batch decompile, compare **the entry name with the chunk
name** before analysing anything. In the source's case, 112 files decompiled to the same unrelated
file because their bundle writer had cloned a template object and `read()` kept returning the
template's bytes. The game itself was fine; only the analysis copy was wrong.
The same warning applies to a hot-update merge: if your bundle wrapper replaces `main.lua` but
`read()` still returns the packaged original, the build patches the **old** script, and the
hot-update version's constants silently disappear. Keep a sidecar map of every byte you write
(replacements and additions) and make your reader return it first; then compare the bytes read back
with the hot-update file before trusting a patch.
## 3. AssetBundle integrity: the CRC is not where you guess
Unity verifies a bundle's CRC when it loads it. The value can live in:
- `<bundle>.manifest` next to the bundle, and
- `assets/AssetBundles/<platform>/AssetDatabase.manifest` (the catalogue).
Guessing which one is live costs a full round. **Run the unmodified build once and read the log** —
Unity prints both values:
```text
E/Unity: CRC Mismatch. Provided d906612, calculated ab764880 from data.
Will not load AssetBundle 'luascript'
```
Change the manifest the game actually reads (the catalogue in the source's case, not the same-named
bundle manifest) to `0` (skip) or to the computed value. Then verify the bundle loads, not only that
the error disappeared.
**An 8-byte zero prefix is not corruption.** In the source's case A, 2,354 of 2,355 bundles began with
eight `0x00` bytes in the original package; the only exception was the catalogue. All of them loaded.
An earlier pass "repaired" 13 of them and carried the damage into the next baseline. Count the prefix
across the original package before treating it as a fault; skip it on read and preserve it on write.
### 3.1 A bundle whose first block will not decompress
The shape is: a valid `UnityFS` header, the first compressed block fails to decompress, later blocks
are fine. That is a **partial-encryption window**, not a corrupt download. To bound it:
1. Parse the UnityFS header and block table yourself; decompress each block independently and record
which blocks fail.
2. Entropy-scan the failing block's compressed stream. A sharp drop in entropy marks the end of the
encrypted window.
3. Run the block's compressor (often LZ4) directly over the ciphertext; the byte offset where it
crashes is the start of the window.
4. Compare the start/end across several bundles. The source found 1,691 bundles with the same
`[56:4096]` window, which proves a build-wide scheme rather than per-file damage.
5. XOR two ciphertexts from different bundles: if the transform is a fixed stream cipher, the
plaintext-derived difference is stable. That tells you the shape, not the key.
Only after this do you know what you are missing: the key or the algorithm. Do not rebuild the
bundles before the window is pinned.
## 4. Rebuilding a bundle without changing it
A bundle is a serialized container, not a zip. Two independent traps:
**The rewriter changes the header/layout.** UnityPy's `save_typetree` can produce a much smaller
serialized file than the original (the source saw 6,700 → 3,552 bytes) because it drops the original
header layout and alignment padding. Compare the object metadata and header of old and new files; if
they differ, pad/restore the original layout before writing the bundle back. For a texture, render the
new text with the game's own font and encode it back to the original format (ETC2 in that case); do
not assume a PNG round-trip is equivalent.
**A stripped resource is still in the dependency graph.** If you remove an AssetBundle but leave the
`AssetBundleManifest` listing it as a dependency of a retained bundle, Unity returns **null** for the
retained bundle. Remove the dependency edges when you remove the assets, not only the files.
**The compressed-size edge case.** A rebuilt bundle can crash where a block's compressed size equals
its raw size — the loader takes a branch that assumes compression. Do not debug this inside a full
build. Replace one hand-made bundle into an existing signed APK, re-align and re-sign, install and
cold-start; each experiment is about a minute. Write a minimal UnityFS reader that lets you change one
block size, one compression flag or one field at a time, and keep a control bundle that differs in
nothing. That is how the source found the exact equality that broke the load.
### 4.1 Adding or replacing a TextAsset
When a Lua script is added to an existing bundle, the writer has to create a new serialized object and
update the container index. Two checks make this safe:
- **Keep the bytes you wrote.** Do not rely on a library's `read()` after `set_raw`/`save_typetree`;
some versions return the template object or the original bytes. Store the written payload in a
sidecar map and serve it on read.
- **Verify entry name and chunk name agree**, for every added and every replaced script. Then verify
the bytes read back equal the source file you intended (especially after merging a hot-update
layer). A build that patches the old script is indistinguishable from a patch that did nothing.
## 5. Mono assemblies: half-encryption, a rebuilt PE header, and the publisher shell
This is a different shape from a packed dex. The assembly file is present and looks like a PE, but its
first `0x1000` bytes are strongly encrypted and the rest is XORed with one byte. The tell is the same
as §2: deep in the file, one value repeats in long runs, because plaintext zeros became that value.
Autocorrelation does not show a period; the repeated value does.
To read it without reversing the runtime's decryptor:
1. XOR the tail with the single byte.
2. Rebuild the PE header from structural landmarks rather than guessing offsets: the
`_CorDllMain`/`mscoree.dll` import, the `FF 25 00 20 40 00` entry trampoline, the `.reloc`
block that points at it, `VS_VERSION_INFO` in `.rsrc`, and the `BSJB` metadata root.
3. Watch for an extra `.sdata` section (static-field initial values): it appears as a hole between
`.text` and `.rsrc` and as a file offset `0x400` instead of `0x200` for `.text`. Missing it
makes ILSpy report *"Field data (rva=...) could not be found in any section"*.
4. Accept the boundary: methods whose bodies lived in the first 4 KB are lost (the source counted 87
small constructors and 123 getters across two assemblies). Static analysis of the rest still works.
**The publisher shell changes the plan.** If `AndroidManifest`'s `application` is a vendor class
(for example a `TPShellApplication`) and `lib/` contains its runtime, the shell checks the APK
(signature/CRC/package) and kills the process about two seconds after launch. The symptom is
`Process ... exited cleanly (4)` with **no Java exception** and no tombstone. Do not read that as a
normal crash. The same shell often decrypts the assembly heads, so removing it also removes the thing
that made the assemblies readable.
The source's route: switch the shell off through its own dex string constants (same-length value
change, then recompute the dex header's SHA-1 and adler32), and recover the plaintext assemblies from
the **original game's process memory** — root, read `/proc/<pid>/maps`, stream anonymous regions,
locate the known XORed body, and restore the DOS header the shell zeroed. That route is specific to
that shell; the general rule is: identify the shell's own kill signal and its own string gate before
patching, and do not ship a rebuild while the shell still owns the process. Shell identification and
the keep/drop decision are in `packers.md` and `code-virtualization-and-custom-linkers.md`;
`advanced-unpacking.md` owns the memory-dump boundary.
## 6. Verification
A Unity asset patch is done when:
- the bundle **loads** (the CRC error is gone, and no null bundle appears in the log);
- the script's **entry name, chunk name and decompiled content** agree;
- a replaced script's bytes read back byte-identical to the source you wrote;
- an added entry exists in the container index and is returned by the loader;
- the on-device screen shows the change, after a cold start, on the same build you installed;
- a control build with **no** patch shows the old behaviour on the same device.
A hash of the APK is not evidence that the bundle inside it changed — check the bundle entry, not the
APK size. Signing and alignment stay in `repack-and-sign.md`.
## 7. Boundary
- **IL2CPP metadata and native code** — `unity-runtime.md` and `il2cpp-protected-metadata.md`.
- **A packer or a self-terminating native check** — `packers.md`,
`code-virtualization-and-custom-linkers.md`, `native-tamper-and-suicide.md`.
- **Crypto classification** — `protocol-reverse.md` §7; do not implement a cipher from a guess.
- **The game's network layer** — `protocol-reverse.md` and `server-api.md`.
- **Splitting, signing and package rename** — `split-apk.md` and `repack-and-sign.md`.
@@ -140,6 +140,52 @@ the same rule as `pitfalls.md` P47.
actually loads — a split or stubbed `libil2cpp.so` inside the APK is not necessarily the one mapped
(`native-and-so.md`).
### When the managed layer is itself the interpreter
IL2CPP is ahead-of-time compiled, which makes it tempting to read `libil2cpp.so` as the only code that
matters. A `.so` that looks like a thin wrapper over `Dictionary` and delegate calls is often sitting
on top of an interpreter written in C# — and a VM written in C# is recoverable from `dump.cs` without
ever reading an opcode handler in assembly. The shape in `dump.cs`:
```text
class <obf> {
int[] aa1; // the guest program, built from a literal
int aa5; // the cursor, i.e. the PC / vEIP
Dictionary<int, Action> aa8; // opcode -> handler
}
```
A `while` loop that reads `array[cursor]` and calls `dict[op]` is the dispatcher; the array initialised
from a literal and the dictionary filled in the constructor are the program and the handler table. The
handler *indices* are assigned in the constructor by walking an enum or a `static_fields` block (one
sample enumerated 1..22 and used those values as dictionary keys), so the opcode→handler map is a
property of the constructor, not something to discover by tracing. Read the constructor first, rename
the fields positionally to `a1..aN`, delete the null and length guards, and the dispatch loop becomes
plain control flow. If the program array is built at run time, hook the constructor and take its
argument instead of tracing the loop.
The recovery method does not change once you have the instruction stream — `vmp-differential-analysis.md`
for the opcode map and `native-vm-recovery.md` §11 for the artefact set. What changes is the cost: a
managed VM is read statically, in a decompiler that still has names.
### Array literals are not in `.rodata`
A static array literal — a crypto key, an S-box, a constant table — has **no inline initialiser in
`libil2cpp.so`**. IL2CPP stores the field's default value in the metadata and materialises it at class
init by calling `RuntimeHelpers::InitializeArray` (the managed-side name; the implementation copies
from the field-default blob). Consequences for both reading and searching:
- `grep`-ing the `.so`, or `strings`-`ing` it, cannot find the table, and its absence is not evidence
that the table is derived at run time.
- Hook `InitializeArray` (or break on it) and the argument is the table; the same bytes are also
readable from the metadata field-default blob without a device.
- The table is per-field, so one hook gives you every literal the class initialisation touches, which
is usually the whole key schedule of a hand-rolled cipher.
This is the cheapest way to answer "where does this constant come from" in a Unity target, and it is
cheaper than reconstructing the cipher. `unverified`: the API name is stable across Unity versions, the
argument shape is not.
## 5. Driving IL2CPP at run time: frida-il2cpp-bridge
When the dump is encrypted or the question is behavioural, the bridge resolves classes by name at run
@@ -183,6 +229,23 @@ directory; with no arguments it uses defaults that may not be writable on a hard
written before the metadata is decrypted is the encrypted file again — check the magic before
importing it.
**Hook the framework primitive, not the app's wrapper.** Obfuscation renames the app's classes; it
does not rename `System.Security.Cryptography.*`, `javax.crypto.Cipher` or `java.security.*`. So when
the question is "what key does this use", trace the primitive instead of the wrapper the app built:
```ts
Il2Cpp.trace(true).classes(Il2Cpp.domain.assembly("System.Security.Cryptography")
.image.class("System.Security.Cryptography.AesCryptoServiceProvider")).and().attach();
```
One such trace reports every key/IV pair the process constructs, no matter which wrapper or
obfuscated call chain produced it, and it removes the need to reconstruct the derivation. On the Java
side the equivalent pair is a hook on `Cipher.getInstance` plus `SecretKeySpec` / `IvParameterSpec`.
The trade is provenance: the primitive tells you the value, not which call site asked for it — use the
app's own class (above) when you need the call site, and the primitive when the derivation is hostile
and you only need the material. `unverified` here: neither trace was run in this record.
The dependency is the boundary: a build that hides or strips the il2cpp exports breaks the bridge, and
the failure presents as *class not found* — indistinguishable from a wrong class name. Confirm the
exports exist before believing a negative lookup.
+93
View File
@@ -0,0 +1,93 @@
"""The 2026-10-27 host fixture must be able to fail.
`docs/tool-verification/fixtures/verify_ref_claims_10c.py` is the only thing standing behind three
`observed` labels, so its checks are as load-bearing as a gate. The first draft failed the rule this
repository applies to gates: the comparison check counted iterations inside the Python loop it was
measuring, so `n == k + 1` restated its own source and could never fail for a real reason. It now
compiles the two comparators and measures the compiler's output.
Each test here injects the wrong claim and requires the check to reject it, plus one test that the
process exit code follows the verdict. `observed` on a host with neither `openssl` nor a C compiler
is a skip, not a pass.
"""
from __future__ import annotations
import importlib.util
import shutil
import pytest
from conftest import REPO_ROOT
pytestmark = pytest.mark.unit
FIXTURE = REPO_ROOT / "docs" / "tool-verification" / "fixtures" / "verify_ref_claims_10c.py"
@pytest.fixture(scope="module")
def claims():
spec = importlib.util.spec_from_file_location("verify_ref_claims_10c", str(FIXTURE))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def _need_openssl():
if not shutil.which("openssl"):
pytest.skip("no openssl on this host: the CTR check degrades to SKIP")
def _need_cc():
if not (shutil.which("gcc") or shutil.which("cc") or shutil.which("clang")):
pytest.skip("no C compiler on this host: the comparison check degrades to SKIP")
def test_checks_pass_on_the_claim(claims):
_need_openssl()
_need_cc()
assert claims.ctr_nonce_tail() is True
assert claims.comparison_oracle() is True
assert claims.header_walk() is True
def test_ctr_check_rejects_an_unchanged_nonce(claims):
_need_openssl()
base = bytes(range(12)) + b"\x00\x00\x00"
same = base + b"\x02"
assert claims.ctr_nonce_tail(nonce_a=same, nonce_b=same) is False
def test_comparison_check_rejects_a_full_pass_mislabelled_early(claims):
_need_cc()
assert claims.comparison_oracle(early_source=claims.C_FULL) is False
def test_comparison_check_rejects_an_early_exit_mislabelled_constant(claims):
_need_cc()
assert claims.comparison_oracle(full_source=claims.C_EARLY) is False
def test_header_check_rejects_an_off_grid_start(claims):
assert claims.header_walk(start=0x110) is False
def test_header_check_rejects_ground_truth_that_disagrees(claims):
# the tail-most pair no longer sits at the largest offset, so "declared" and the forward scan
# cannot both be the file length
pairs = [(0x1100, 0x08), (0x1300, 0x10), (0x10A0, 0x10)]
assert claims.header_walk(pairs=pairs) is False
def test_main_exit_code_follows_the_verdict(claims, monkeypatch):
# a check that returns False without printing must still fail the run
monkeypatch.setattr(claims, "ctr_nonce_tail", lambda: False)
monkeypatch.setattr(claims, "comparison_oracle", lambda: True)
monkeypatch.setattr(claims, "header_walk", lambda: True)
assert claims.main() == 1
def test_main_treats_a_skip_as_not_a_failure(claims, monkeypatch):
monkeypatch.setattr(claims, "ctr_nonce_tail", lambda: None)
monkeypatch.setattr(claims, "comparison_oracle", lambda: True)
monkeypatch.setattr(claims, "header_walk", lambda: True)
assert claims.main() == 0