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
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
Security research
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
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