#Why this matters
Real-world mobile targets and advanced reverse-engineering challenges rarely place all critical logic inside a single layer. An Android APK commonly handles user input and networking in Kotlin or Java, passes data across the Java Native Interface (JNI) into an ARM64 .so library, decrypts constants during library initialization, and enforces runtime environment checks before running its core verification routine.
Analyzing only classes.dex in jadx stops at a native keyword with no body, while opening a stripped .so in Ghidra without knowing how Java invokes it leaves you guessing among hundreds of unexported functions. Mastering the capstone workflow means connecting static bytecode analysis, native ELF decompilation, and Frida runtime instrumentation into a single repeatable investigation.
#Mapping the multi-layer architecture
Before opening a disassembler, map how the layers interact inside a hybrid Android binary:
- 4App Bytecodeclasses.dex (Java/Kotlin UI, preprocessing, native declarations)
- 3JNI BridgeSystem.loadLibrary, JNIEnv function table, type conversions
- 2Native ELFlib/arm64-v8a/libcore.so (compiled C/C++ logic, .init_array)
- 1Runtime & OS/proc/self/status checks, ptrace, emulator & hook probes
When a Java class runs System.loadLibrary("core"), the Android runtime loads libcore.so from the APK's matching ABI slice (for example lib/arm64-v8a/libcore.so on a 64-bit ARM device or lib/x86_64/libcore.so on an x86_64 emulator). Constructors in .init_array run first, followed by JNI_OnLoad if exported.
#Bridging jadx and Ghidra across JNI
Start in jadx to locate every native method declaration and understand how the app prepares inputs before crossing the boundary:
- Search for
nativedeclarations andSystem.loadLibrarycalls injadx. - Record the exact package, class, method name, and parameter/return types (for instance,
com.example.lab.Verifier.verifyToken(String)returningboolean). - Note any Java-side preprocessing such as Base64 decoding, whitespace trimming, or splitting a token into substrings.
Next, extract the .so matching your test device's ABI from the APK (which is a standard ZIP archive) and load it into Ghidra. Native functions bind to Java in one of two ways:
| Binding mechanism | Where to look in Ghidra | Typical visibility |
|---|---|---|
| Static JNI naming | Exports named Java_<pkg>_<class>_<method> |
Directly searchable in Symbol Tree |
| Dynamic registration | JNI_OnLoad calling RegisterNatives |
Implementation stays unexported (FUN_...) |
In stripped libraries, developers often prefer dynamic registration so symbol names never appear in .dynsym. To read JNI_OnLoad cleanly in Ghidra, retype its first parameter as JavaVM * and its helper pointer as JNIEnv *. Without JNIEnv * typing, Ghidra displays confusing pointer math such as (**(code **)(*param_1 + 0x548))(...) instead of clean struct member calls to GetStringUTFChars or RegisterNatives.
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env = NULL;
if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
}
jclass cls = (*env)->FindClass(env, "com/example/lab/Verifier");
JNINativeMethod methods[] = {
{"verifyToken", "(Ljava/lang/String;)Z", (void *)FUN_00101420}
};
(*env)->RegisterNatives(env, cls, methods, 1);
return JNI_VERSION_1_6;
}Once you see the JNINativeMethod table in memory or in the decompiler, jump straight to FUN_00101420: that is the true implementation of verifyToken, taking (JNIEnv *env, jobject thiz, jstring input).
#Instrumenting the boundary with Frida
Static analysis tells you what the code can do; Frida lets you observe what the app actually passes across the Java-to-native boundary at runtime. This is especially valuable when Java encrypts or encodes an argument before calling the native library, or when .init_array decrypts lookup tables in memory on startup.
First, verify your lab emulator connection and package name, then launch the app with a trace script:
$ frida-ps -U | grep lab
4812 com.example.lab
$ frida -U -f com.example.lab -l trace_jni.jsUse Java.use in Frida to inspect inputs and outputs at the Java method boundary, and Module.findBaseAddress with Interceptor.attach to observe the native function offset you identified in Ghidra:
Java.perform(function () {
var Verifier = Java.use("com.example.lab.Verifier");
Verifier.verifyToken.implementation = function (token) {
var ok = this.verifyToken(token);
console.log("[Java] verifyToken len=" + token.length() + " -> " + ok);
return ok;
};
});
var base = Module.findBaseAddress("libcore.so");
if (base !== null) {
// Offset 0x1420 identified from RegisterNatives in Ghidra
Interceptor.attach(base.add(0x1420), {
onEnter: function (args) {
console.log("[Native] entered FUN_00101420, thiz=" + args[1]);
},
onLeave: function (retval) {
console.log("[Native] return=" + retval.toInt32());
}
});
}Watch out for ASLR (Address Space Layout Randomization): the base address of libcore.so changes on every process launch, so never hardcode a runtime address. Always compute Module.findBaseAddress("libcore.so").add(offset) using the relative file offset from Ghidra (assuming Ghidra's image base is 0x0, or subtracting Ghidra's base such as 0x100000).
#Untangling layered protections and solving the core logic
When facing a multi-layer capstone target, work systematically from the outside in rather than diving randomly into assembly:
- Map initialization and environment checks: Inspect
.init_arrayandJNI_OnLoadforTracerPidreads in/proc/self/status,ptracecalls, or debugger checks so you know what triggers early termination. - Capture decrypted state after initialization: If the library unpacks S-boxes or constant tables at startup, inspect those memory regions once initialization finishes rather than re-implementing custom obfuscated decoders by hand.
- Isolate and model the core validator: Once you reach the pure verification function inside the native binary, extract its byte equations and apply Z3
BitVecmodeling (just as with standalone native crackmes) to verify the logic or demonstrate the weakness.
#Defending and common mistakes
Reverse engineers often stall on multi-layer mobile targets because of avoidable workflow errors:
- Stopping at
jadx: Assuming noJava_export in.dynsymmeans native code is unused, while overlookingRegisterNativesinsideJNI_OnLoador constructors in.init_array. - ABI mismatch: Inspecting
lib/armeabi-v7a/libcore.so(32-bit ARM) in Ghidra while hookingarm64-v8a(64-bit ARM) on the emulator, which makes every offset wrong. - Forgetting Ghidra's image base: Ghidra often maps ELF binaries starting at
0x100000instead of0x0. Subtract the Ghidra base before callingbase.add(offset)in Frida. - Ignoring
JNIEnvtyping: Leavingparam_1aslong *hidesFindClass,GetStringUTFChars, andRegisterNativesbehind opaque offset arithmetic.
For mobile defenders, the architectural lesson matches desktop native analysis: moving checks from Java into C/C++, hiding symbols with RegisterNatives, or adding basic anti-debug checks raises analyst effort, not cryptographic assurance. Anyone controlling the device can attach instrumentation or dump initialized memory. Keep secret keys, licensing decisions, and access control on the server, and treat native obfuscation strictly as a secondary layer alongside strong server-side validation.
#Summary
- Hybrid Android targets split logic between Dalvik bytecode (
jadx) and compiled.solibraries (Ghidra), connected through JNI. - Check both
Java_...static exports andRegisterNativestables insideJNI_OnLoad, applyingJNIEnvtypes in Ghidra to reveal API calls. - Pair
Java.usewithModule.findBaseAddress(...).add(offset)in Frida to trace arguments and return values across ASLR-randomized libraries. - Client-side native layers cannot hold secrets safely; enforce authorization and trust boundaries on the server.