Back to skills
SKILL.md
So Jni Triage
ASecurityStructured static and dynamic analysis workflow for Android Native SO libraries (JNI_OnLoad, RegisterNatives, .init_array string encryption, OLLVM, and Unidbg/Stalker tracing). Use when reversing Android .so files, locating native signature/encryption routines with IDA Pro/Ghidra/Frida/Unidbg MCPs, or avoiding token blowups on OLLVM control-flow flattened functions.
- 5 stars
- 0 votes
- 0 copies
- 0 views
- Added December 1, 2026
Works with
Security analysis
100/100Pro scans all 3 files and shows the line behind each finding
npx -y skills add muyang520/awesome-mobile-re-mcp-skills --skill so-jni-triage --agent claude-codeAre you the author of So Jni Triage?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/muyang520-so-jni-triage)---
name: so-jni-triage
description: >-
Structured static and dynamic analysis workflow for Android Native SO libraries (JNI_OnLoad, RegisterNatives, .init_array string encryption, OLLVM, and Unidbg/Stalker tracing).
Use when reversing Android .so files, locating native signature/encryption routines with IDA Pro/Ghidra/Frida/Unidbg MCPs,
or avoiding token blowups on OLLVM control-flow flattened functions.
---
# Android Native SO & JNI Reverse Engineering Triage SOP
Reversing commercial Android `.so` libraries fails when an AI agent dumps thousands of lines of OLLVM-flattened pseudocode into context or searches static strings that haven't been decrypted by `.init_array` yet. Follow this **5-stage precision workflow** across static (`ida-pro-mcp` / `GhidraMCP`) and dynamic (`frida` / `Unidbg` / `trace-ui`) tools.
---
## Stage 1: Binary Fingerprinting & Packer Triage (30 Seconds)
Run the bundled zero-dependency ELF scanner first (parses `PT_DYNAMIC` even if section headers are stripped, lists `.init_array` constructors, static `Java_*` exports, and scans AES/SM4/SHA256/ChaCha20/TEA constants):
```bash
python skills/so-jni-triage/scripts/elf_so_triage.py libtarget.so --json
```
- **Bundled Helpers**: [elf_so_triage.py](./scripts/elf_so_triage.py) · [frida17_jni_and_init_tracer.js](./scripts/frida17_jni_and_init_tracer.js)
Before decompiling anything, inspect ELF metadata (`elf_so_triage.py`, `readelf -d`, `rabin2 -I`, or IDA Segments):
1. **Architecture**: Prioritize `arm64-v8a` (`AArch64`) over `armeabi-v7a`—64-bit registers (`X0–X7` args, `X0` return) produce cleaner decompiler output in IDA Hex-Rays and Ghidra.
2. **Section / Segment Anomalies**:
- Missing section headers or custom PT_LOAD segments + tiny `JNI_OnLoad` stub -> **SO Packer / Section Encryption** (`UPX` modified, commercial SO shell). **Stop static analysis**: dump the SO from `/proc/<pid>/maps` in memory *after* `JNI_OnLoad` finishes, then fix ELF headers (`SoFixer`).
3. **`.init_array` / `DT_INIT` Check**:
- Inspect `.init_array` entries first! Compiler obfuscators (`Hikari`, `OLLVM`, `datadiv_decode`) decrypt global C-strings inside `.init_array` constructors. Static string searches in IDA will return garbage until either `.init_array` is emulated or strings are read dynamically at runtime.
---
## Stage 2: Fast JNI Entrypoint Resolution (`Static` vs `RegisterNatives`)
Locate the exact native function pointer backing the target Java `native` method:
1. **Case A — Static Symbol Export**:
- Check exports matching `Java_<pkg>_<Class>_<method>`. Note JNI escaping (`_1` = `_`, `_2` = `;`, `_3` = `[`).
2. **Case B — Dynamic Registration (`RegisterNatives` in `JNI_OnLoad`)**:
- `JNINativeMethod` layout on **ARM64** (24 bytes per entry):
```c
typedef struct {
const char* name; // +0x00 (8 bytes): Java method name
const char* signature; // +0x08 (8 bytes): JNI descriptor, e.g. "(Ljava/lang/String;[B)[B"
void* fnPtr; // +0x10 (8 bytes): Native implementation address!
} JNINativeMethod;
```
- If `JNI_OnLoad` is heavily obfuscated, **do NOT trace it manually in IDA**. Run this Frida 16/17 `RegisterNatives` resolver to print the exact `module + static offset` in 2 seconds:
```javascript
function hookRegisterNatives(targetSoName) {
let regPtr = null;
// Locate RegisterNatives from libart.so symbols (non-JNI-env dependent)
const artSyms = Process.getModuleByName("libart.so").enumerateSymbols();
for (const sym of artSyms) {
if (sym.name.includes("RegisterNatives") && !sym.name.includes("CheckJNI")) {
regPtr = sym.address;
break;
}
}
if (!regPtr) {
console.log("[!] RegisterNatives symbol not found in libart.so");
return;
}
Interceptor.attach(regPtr, {
onEnter(args) {
const javaClass = Java.vm.tryGetEnv().getClassName(args[1]);
const methodsPtr = args[2];
const count = args[3].toInt32();
const pSize = Process.pointerSize;
for (let i = 0; i < count; i++) {
const entry = methodsPtr.add(i * pSize * 3);
const name = entry.readPointer().readCString();
const sig = entry.add(pSize).readPointer().readCString();
const fnPtr = entry.add(pSize * 2).readPointer();
const mod = Process.findModuleByAddress(fnPtr);
if (mod && (!targetSoName || mod.name.includes(targetSoName))) {
const offset = fnPtr.sub(mod.base);
console.log(`[JNI] ${javaClass}.${name}${sig} => ${mod.name}!${offset} (runtime=${fnPtr})`);
}
}
}
});
}
```
---
## Stage 3: Anti-Token-Blowup Rule for OLLVM Functions
When `ida-pro-mcp` or `GhidraMCP` decompiles `sub_XXXXXX` and you see:
- Giant `while (1)` + `switch (state_var)` state-machine dispatcher with 100+ cases (**Control Flow Flattening / FLA**), OR
- Opaque predicates (`((x * (x + 1)) & 1) == 0` — **BCF**), OR
- Instruction substitution (`a + b` rewritten as `(a ^ b) + 2 * (a & b)` — **SUB**):
**STOP calling `decompile_function` repeatedly on giant flattened functions** (wastes 20k–50k tokens and causes hallucinated control flow). Instead, pivot immediately to **Anchor-Driven + Trace-Driven Analysis**:
1. **Hook Input/Output Boundaries First**: Hook `mod.base.add(offset)` via Frida `Interceptor.attach`, feed **known deterministic inputs** (e.g., `"123456"`, `""`, `"a"`), and check if changing 1 bit of input changes output deterministically or includes timestamp/nonce/device-ID.
2. **Scan Standard Crypto Constants & JNI Calls**:
- Search `.rodata` / runtime memory for AES S-Box (`63 7c 77 7b f2 6b 6f c5`), SHA-256 IV (`67 e6 09 6a`), MD5 IV (`01 23 45 67`), or Base64 custom alphabets (`64`-byte printable tables).
- Trace JNI `JNIEnv` callbacks (`GetStringUTFChars`, `GetByteArrayElements`, `NewStringUTF`, `CallObjectMethod`)—data right before/after `JNIEnv` transitions is almost always plaintext or final signature!
3. **Instruction/Block Trace (`Unidbg` + `WebTraceView` / `trace-ui` MCP or `Frida Stalker`)**:
- Emulate the SO in **Unidbg** (`zhkl0228/unidbg`) to get a reproducible environment without anti-Frida `ptrace`/`/proc/self/task` checks.
- Load the trace into `imj01y/trace-ui` or `misslng/WebTraceView` MCP and perform **backward taint / memory write lookup** from the final output buffer back to the key schedule and plaintext assembly!
---
## Stage 4: Common Native Anti-Debugging / Anti-Frida Checkpoints
If attaching Frida kills the app (`SIGSEGV` / `SIGABRT` / `exit_group`):
1. Hook `pthread_create` (`libc.so`) in spawn mode and log `(thread_fn - mod.base)` for every thread spawned inside the target SO during `.init_array` and `JNI_OnLoad`.
2. Inspect `openat` / `fopen` / `fgets` calls reading `/proc/self/maps` (`frida-agent`), `/proc/self/status` (`TracerPid`), `/proc/self/task/<tid>/stat` (`gmain`, `gum-js-loop`, `pool-frida`), and raw `svc #0` ARM64 inline syscalls (`__NR_openat = 56`, `__NR_read = 63`, `__NR_exit_group = 94`).
Files in this skill
- SKILL.md
- scripts/elf_so_triage.py
- scripts/frida17_jni_and_init_tracer.js
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.