Frida Android Hooks
Use this skill when instrumenting Android Java/Kotlin/JNI behavior.
Setup Checks
- Verify host and device versions match:
frida --version
adb shell /data/local/tmp/frida-server --version
frida-ps -Uai
- Use spawn for early initialization:
frida -U -f com.example.app -l agent.js --no-pause
- Use attach for behavior reachable after app startup:
frida -U -n com.example.app -l agent.js
Java Hook Pattern
Java.perform(() => {
const Target = Java.use("com.example.Target");
Target.method.overload("java.lang.String").implementation = function (value) {
console.log("[Target.method]", value);
const result = this.method(value);
console.log("[Target.method] ->", result);
return result;
};
});
Android Rules
- Always hook inside
Java.perform() unless only native APIs are used.
- Resolve overloads explicitly. Do not rely on ambiguous method names.
- Hook constructors through
$init.
- For Kotlin, expect companion classes, synthetic methods, default-argument helpers, and obfuscated names.
- If a class is not found, inspect class loaders and set
Java.classFactory.loader to the app loader that can see it.
- For native methods, bridge to
frida-native-hooks after identifying the loaded .so and JNI symbol.
Practitioner Patterns
- For obfuscated code, hook meaningful platform boundaries first: URL/request builders, JSON parsers, Base64, crypto, SharedPreferences, keystore, file I/O, WebView, class loading, and native library loading.
- Log Java stack traces on high-signal hooks to find the app-owned caller before writing app-specific hooks.
- Convert byte arrays deliberately. Print both hex and UTF-8/ASCII only when valid; binary crypto material is often not text.
- Hook reflection and dynamic loading when classes appear late:
Class.forName, ClassLoader.loadClass, DexClassLoader, PathClassLoader, and Runtime.loadLibrary*.
- For TLS/pinning, identify the actual stack before bypassing: OkHttp/CertificatePinner, TrustManager, Conscrypt, WebView, Flutter/BoringSSL, or native custom validation.
- For root/emulator/integrity bypasses, avoid blind mega-scripts as the final answer. Use them to reveal checks, then keep the smallest hooks that change the target behavior.
Discovery Snippets
Java.perform(() => {
const groups = Java.enumerateMethods("*crypto*!*/isu");
console.log(JSON.stringify(groups, null, 2));
});
Java.perform(() => {
Java.enumerateClassLoaders({
onMatch(loader) {
try {
Java.classFactory.loader = loader;
Java.use("com.example.Target");
console.log("loader:", loader);
} catch (_) {}
},
onComplete() {}
});
});
Pinning and Auth Work
- Treat public bypass snippets as reconnaissance, not final proof.
- Identify the actual trust path: platform trust manager, OkHttp, Conscrypt, WebView, native TLS, custom signature, or backend challenge.
- Log inputs/outputs before replacing trust decisions.
- Preserve evidence: hooked class, stack trace, endpoint, certificate or hash material observed, and app version.
References
Read references/android-patterns.md for overload, constructor, class-loader, JNI, OkHttp, WebView, and spawn timing patterns.
1---2name: frida-android-hooks3description: Create and debug Frida hooks for Android apps, including Java.perform, overloads, constructors, class loaders, Kotlin, JNI, pinning, spawn, and Gadget.4---56# Frida Android Hooks78Use this skill when instrumenting Android Java/Kotlin/JNI behavior.910## Setup Checks11121. Verify host and device versions match:13 ```bash14 frida --version15 adb shell /data/local/tmp/frida-server --version16 frida-ps -Uai17 ```182. Use spawn for early initialization:19 ```bash20 frida -U -f com.example.app -l agent.js --no-pause21 ```223. Use attach for behavior reachable after app startup:23 ```bash24 frida -U -n com.example.app -l agent.js25 ```2627## Java Hook Pattern2829```js30Java.perform(() => {31 const Target = Java.use("com.example.Target");32 Target.method.overload("java.lang.String").implementation = function (value) {33 console.log("[Target.method]", value);34 const result = this.method(value);35 console.log("[Target.method] ->", result);36 return result;37 };38});39```4041## Android Rules4243- Always hook inside `Java.perform()` unless only native APIs are used.44- Resolve overloads explicitly. Do not rely on ambiguous method names.45- Hook constructors through `$init`.46- For Kotlin, expect companion classes, synthetic methods, default-argument helpers, and obfuscated names.47- If a class is not found, inspect class loaders and set `Java.classFactory.loader` to the app loader that can see it.48- For native methods, bridge to `frida-native-hooks` after identifying the loaded `.so` and JNI symbol.4950## Practitioner Patterns5152- For obfuscated code, hook meaningful platform boundaries first: URL/request builders, JSON parsers, Base64, crypto, SharedPreferences, keystore, file I/O, WebView, class loading, and native library loading.53- Log Java stack traces on high-signal hooks to find the app-owned caller before writing app-specific hooks.54- Convert byte arrays deliberately. Print both hex and UTF-8/ASCII only when valid; binary crypto material is often not text.55- Hook reflection and dynamic loading when classes appear late: `Class.forName`, `ClassLoader.loadClass`, `DexClassLoader`, `PathClassLoader`, and `Runtime.loadLibrary*`.56- For TLS/pinning, identify the actual stack before bypassing: OkHttp/CertificatePinner, TrustManager, Conscrypt, WebView, Flutter/BoringSSL, or native custom validation.57- For root/emulator/integrity bypasses, avoid blind mega-scripts as the final answer. Use them to reveal checks, then keep the smallest hooks that change the target behavior.5859## Discovery Snippets6061```js62Java.perform(() => {63 const groups = Java.enumerateMethods("*crypto*!*/isu");64 console.log(JSON.stringify(groups, null, 2));65});66```6768```js69Java.perform(() => {70 Java.enumerateClassLoaders({71 onMatch(loader) {72 try {73 Java.classFactory.loader = loader;74 Java.use("com.example.Target");75 console.log("loader:", loader);76 } catch (_) {}77 },78 onComplete() {}79 });80});81```8283## Pinning and Auth Work8485- Treat public bypass snippets as reconnaissance, not final proof.86- Identify the actual trust path: platform trust manager, OkHttp, Conscrypt, WebView, native TLS, custom signature, or backend challenge.87- Log inputs/outputs before replacing trust decisions.88- Preserve evidence: hooked class, stack trace, endpoint, certificate or hash material observed, and app version.8990## References9192Read `references/android-patterns.md` for overload, constructor, class-loader, JNI, OkHttp, WebView, and spawn timing patterns.