Files
apk-reverse/skills/apk-reverse/references/framework-runtimes.md
T
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

12 KiB
Raw Blame History

Cross-Platform Runtimes

Load this when the app's UI is not native, or when Java-layer hooks produce no hits at all.

Many apps ship a native shell plus a cross-platform runtime. Their business logic, their UI, and their feature gates live inside the runtime, not in the dex. Patching the dex then does nothing — the Java code you can see is mostly glue. Determine the runtime before choosing where to patch.

Identify the runtime early

Signals in the APK:

Runtime Giveaways
Flutter libflutter.so, libapp.so, assets/flutter_assets/, Dart snapshot
React Native libhermes.so or libjsc.so, index.android.bundle, assets/index.android.bundle
Unity libunity.so, libil2cpp.so, assets/bin/Data/, globalgamemanagers → unity-runtime.md for Mono versus IL2CPP
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.

When the runtime runs JavaScript and the JS you find is one entry call fed a huge hex/base64 opcode literal, that is not a runtime-identification question at all — it is a JS virtual machine (jsvmp). Load references/jsvmp-recovery.md for that shape; the table above only names the engine.

The layer trap

The expensive mistake: seeing a UI element (dialog, paywall, gate) and assuming it is a native control, then spending a long time looking for it in the dex.

If it is drawn by the runtime, the dex contains only the bridge. Symptoms of being on the wrong layer:

  • hooking the obvious Java dialog/Activity classes produces zero hits while the UI clearly appears;
  • the classes that do appear in stacks are the runtime's own, with obfuscated names;
  • hooking a Java method changes nothing about the visible behaviour.

Establish layer ownership before investing in a patch direction.

How to tell which layer drew a given UI

  1. Enumerate the Java dialog and presentation classes and hook their show/creation paths.
  2. Reproduce the UI. If any hook fires, the caller stack names the detection and you are on the Java layer.
  3. If nothing fires while the UI is on screen, the UI is runtime-drawn or native-drawn. Switch axis.
  4. Expect runtime-owned windows to appear as ordinary system Dialog/Presentation objects used as containers for the runtime's surface. A hit on such a container is not evidence that the visible element is a native dialog — read the class name carefully before drawing conclusions.

Flutter specifics

  • Business logic is compiled ahead-of-time into libapp.so; UI is rendered by libflutter.so with no per-widget Java objects.
  • Widgets, dialogs, and paywalls are not Java views. They will never appear in Java stack traces, and no Java hook can intercept them.
  • The Java side is thin: one Activity, plus plugin classes. Calls cross the boundary through the platform-channel mechanism, whose class names are frequently obfuscated.
  • Because channel classes may be renamed, locate them by method signature and call shape, not by class name.

Where to intervene in a Flutter app

Goal Layer Notes
Stop the app being killed / refused at startup host native library earliest point, see native-and-so.md
Observe what the runtime is told platform channel shows the messages that drive the UI
Change a decision permanently libapp.so most direct, hardest to locate
Change startup behaviour only host native library constructor survives runtime restarts

Editing libapp.so is the most durable but locating Dart AOT code is genuinely hard. This subject is large enough to have its own reference: references/dart-aot.md covers pinning the Dart version, building a decompiler for exactly that version, the object-pool model and how to index it, the register and boolean conventions, the three assembly signatures that identify most business logic, the locating workflow, and how to patch this layer safely.

Unity specifics

  • Two backends, and they are not the same problem. A Mono build ships readable CIL (assets/bin/Data/Managed/Assembly-CSharp.dll); an IL2CPP build ships lib/<abi>/libil2cpp.so plus assets/bin/Data/Managed/Metadata/global-metadata.dat, and the metadata is what carries the names. references/unity-runtime.md covers identifying which one you have, dumping the pair with Il2CppDumper, importing the result into IDA in the order that works, and the Frida bridge for a run-time lookup.
  • A Unity UI is drawn by the engine, so Java hooks are glue. The Android layer is SDKs, permissions and the launch Activity; the gate you are looking at is a C# method. Patching the dex to remove it is the layer error this file opens with.
  • Debugger.IsAttached is a real anti-debug here. A retail Mono runtime refuses a debugger connection at the VM level, which reads as "the game is protected" — unity-runtime.md §Debugging Mono at run time owns that path, and ida-so-debugging.md owns the native attach underneath it.
  • 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 runtime. Find it, then find what references it.

  • Search them in the encoding the runtime actually uses, or you will conclude they do not exist. This is the single most common false negative in cross-platform work. A runtime snapshot does not necessarily store text as UTF-8; UTF-16 (little-endian on these targets) is common and entirely valid. A UTF-8 search of such a snapshot returns zero hits, which reads as "the strings were stripped / encrypted, this route is dead" — and that conclusion is wrong.

    blob = open('libapp.so', 'rb').read()          # or whichever artifact holds the snapshot
    for phrase in ('<feature label>', '<dialog title>'):
        print(phrase, 'utf-8:', blob.find(phrase.encode('utf-8')),
                      'utf-16le:', blob.find(phrase.encode('utf-16-le')))
    

    Try both, and try a short distinctive substring rather than a long phrase. Which encoding applies is predictable rather than random: in a Dart AOT snapshot ASCII literals are stored one-byte (a UTF-8 search finds them) while CJK / non-Latin literals are UTF-16LE (a UTF-8 search returns zero). dart-aot.md §7 gives the exact framing, and scripts/dart_pool_strings.py --find locates either encoding by file offset.

  • A phrase that is absent may simply never exist as one literal. UI text is often assembled from fragments or templates, so "the whole sentence" can be missing while both halves are present. Search the shortest distinctive token, and expect the interesting anchor to be a label rather than a sentence.

  • Landing on a string tells you where the text lives, not which code decided to show it. Treat the hit as an anchor for reference-hunting, not as the answer.

  • Compare two builds. The same feature in a slightly different version often reveals the code path.

  • Watch the boundary, not the interior. For cross-platform apps it is usually far cheaper to observe what crosses between layers than to reverse the interior of the runtime.

  • Do not assume the obfuscated names are stable or meaningful. They are not, and treating them as identities leads to conclusions that break on the next build.

  • Obfuscated identifiers can be non-ASCII and invisible. Renaming passes can replace class and member names with characters outside ASCII (combining marks, variant selectors and similar). If a class exists at runtime but "cannot be found" by the name you read from a decompiler, suspect encoding or normalisation in your tooling rather than a missing class. Resolve such members by shape — parameter counts, types, interface implementation — instead of by name, and prefer runtime enumeration of loaded classes over guessing identifiers.

What this changes about your plan

  • Budget for the runtime layer up front. If the app is Flutter/RN/Unity, the dex is not the main battlefield and a dex-only plan will stall.
  • Any behavioural claim must be validated through the runtime's own UI, because that is what the user sees. A patch that changes internal state without changing the UI is not a fix.
  • Keep the layer you are working in explicit in your notes. "Patched the paywall" is meaningless without saying which layer owned it.