Skip to main content
Multi-Layer Native & Mobile RE Capstone
Lesson 11 of 13

Multi-Layer Native & Mobile RE Capstone

Combine jadx, Ghidra, and Frida to trace execution across the Android JNI boundary, locate dynamically registered native functions, and evaluate multi-layer client protections.

Expert 38 min Reverse engineering
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Trace control flow from Dalvik bytecode in jadx across JNI into ARM64 native shared objects in Ghidra
  • Locate both statically exported Java_ symbols and dynamically registered RegisterNatives functions
  • Configure Ghidra JNIEnv types and Frida hooks to inspect arguments and return values at runtime
  • Evaluate why layered client-side protections fail against combined static and dynamic analysis

Recommended first: Bytecode (Python/.NET) & Android APK/Smali Reverse EngineeringPacking, Unpacking & Control-Flow ObfuscationAnti-Debugging & Anti-VM Techniques (ptrace, IsDebuggerPresent)Crackmes, Keygenning & Constraint Solving with Z3

#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:

  1. 4App Bytecodeclasses.dex (Java/Kotlin UI, preprocessing, native declarations)
  2. 3JNI BridgeSystem.loadLibrary, JNIEnv function table, type conversions
  3. 2Native ELFlib/arm64-v8a/libcore.so (compiled C/C++ logic, .init_array)
  4. 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.

Cross-layer call from Dalvik bytecode to native ELFCross-layer call from Dalvik bytecode to native ELFAppRuntimelibcore.soSystem.loadLibrary("core")Execute .init_array and JNI_OnLoadRegisterNatives(Verifier, methods, count)verifyToken(input)boolean resultUnexported native handlers still execute when bound via RegisterNatives

#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:

  1. Search for native declarations and System.loadLibrary calls in jadx.
  2. Record the exact package, class, method name, and parameter/return types (for instance, com.example.lab.Verifier.verifyToken(String) returning boolean).
  3. 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.

c
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:

Attaching Frida to an authorized lab package
$ frida-ps -U | grep lab
4812  com.example.lab
$ frida -U -f com.example.lab -l trace_jni.js

Use 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:

javascript
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:

  1. Map initialization and environment checks: Inspect .init_array and JNI_OnLoad for TracerPid reads in /proc/self/status, ptrace calls, or debugger checks so you know what triggers early termination.
  2. 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.
  3. Isolate and model the core validator: Once you reach the pure verification function inside the native binary, extract its byte equations and apply Z3 BitVec modeling (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 no Java_ export in .dynsym means native code is unused, while overlooking RegisterNatives inside JNI_OnLoad or constructors in .init_array.
  • ABI mismatch: Inspecting lib/armeabi-v7a/libcore.so (32-bit ARM) in Ghidra while hooking arm64-v8a (64-bit ARM) on the emulator, which makes every offset wrong.
  • Forgetting Ghidra's image base: Ghidra often maps ELF binaries starting at 0x100000 instead of 0x0. Subtract the Ghidra base before calling base.add(offset) in Frida.
  • Ignoring JNIEnv typing: Leaving param_1 as long * hides FindClass, GetStringUTFChars, and RegisterNatives behind 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 .so libraries (Ghidra), connected through JNI.
  • Check both Java_... static exports and RegisterNatives tables inside JNI_OnLoad, applying JNIEnv types in Ghidra to reveal API calls.
  • Pair Java.use with Module.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.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge