Android Reverse Engineering Deep Dive
Mobile Reverse Engineering Tools & Techniques · Mobile Application Security track
11 min read
In this module
Inside the APK
An APK is a ZIP archive carrying everything Android needs to install and run an app: compiled Dalvik bytecode (classes.dex), resources, assets, native libraries, and the AndroidManifest. Reverse engineering one means peeling back each layer with the right tool. This lesson walks through the core toolchain that professional Android reversers reach for every day.
jadx: From Bytecode to Java
jadx (Java Android Decompiler) is the workhorse of Android decompilation. It converts DEX bytecode back into Java source that, on a good day, reads almost like the original.
# Decompile an APK with jadx (command line)$ jadx -d output_directory target.apk
# Launch the GUI for interactive analysis$ jadx-gui target.apkjadx eats DEX, AAR, and JAR. The GUI gives you a searchable class tree, cross-references, and click-through navigation from any call site to its implementation. For most apps the output is shockingly close to the original Java or Kotlin.
jadx Limitations
jadx is a decompiler, not a debugger. Static-only, with a handful of known weaknesses:
- Obfuscated code: ProGuard/R8 renaming muddies the waters but doesn't stop decompilation. Commercial obfuscators that flatten control flow or encrypt strings produce syntactically valid Java that reads like a fever dream.
- Complex control flow: deeply nested exception handlers, switch statements with fall-through, and compiler-generated synthetic methods can spit out broken or uncompilable output.
- Native code: jadx can't touch
.sofiles. JNI calls show up as barenativemethod declarations with no body. - Dynamic class loading: classes pulled in at runtime via
DexClassLoaderare invisible to a static APK scan.
jadx decompiles Android DEX bytecode into readable Java. It handles most application logic well, can't touch native code, gives up on heavily obfuscated control flow, and never sees dynamically loaded classes. Use jadx-gui for interactive exploration; the CLI for batch jobs.
apktool: Resource Decoding and Smali
jadx aims for readable Java. apktool has different priorities. It decodes the APK's binary resources (AndroidManifest.xml, layouts, string tables) into normal XML, and disassembles the DEX bytecode into smali: the assembly language of the Dalvik VM.
# Decode an APK with apktool$ apktool d target.apk -o target_decoded
# The output directory structure:# target_decoded/# AndroidManifest.xml (decoded from binary XML)# smali/ (disassembled Dalvik bytecode)# res/ (decoded resources: layouts, strings, drawables)# assets/ (raw asset files, unchanged)# lib/ (native libraries, unchanged)The killer feature is that apktool's output is round-trippable. Edit the smali or XML, rebuild, sign, install:
# Rebuild the modified APK$ apktool b target_decoded -o modified.apk
# One-off: make a throwaway signing key$ keytool -genkeypair -keystore my-keystore.jks -alias test \ -keyalg RSA -keysize 2048 -validity 10000
# Align first, then sign (signing after zipalign keeps the v2+ signature valid)$ zipalign -p -f 4 modified.apk aligned.apk$ apksigner sign --ks my-keystore.jks aligned.apk
# Your key isn't the developer's, so remove the original before installing$ adb uninstall com.target.app$ adb install aligned.apkOrder matters here. APK Signature Scheme v2 and later sign the whole file, so running zipalign after apksigner breaks the signature. And because Android won't update an app with one signed by a different key, the original has to come off first (taking its data with it).
Understanding Smali
Smali is a readable form of Dalvik bytecode, the way x86 assembly is a readable form of machine code. One file per class:
# Example: a simple method in smali.method public isRooted()Z .locals 2
# Check if /system/app/Superuser.apk exists const-string v0, "/system/app/Superuser.apk" new-instance v1, Ljava/io/File; invoke-direct {v1, v0}, Ljava/io/File;-><init>(Ljava/lang/String;)V invoke-virtual {v1}, Ljava/io/File;->exists()Z move-result v0
return v0.end methodSmali uses a register-based instruction set (matching Dalvik), short type descriptors (Z for boolean, Ljava/lang/String; for String), and a straightforward call convention. With a bit of practice you can read it fluently enough for targeted patches — flipping a root-detection method to always return false, for example.
Click through the entries of target.apk below and switch between tools to see how differently jadx, apktool, aapt2 and readelf treat the same file. Then scroll to the patch: it's the method above with its body swapped for a constant false, followed by the rebuild and the price you pay for re-signing.
Inside an APK
Pick an entry to see what it is and which tools read it. Tool output is illustrative.
target.apk
ZIP archiveAn APK is an ordinary ZIP file, so any unzip tool can list and extract it. Several entries inside are compiled binary formats, though, which is why reversing needs a different tool for each one. Pick an entry to see what it is and what reads it.
Lists the entries
Patch isRooted() and rebuild
After apktool d, the method is in smali/com/target/app/RootCheck.smali. Replacing the body with a constant false makes every root check pass.
| 1 | 1 | .method public isRooted()Z | |
| 2 | - | .locals 2 | |
| 2 | + | .locals 1 | |
| 3 | 3 | ||
| 4 | - | # Check if /system/app/Superuser.apk exists | |
| 5 | - | const-string v0, "/system/app/Superuser.apk" | |
| 6 | - | new-instance v1, Ljava/io/File; | |
| 7 | - | invoke-direct {v1, v0}, Ljava/io/File;-><init>(Ljava/lang/String;)V | |
| 8 | - | invoke-virtual {v1}, Ljava/io/File;->exists()Z | |
| 9 | - | move-result v0 | |
| 4 | + | const/4 v0, 0x0 | |
| 10 | 5 | ||
| 11 | 6 | return v0 | |
| 12 | 7 | .end method |
const/4 v0, 0x0 loads 0 (false) into v0 and return v0 hands it back. Only one register is used now, so .locals drops from 2 to 1.
- 1. Rebuild$ apktool b target_decoded -o modified.apk
Reassembles the smali into classes.dex and re-encodes the manifest and resources. The output is unsigned.
- 2. Align$ zipalign -p -f 4 modified.apk aligned.apk
Aligns uncompressed entries to 4-byte boundaries (and .so files to page boundaries with -p). It rewrites the file, so it comes before signing.
- 3. Sign$ apksigner sign --ks my-keystore.jks aligned.apk
Signs with your own key, adding a new v1 signature in META-INF/ and new v2/v3 signatures in the APK Signing Block.
- 4. Install$ adb uninstall com.target.app && adb install aligned.apk
Android won't update an app with one signed by a different key, so the original has to come off first, taking its data with it.
- The certificate digest changes, so any check the app makes on its own signing certificate now fails.
- Play Integrity no longer recognises the app: the verdict's appRecognitionVerdict becomes UNRECOGNIZED_VERSION, and a server that enforces it will refuse the session.
- Re-signing can't be avoided. Without the developer's private key there's no way to produce their signature, so the patch only gets past checks that don't look at the signature.
apktool decodes APK resources and disassembles DEX to smali, a human-readable Dalvik assembly language. Unlike jadx output, smali is round-trippable: you can modify it, reassemble the APK, sign it, and install the patched version. This makes apktool essential for binary patching and modification tasks.
dex2jar and JD-GUI: The Alternative Chain
Before jadx took over, the standard pipeline strung two tools together:
- dex2jar converts DEX bytecode to standard Java bytecode in a JAR file.
- JD-GUI (Java Decompiler GUI) decompiles the JAR to Java source.
# Convert DEX to JAR$ d2j-dex2jar target.apk -o target.jar
# Open the JAR in JD-GUI for viewing$ jd-gui target.jarjadx has mostly retired this two-step approach by handling both halves internally and producing nicer output. dex2jar still earns its keep, though. When jadx chokes on a particular class, the dex2jar chain sometimes sails through — and vice versa. Different decompilation algorithms, different failure modes. Experienced analysts keep both tools handy.
Native Library Analysis
Plenty of Android apps ship native code as ARM (occasionally x86) shared libraries. The .so files live under the APK's lib/ directory, sorted by ABI:
lib/ arm64-v8a/ (64-bit ARM, most common) libnative.so armeabi-v7a/ (32-bit ARM, legacy) libnative.so x86_64/ (emulator support) libnative.soNative libraries are compiled C/C++ — DEX decompilers are useless on them. You need a binary analysis tool. Ghidra is the open-source default.
Loading Native Libraries in Ghidra
When you drag an Android .so into Ghidra:
- Pick the right processor: AARCH64 for arm64-v8a, and ARM v7 little-endian (
ARM:LE:32:v7) for armeabi-v7a. Ghidra usually reads this from the ELF header for you. Skip the Cortex variant, which is meant for Thumb-only Cortex-M microcontrollers. - Let auto-analysis chew through it. Functions, strings, and cross-references all light up.
- Hunt for exported symbols, especially anything following the JNI naming convention.
// JNI function naming convention:// Java_<package>_<class>_<method>// Underscores in package names become _1
// Example: com.example.app.CryptoHelper.decrypt()JNIEXPORT jstring JNICALLJava_com_example_app_CryptoHelper_decrypt( JNIEnv *env, jobject thiz, jbyteArray encrypted_data, jstring key) { // Native implementation here}JNI Interface Reversing
JNI is the bridge between Java/Kotlin code and native libraries. To reverse it well, you need to be comfortable on both sides.
Finding Native Method Implementations
Every Java native method needs a matching C/C++ implementation registered with the JVM. There are two ways to do that:
Static registration follows the naming convention Java_<package>_<class>_<method>. The functions show up as exported symbols in the .so, and Ghidra's symbol tree leads you straight to them.
Dynamic registration calls RegisterNatives() from the library's JNI_OnLoad function. Harder to trace, because the method names are just strings at runtime:
// Dynamic JNI registration (harder to reverse)JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { JNIEnv *env; vm->GetEnv((void**)&env, JNI_VERSION_1_6);
JNINativeMethod methods[] = { {"decrypt", "([BLjava/lang/String;)Ljava/lang/String;", (void*)native_decrypt_impl} };
jclass cls = env->FindClass("com/example/app/CryptoHelper"); env->RegisterNatives(cls, methods, 1); return JNI_VERSION_1_6;}Open the library in Ghidra, find JNI_OnLoad, follow the call to RegisterNatives, and read the JNINativeMethod array. That tells you which method name maps to which native function pointer.
JNI is the bridge between Java and native code. Statically registered methods follow Java_package_Class_method and show up as exported symbols. Dynamically registered methods are wired up by RegisterNatives() inside JNI_OnLoad, so you have to chase function-pointer arrays to find them. Whichever you're hunting, always open JNI_OnLoad first.
ProGuard and R8 Obfuscation
ProGuard — and its successor R8, now the default in Android builds — runs a few different transforms on the compiled bytecode:
What ProGuard/R8 Does
- Identifier renaming: classes, methods, and fields get squashed to single-letter names (
a,b,c). Package structures collapse. - Dead code removal: anything unreachable gets stripped out.
- Code optimisation: inlining, constant folding, branch elimination, class merging — all aimed at shrinking the bytecode. Merged and inlined classes can make the decompiled structure look quite different from the source.
What ProGuard/R8 Does Not Do
- String encryption: every string constant stays plaintext inside the DEX. API keys, URLs, error messages — all on display.
- Control flow obfuscation: method structure survives intact. Loops, conditionals, calls all decompile cleanly.
- Native code protection: ProGuard only touches DEX. Native libraries pass through untouched.
- Resource protection: XML layouts, assets, resource IDs all stay readable.
// Before ProGuard:public class NetworkManager { public String fetchApiData(String endpoint) { HttpClient client = new HttpClient(); return client.get("https://api.example.com/" + endpoint); }}
// After ProGuard (decompiled by jadx):public class a { public String a(String str) { b bVar = new b(); return bVar.a("https://api.example.com/" + str); }}// Note: the string "https://api.example.com/" is still plaintextBeyond ProGuard: Commercial Obfuscation
Apps that need real teeth reach for commercial tools — DexGuard, Arxan, Bangcle. These pile on:
- String encryption: strings are stored encrypted and decoded only at runtime.
- Control flow flattening: methods get rewritten into state machines that decompile into spaghetti.
- Native code packing: the DEX bytecode is encrypted and tucked inside a native library, only decrypted in memory.
- Anti-tamper checks: the app sniffs its own integrity and refuses to run if it's been touched.
These raise the effort bar, sometimes dramatically. They don't make reverse engineering impossible. Hook the runtime with Frida and you watch the strings get decrypted, the bytecode get unpacked, and the integrity check skipped — static obfuscation can't survive a dynamic analyst.
ProGuard/R8 renames identifiers and removes dead code but does not encrypt strings, flatten control flow, or prevent decompilation. It raises the bar for casual analysis but not for a determined reverse engineer. Commercial obfuscators like DexGuard add string encryption, control flow flattening, and native packing, which significantly increase analysis effort but can be circumvented through dynamic instrumentation.