Skip to content

11 — Android Runtime · References

Annotated. Each entry says why you would open it, so you can pick the right one under time pressure.

Implementation-level sources (OAT format, ArtMethod, GC, dex2oat) are catalogued in 13-ART/references and not duplicated here.


Primary source — AOSP

Read on cs.android.com, which gives cross-references and history. See 07-AOSP for the navigation technique.

Class loading — the core of this chapter

Path Open it when
libcore/ojluni/src/main/java/java/lang/ClassLoader.java You want the parent-delegation loop in loadClass verbatim
libcore/dalvik/src/main/java/dalvik/system/BaseDexClassLoader.java You need to know what every Android DEX loader has in common
libcore/dalvik/src/main/java/dalvik/system/PathClassLoader.java Understanding how the app's own APK is loaded
libcore/dalvik/src/main/java/dalvik/system/DexClassLoader.java Investigating file-based dynamic loading
libcore/dalvik/src/main/java/dalvik/system/InMemoryDexClassLoader.java Investigating a packer. The constructor you hook
libcore/dalvik/src/main/java/dalvik/system/DelegateLastClassLoader.java You met inverted delegation and want to confirm the semantics
libcore/dalvik/src/main/java/dalvik/system/DexPathList.java Tracing exactly how findClass searches
libcore/dalvik/src/main/java/dalvik/system/DexFile.java The Java-to-native boundary for DEX handling
art/runtime/native/dalvik_system_DexFile.cc The JNI implementation behind DexFile

Framework — how an app process starts

Path Covers
frameworks/base/core/java/android/app/ActivityThread.java main(), handleBindApplication, makeApplication — the app process entry point
frameworks/base/core/java/android/app/LoadedApk.java getClassLoader() — where the app's loader is constructed
frameworks/base/core/java/android/app/ApplicationLoaders.java The loader cache and construction policy
frameworks/base/core/java/android/app/Application.java attachBaseContext and onCreate — the earliest app code
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java Preloading and the fork model
frameworks/base/core/java/com/android/internal/os/Zygote.java The fork itself, and the seccomp filter applied to the child

Runtime enforcement

Path Covers
art/runtime/class_linker.cc Turning a DEX class definition into a live mirror::Class
art/runtime/hidden_api.cc Non-SDK interface classification and enforcement
art/runtime/verifier/method_verifier.cc Bytecode verification — read this before calling it a sandbox
art/runtime/runtime.cc Runtime construction and global state
libcore/ojluni/src/main/java/java/lang/reflect/Method.java invoke — the reflection sink worth hooking

Official documentation

Resource Why
ART and Dalvik Google's own overview; the canonical framing
Configuring ART Every dalvik.vm.* property
ART Mainline module Why runtime internals differ across devices on one Android release
Restrictions on non-SDK interfaces The hidden-API lists, and the hidden_api_policy setting
Dex format Cross-reference with 12-DEX-Internals
Android behaviour changes Check before asserting version-dependent runtime behaviour
Play policy: device and network abuse The rules on downloading and executing code — relevant to §5.4

Tooling

Tool Use
Frida — Java API Java.enumerateClassLoaders, Java.classFactory.loader, Java.choose
Frida — Android guide Spawn vs attach, gadget, setup
jadx Reading the stub and the recovered payload
baksmali / smali When the decompiler fails on deliberately malformed DEX
aapt2 dump xmltree Reading <application android:name> — always step one
ent or binwalk -E Entropy analysis of assets/ to spot encrypted payloads
strace -f -e trace=openat,mmap Watching DEX files being opened and mapped

Chapter scripts

Script Purpose
scripts/runtime-recon.js Enumerate loaders and runtime state
scripts/find-dynamic-loading.py Cross-reference dynamic loading against external-storage use
scripts/dexopt-inspect.sh Report and change compilation state
examples/hook-classloaders.js Capture dynamically loaded DEX
../13-ART/scripts/dump-loaded-dex.js Hardened version with a memory-sweep fallback

Security research

Resource Why
Android Security Bulletins Monthly. Read for the pattern of which subsystems recur
Google Project Zero The highest-quality public Android runtime research
Android VRP rules What Google treats as a reportable runtime vulnerability

Note on CVE citation. This chapter describes runtime vulnerability classes rather than naming identifiers, because runtime bugs are numerous and version-specific and a misattributed CVE in a client report is worse than no citation. Pull specifics from the bulletin for the affected release.


OWASP

Resource Relevance
MASVS MASVS-CODE covers dynamic code loading and code integrity
MASTG Reverse engineering and tampering procedures
MASTG test apps (UnCrackable series) Practice targets — see 80-Appendix

Books and long-form

Work Why
Android Internals: A Confectioner's Cookbook — Jonathan Levin Deepest published treatment of the low-level runtime and process model
Android Security Internals — Nikolay Elenkov Best structural account of the security model the runtime sits inside
Virtual Machines — Smith & Nair The general theory: interpretation, JIT, deoptimization
Inside the Java Virtual Machine — Bill Venners Dated but still the clearest explanation of class loading and delegation

Chapter Relationship
12-DEX-Internals The byte format this runtime consumes
13-ART The implementation: OAT, VDEX, ArtMethod, GC, entry points
14-Dalvik The predecessor, and the full Smali reference
06-Android-Architecture Zygote and the boot process in context
09-Android-App-Internals Process creation, UID assignment, app identity
21-App-Sandbox The boundaries the runtime does not provide
22-SELinux The MAC layer that constrains even root
40-Obfuscation Packers, and the unpacking methodology this chapter enables
53-Frida The instrumentation these techniques depend on
65-Hooking Hooking across managed and native layers