APK reversing (unpack → patch → hook)
When it applies
You have an APK and a device/emulator you're authorized to test (tradecraft-scope-roe,
scope.txt), and the job is mechanics: read the logic, locate a check, patch and repackage, or
hook the runtime. For the broader what-to-test coverage map, work mobile-android-assessment
alongside — this skill is the reverse-engineering toolchain it routes into.
Why it works
An APK is a zip of DEX bytecode plus resources. DEX decompiles to near-readable Java (jadx) and
round-trips losslessly through smali (apktool), so you can read at the Java level but patch at the
smali level and rebuild. Anything the app hides from static reading — decrypted strings, runtime
checks, pinning — yields to Frida instrumentation on a rooted/emulated device.
Method
Ready-to-adapt Frida hook recipes (crypto, OkHttp, pinning, root/emulator/anti-debug bypass,
storage): see cheatsheet.md next to this file.
- Triage — unpack both ways before touching anything.
jadx -d jadx_out app.apk # readable Java view
apktool d app.apk -o apktool_out # smali + resources + manifest
Read AndroidManifest.xml first: package, main activity, exported components, permissions,
and whether lib/ ships .so files. Grep jadx_out for login|sign|encrypt|cipher|token|root| certificate|trust|okhttp|retrofit|webview.
- Read the Java layer. Start at
Application and the launcher activity, then the
auth/network/crypto classes and third-party SDK init. If jadx output is readable, locate the
business logic here before going lower.
- Drop to smali when jadx is incomplete or you need to patch. In
apktool_out: smali*/,
res/values/strings.xml, the manifest. Prime patch targets: root-detection return values,
login/cert-validation branches, debug flags, android:exported. jadx failing on a class does
not mean the logic is unreadable — the smali is always there.
- Rebuild, sign, install.
apktool b apktool_out -o rebuilt.apk
zipalign -p 4 rebuilt.apk rebuilt-aligned.apk
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey \
-keyalg RSA -keysize 2048 -validity 10000 # once; reuse it
apksigner sign --ks debug.keystore rebuilt-aligned.apk
apksigner verify rebuilt-aligned.apk
adb install -r rebuilt-aligned.apk
- Dynamic hooks when static stalls (runtime-decrypted strings, pinning, anti-tamper):
adb devices && frida-ps -U # device + process sanity
frida -U -f com.example.app -l hook.js # spawn + inject
frida-trace -U -f com.example.app -j '*!*certificate*'
Hook the Java layer first (javax.crypto.Cipher, MessageDigest, OkHttp, WebView, the
root/pinning checks); print arguments and returns before you start overriding them. Go to
native hooks only when the Java layer proves to be a JNI wrapper. Full pinning-bypass technique:
mobile-cert-pinning-bypass.
- Split to native when the
.so carries the real logic — signals: Java methods are thin JNI
wrappers, the signing/risk-control logic vanishes after System.loadLibrary(), or cert checks
live in native code. Find JNI entry points (JNI_OnLoad for dynamic registration via
RegisterNatives, Java_<pkg>_<class>_<method> for static) and continue with
reverse-eng-binary-triage on the extracted .so.
Gotchas
- Don't patch blind. Read the manifest and main entry first; never write hooks before you know
which class/method matters.
- jadx partial-failure is normal — it still emits usable output for the rest; switch to smali
or a second engine (JEB/Ghidra) for the broken classes.
- Signature scheme v2+ breaks on naive rezipping — always rebuild with
apktool b +
apksigner, never by hand-editing inside the zip.
- The app may detect the emulator/root/frida and refuse to run — bypass hooks are in
cheatsheet.md; confirm the bypass fired (the check logged) before trusting later observations.
- Malicious-sample tells (authorized triage only): transparent/hidden launcher icon,
service.d/priv-app persistence, remote curl|sh payloads. Record indicators as evidence —
never execute destructive commands.
- Clean up — uninstall patched builds and remove pushed frida-server when done.
Verify success
You can state: entry components and key classes; whether the critical logic lives in Java, smali,
or a .so; every confirmed sensitive point (login, signing, root, SSL, WebView, JNI); exactly
what any patch changed; and which class/method/export each hook covered — with the rebuilt APK
installed and behaving as the patch intended.
References
jadx & apktool documentation; Frida docs and CodeShare; OWASP MASTG.
Portions adapted from reverse-skill by zhaoxuya520, MIT License.
1---2name: mobile-apk-reverse3description: >4 Reverse an Android APK end-to-end — jadx/apktool unpacking, manifest and smali analysis,5 rebuild-sign-install patching, and Frida runtime hooks. Load when handed an .apk to understand,6 modify, or instrument: login/signing/risk-control logic, root or SSL-pinning checks, cert7 validation, embedded .so/JNI code. Signals: an APK in scope, "decompile/patch this app",8 smali, AndroidManifest.xml, jadx/apktool/frida/adb, System.loadLibrary, OkHttp/Retrofit.9domain: mobile10type: technique11stability: learning12modes: [pentest, bugbounty]13severity: medium14owasp: [M7:2024-Insufficient-Binary-Protections]15tools: [jadx, apktool, frida, adb, zipalign, apksigner, keytool]16schema_version: 117metadata:18 source: https://skillmd.com/skills/noorqureshi/mobile-apk-reverse19---2021# APK reversing (unpack → patch → hook)2223## When it applies24You have an APK and a device/emulator you're authorized to test (`tradecraft-scope-roe`,25`scope.txt`), and the job is mechanics: read the logic, locate a check, patch and repackage, or26hook the runtime. For the broader *what-to-test* coverage map, work `mobile-android-assessment`27alongside — this skill is the reverse-engineering toolchain it routes into.2829## Why it works30An APK is a zip of DEX bytecode plus resources. DEX decompiles to near-readable Java (jadx) and31round-trips losslessly through smali (apktool), so you can read at the Java level but patch at the32smali level and rebuild. Anything the app hides from static reading — decrypted strings, runtime33checks, pinning — yields to Frida instrumentation on a rooted/emulated device.3435## Method36> Ready-to-adapt Frida hook recipes (crypto, OkHttp, pinning, root/emulator/anti-debug bypass,37> storage): see [`cheatsheet.md`](cheatsheet.md) next to this file.38391. **Triage — unpack both ways before touching anything.**40 ```bash41 jadx -d jadx_out app.apk # readable Java view42 apktool d app.apk -o apktool_out # smali + resources + manifest43 ```44 Read `AndroidManifest.xml` first: package, main activity, exported components, permissions,45 and whether `lib/` ships `.so` files. Grep jadx_out for `login|sign|encrypt|cipher|token|root|46 certificate|trust|okhttp|retrofit|webview`.472. **Read the Java layer.** Start at `Application` and the launcher activity, then the48 auth/network/crypto classes and third-party SDK init. If jadx output is readable, locate the49 business logic here before going lower.503. **Drop to smali when jadx is incomplete or you need to patch.** In `apktool_out`: `smali*/`,51 `res/values/strings.xml`, the manifest. Prime patch targets: root-detection return values,52 login/cert-validation branches, debug flags, `android:exported`. jadx failing on a class does53 not mean the logic is unreadable — the smali is always there.544. **Rebuild, sign, install.**55 ```bash56 apktool b apktool_out -o rebuilt.apk57 zipalign -p 4 rebuilt.apk rebuilt-aligned.apk58 keytool -genkey -v -keystore debug.keystore -alias androiddebugkey \59 -keyalg RSA -keysize 2048 -validity 10000 # once; reuse it60 apksigner sign --ks debug.keystore rebuilt-aligned.apk61 apksigner verify rebuilt-aligned.apk62 adb install -r rebuilt-aligned.apk63 ```645. **Dynamic hooks when static stalls** (runtime-decrypted strings, pinning, anti-tamper):65 ```bash66 adb devices && frida-ps -U # device + process sanity67 frida -U -f com.example.app -l hook.js # spawn + inject68 frida-trace -U -f com.example.app -j '*!*certificate*'69 ```70 Hook the Java layer first (`javax.crypto.Cipher`, `MessageDigest`, OkHttp, WebView, the71 root/pinning checks); print arguments and returns before you start overriding them. Go to72 native hooks only when the Java layer proves to be a JNI wrapper. Full pinning-bypass technique:73 `mobile-cert-pinning-bypass`.746. **Split to native when the `.so` carries the real logic** — signals: Java methods are thin JNI75 wrappers, the signing/risk-control logic vanishes after `System.loadLibrary()`, or cert checks76 live in native code. Find JNI entry points (`JNI_OnLoad` for dynamic registration via77 `RegisterNatives`, `Java_<pkg>_<class>_<method>` for static) and continue with78 `reverse-eng-binary-triage` on the extracted `.so`.7980## Gotchas81- **Don't patch blind.** Read the manifest and main entry first; never write hooks before you know82 which class/method matters.83- **jadx partial-failure is normal** — it still emits usable output for the rest; switch to smali84 or a second engine (JEB/Ghidra) for the broken classes.85- **Signature scheme v2+ breaks on naive rezipping** — always rebuild with `apktool b` +86 `apksigner`, never by hand-editing inside the zip.87- **The app may detect the emulator/root/frida and refuse to run** — bypass hooks are in88 `cheatsheet.md`; confirm the bypass fired (the check logged) before trusting later observations.89- **Malicious-sample tells** (authorized triage only): transparent/hidden launcher icon,90 `service.d`/`priv-app` persistence, remote `curl|sh` payloads. Record indicators as evidence —91 never execute destructive commands.92- **Clean up** — uninstall patched builds and remove pushed frida-server when done.9394## Verify success95You can state: entry components and key classes; whether the critical logic lives in Java, smali,96or a `.so`; every confirmed sensitive point (login, signing, root, SSL, WebView, JNI); exactly97what any patch changed; and which class/method/export each hook covered — with the rebuilt APK98installed and behaving as the patch intended.99100## References101jadx & apktool documentation; Frida docs and CodeShare; OWASP MASTG.102103---104_Portions adapted from [reverse-skill](https://github.com/zhaoxuya520/reverse-skill) by zhaoxuya520, MIT License._