You can write a Frida script with an LLM in a few seconds, and it will usually look like something a mobile app pentester would paste into frida -U -f. The problem is what happens next. On current Frida (17.x), drafts that still call Module.getExportByName or Memory.readU32 throw TypeError: not a function. Drafts that guess the wrong module name, read an integer PIN as a C string, or hook only the second check in a short-circuiting && either crash the hook or stay silent while the app keeps denying access. An AI Frida hook is a draft until it has run against a binary where you already know the answer.
This guide runs that loop on a tiny C "license vault" we compiled on Linux under Frida 17.27.4: wrong PIN and wrong key still unlock once the hooks are fixed. Every error message and every success line below is real output from that lab. The drafts were written for this guide to reproduce mistakes models commonly make with the Frida JS API; they are not a captured model transcript, and no model was called in the lab.
For static reverse engineering with an LLM instead of live hooks, see GhidraMCP malware analysis and r2ai with radare2. For the broader authorized bug-bounty loop, see AI bug bounty workflow.
Authorized work only. Instrument your own app, a lab binary you built, or an in-scope bug-bounty / VDP target whose program permits dynamic instrumentation. Keep secrets, tokens and real user data out of prompts; see what to send the model.
Why write Frida scripts with an LLM
Frida scripts are short, and the public corpus is huge: CodeShare snippets, CTF writeups, and years of blog posts. Models have seen that corpus — including a lot of Frida 16-era JavaScript. Three failure modes show up constantly:
- APIs that no longer exist. Frida 17.0.0 removed the static
Module.findExportByName/Module.getExportByNamehelpers and the legacyMemory.readU32/Memory.writeU32style. Calling them today isTypeError: not a function. - Wrong process layout. A guessed module name (
vault.soinstead of the main executable), a symbol that was never exported, or an Android class name that does not exist in this APK. - Wrong types and control flow. Treating an
intas achar*, replacing a boolean return with a string pointer, or hooking only the second operand ofcheck_pin(pin) && verify_license(key)so a failing PIN never reaches the license hook.
The model is good at the boring parts: wrapping Interceptor.attach, remembering onEnter / onLeave, and sketching a Java.perform block from the docs. Only your process knows the real module list, export names and calling conventions. So the loop matters more than the prompt.
What changed in Frida 17 (verify before you prompt)
We re-checked the Frida 17.0.0 release notes and the live JavaScript API against Frida 17.27.4 (current on PyPI as of November 20, 2026). The breaks that hit LLM drafts hardest:
| Old habit (Frida 16 and earlier) | Current Frida 17+ |
|---|---|
Module.getExportByName('libc.so', 'open') | Process.getModuleByName('libc.so').getExportByName('open') |
Module.findExportByName(null, 'open') | Module.getGlobalExportByName('open') (or look up a module first) |
Module.getBaseAddress('libc.so') | Process.getModuleByName('libc.so').base |
Memory.readU32(ptr) / Memory.writeU32(ptr, n) | ptr.readU32() / ptr.writeU32(n) |
| Java / ObjC / Swift bridges always present in GumJS | Bridges are not bundled into compiled agents anymore; the Frida REPL and frida-trace still ship them for convenience (Bridges) |
Instance methods such as module.getExportByName(name) and module.findExportByName(name) still exist on Module objects — the static helpers are what went away. The Interceptor example in the docs now starts from Process.getModuleByName('libc.so') before Interceptor.attach.
The lab: a fake license vault under Frida 17.27.4
We used a Python venv, pip install frida-tools (Frida 17.27.4, frida-tools 14.13.2), and this throwaway C program:
/* vault.c — offline license check (lab build) */
#include <stdio.h>
#include <string.h>
int check_pin(int pin) {
return pin == 7431;
}
int verify_license(const char *key) {
return strcmp(key, "RED-ROUTER-2026-OK") == 0;
}
int main(void) {
char key[64];
int pin;
printf("vault: offline license check (lab build)\n");
printf("enter pin: "); fflush(stdout);
scanf("%d", &pin);
printf("enter license key: "); fflush(stdout);
scanf("%63s", key);
if (check_pin(pin) && verify_license(key)) {
printf("ACCESS GRANTED: vault unlocked\n");
return 0;
}
printf("ACCESS DENIED\n");
return 1;
}
Build (the -rdynamic flag matters — without it, check_pin / verify_license never appear in the dynamic export table, and getExportByName fails even when nm can see the symbols):
python3 -m venv venv && ./venv/bin/pip install frida-tools
gcc -O0 -fno-stack-protector -no-pie -rdynamic -o vault vault.c
Without hooks, wrong credentials deny as expected:
vault: offline license check (lab build)
enter pin: enter license key: ACCESS DENIED
We drove Frida by spawning ./vault with piped stdio from a small Python harness (frida.get_local_device().spawn(..., stdio="pipe"), then attach, create_script, resume, input). Attach to a running ./vault also worked on this box (/proc/sys/kernel/yama/ptrace_scope was absent). If attach is blocked in your environment, prefer spawn (frida -f) and document what your kernel actually does — do not invent a workaround in the prompt.
Step 1: Give the model real module and export names
Most bad hooks start with a guessed name. Before you ask the model to write anything, dump what Frida can see:
const main = Process.mainModule;
console.log('name=' + main.name + ' path=' + main.path + ' base=' + main.base);
for (const e of main.enumerateExports()) {
if (e.name.indexOf('check') >= 0 || e.name.indexOf('verify') >= 0)
console.log(e.type + ' ' + e.name + ' @ ' + e.address);
}
Lab output:
name=vault path=/workspace/seo/frida-lab/vault base=0x400000
function check_pin @ 0x401166
function verify_license @ 0x40117c
Paste those names (and the signature you recovered from the binary or headers) into the prompt. Do not paste the license string or other secrets — the model does not need the real PIN to draft a hook that logs arguments and replaces a return value.
Draft mistake 1: Frida 16 static Module helpers
A draft that still looks like every Frida 16 tutorial:
const check = Module.getExportByName(null, 'check_pin');
Interceptor.attach(check, {
onEnter(args) { console.log('pin=' + args[0].toInt32()); },
onLeave(retval) { retval.replace(1); }
});
Real Frida 17.27.4 error:
[draft1] loading with Module.getExportByName (Frida 16 style)
TypeError: not a function
at <eval> (/script1.js:6:37)
Module.findExportByName('libc.so', 'open') fails the same way. The fix from the release notes:
const check = Process.mainModule.getExportByName('check_pin');
// or: Process.getModuleByName('vault').getExportByName('check_pin')
// global C exports: Module.getGlobalExportByName('open')
Draft mistake 2: wrong module name
const mod = Process.getModuleByName('vault.so');
[draft2] looking up vault.so
Error: unable to find module 'vault.so'
On this lab binary the main module is literally named vault (Process.mainModule.name). Models often append .so or invent a package-style name. Feed Process.enumerateModules() output back into the next prompt.
Draft mistake 3: reading an int PIN as a string
Interceptor.attach(Process.mainModule.getExportByName('check_pin'), {
onEnter(args) {
const pin = args[0].readUtf8String(); // wrong: args[0] is the int
console.log('pin string="' + pin + '"');
}
});
[draft3] hooking check_pin at 0x401166
Error: access violation accessing 0x270f
0x270f is 9999 — the PIN we typed — treated as a pointer. The model "knew" readUtf8String from string-argument examples and applied it to an int. Use args[0].toInt32() for integer parameters; reserve readUtf8String / readCString for actual pointers.
Draft mistake 4: wrong export name
Process.mainModule.getExportByName('check_pincode');
[draft4] looking for check_pincode
Error: /workspace/seo/frida-lab/vault: unable to find export 'check_pincode'
Close names are not fuzzy. Re-run enumerateExports() (or enumerateSymbols() when the symbol is not exported) and paste the exact string.
Draft mistake 5: hooking only the second check (silent miss)
Interceptor.attach(Process.mainModule.getExportByName('verify_license'), {
onEnter(args) {
console.log('key="' + args[0].readUtf8String() + '"');
},
onLeave(retval) { retval.replace(1); }
});
With PIN 9999 and key WRONG-KEY, the lab printed:
[draft4b] only hooking verify_license at 0x40117c
vault: offline license check (lab build)
enter pin: enter license key: ACCESS DENIED
No hook log for verify_license. check_pin(pin) && verify_license(key) never calls the second function when the PIN fails. The draft "worked" as JavaScript and still left you denied. Models miss short-circuiting control flow constantly — plant a case where each hooked function must run, or hook both sides.
Draft mistake 6: legacy Memory.readU32
Interceptor.attach(Process.mainModule.getExportByName('check_pin'), {
onEnter(args) {
const pin = Memory.readU32(args[0]); // removed in Frida 17
}
});
[draft5] Interceptor with legacy Memory.readU32
TypeError: not a function
Same class of break as the static Module helpers. Current style is args[0].readU32() only when args[0] is actually a pointer to a uint32_t; for a by-value int, use toInt32().
The fixed AI Frida hook
'use strict';
const main = Process.mainModule;
console.log('[fixed] main module: ' + main.name + ' base=' + main.base);
const checkPin = main.getExportByName('check_pin');
const verifyLicense = main.getExportByName('verify_license');
console.log('[fixed] check_pin @ ' + checkPin);
console.log('[fixed] verify_license @ ' + verifyLicense);
Interceptor.attach(checkPin, {
onEnter(args) {
this.pin = args[0].toInt32();
console.log('[ai frida hook] check_pin(pin=' + this.pin + ')');
},
onLeave(retval) {
const before = retval.toInt32();
retval.replace(1);
console.log('[ai frida hook] check_pin -> ' + before + ' replaced with 1');
}
});
Interceptor.attach(verifyLicense, {
onEnter(args) {
this.key = args[0].readUtf8String();
console.log('[ai frida hook] verify_license(key="' + this.key + '")');
},
onLeave(retval) {
const before = retval.toInt32();
retval.replace(1);
console.log('[ai frida hook] verify_license -> ' + before + ' replaced with 1');
}
});
Spawned with the same wrong credentials (9999 / WRONG-KEY):
[fixed] main module: vault base=0x400000
[fixed] check_pin @ 0x401166
[fixed] verify_license @ 0x40117c
vault: offline license check (lab build)
enter pin: enter license key: [ai frida hook] check_pin(pin=9999)
[ai frida hook] check_pin -> 0 replaced with 1
[ai frida hook] verify_license(key="WRONG-KEY")
[ai frida hook] verify_license -> 0 replaced with 1
ACCESS GRANTED: vault unlocked
Attach produced the same unlock. That is the bar: the draft is not done when it looks right — it is done when the lab binary behaves the way you predicted.
Android Java.perform (docs only — no emulator on this box)
This lab box has no Android emulator or USB device, so we did not run a Java hook here. The API below is taken from the live JavaScript API and the Android examples, which you should re-check before you ship a script.
Java.perform(fn) attaches the current thread to the VM and runs fn once the app class loader is available. Inside it, Java.use('android.app.Activity') returns a wrapper whose methods can be replaced via .implementation. Overloads are selected explicitly, for example:
Java.perform(() => {
const Cipher = Java.use('javax.crypto.Cipher');
const init = Cipher.init.overload('int', 'java.security.Key');
init.implementation = function (opmode, key) {
console.log('Cipher.init opmode=' + opmode + ' key=' + key);
return init.call(this, opmode, key);
};
});
Two Frida 17 notes for mobile app pentest Frida work:
- REPL vs compiled agents. The Frida CLI REPL and
frida-tracestill bundle the Java bridge. Scripts you compile into a custom agent mustimport Java from "frida-java-bridge"and build withfrida-compile(Bridges). - Same draft discipline. Wrong class names, wrong overloads and missing
Java.performfail for the same reasons the native drafts failed above — feedJava.enumerateLoadedClasses/ overload lists back into the prompt, and only keep hooks you have exercised on a device or emulator you control.
For installing frida-server on a rooted device or emulator image, follow Frida's own Android guide; we are not repeating device setup here because we did not run it.
Automate the loop: draft, load, compare
The drafting side can call RedRouter's OpenAI-compatible endpoint. The base URL is https://redrouter.org/v1 and the key goes in a Bearer header, per the RedRouter quickstart. We did not have an API key on the lab box, so this half is a sketch:
from openai import OpenAI
import os, frida, time
client = OpenAI(base_url="https://redrouter.org/v1",
api_key=os.environ["REDROUTER_API_KEY"])
prompt = """Write a Frida 17 JS hook for Process.mainModule exports
check_pin(int) and verify_license(const char*). Log args, replace both
returns with 1. Do not use Module.getExportByName or Memory.readU32."""
draft = client.chat.completions.create(
model="glm-5.3-flash-red",
messages=[{"role": "user", "content": prompt}],
).choices[0].message.content
# Extract the JS, load it under spawn, compare stdout to "ACCESS GRANTED"
# Feed Frida's TypeError / access-violation text back into the next turn.
Keep the harness boring: spawn or attach, load the draft, feed known-bad credentials, assert on the process stdout and on Frida's error messages. Save only scripts that produce the planted outcome.
What to send the model
Send module names, export names, recovered C / JNI signatures, and the exact Frida error text. Do not send production license keys, session tokens, customer PII or traffic from out-of-scope apps. If the model needs an example string argument, use a placeholder.
On RedRouter, Zero Data Retention is an opt-in setting and off by default. The data handling docs explain what's stored when content storage is on, how API-key content storage works, and how to turn ZDR on. Our security page covers how we handle security workloads.
Which model to use
For drafting Frida scripts, we'd start with GLM 5.3 Flash Red (glm-5.3-flash-red). On docs.redrouter.org/models it lists at $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens, with a 1,048,576-token context window. A draft-and-fix round like the one above is a few thousand tokens. If the hook is part of a broader authorized mobile app pentest or red-team engagement, red-cyber-1 (Beta) lists at $0.28 / $0.13 / $1.10 per 1M. Plans are on /pricing. Check the models page for current rates before you budget.
Common LLM Frida mistakes
- Frida 16 static APIs —
Module.getExportByName,Module.findExportByName,Memory.readU32. - Guessed module names —
.sosuffixes, package names, or Android library names that are not loaded yet. - Type confusion —
readUtf8Stringon integers;toInt32on string pointers you still need to dereference. - Wrong export / class / overload — close spellings fail hard; overloads need the full JNI-style signature list.
- Short-circuit blindness — hooking only the second
&&operand, or only a method that is never called on the denial path. - Assuming bridges in compiled agents — Java/ObjC/Swift need an explicit bridge import outside the REPL.
- Skipping the lab — a script that "looks right" but was never loaded under
frida -forattach.
Validation checklist
- [ ] Frida version recorded (
frida --version); docs matched to that major. - [ ] Module and export names came from
Process.mainModule/enumerateExports, not from memory. - [ ] No static
Module.getExportByName/findExportByName/ legacyMemory.read*. - [ ] Integer args use
toInt32(); pointer args usereadUtf8String/readPointeras appropriate. - [ ] Both sides of short-circuiting checks are exercised with planted inputs.
- [ ] Attach or spawn path tested; failures (ptrace, SELinux, missing
frida-server) written down honestly. - [ ] Android:
Java.perform+ exact overload confirmed on a device/emulator you control. - [ ] Prompts contain no secrets; ZDR left as an opt-in decision for the engagement.
FAQ
Can an LLM write a Frida script that works the first time?
Sometimes, on APIs that have been stable for years. On Frida 17, first drafts that copy Frida 16 snippets fail immediately. Treat every script as a draft until it runs against a lab binary or in-scope app you control.
How do I write a Frida script with an LLM for a mobile app pentest?
Recover class and method names from the APK (or from Java.enumerateLoadedClasses on a device), ask for a Java.perform hook with an explicit .overload(...), and load it with frida -U -f <package> -l hook.js only against apps you own or that are in scope. Keep tokens and user data out of the prompt.
Why does my AI Frida hook throw TypeError: not a function?
Almost always a Frida 17 break: static Module.getExportByName / findExportByName, or Memory.readU32 / Memory.writeU32. Switch to Process.getModuleByName(...).getExportByName(...) and pointer methods like readU32().
Why did my license bypass hook do nothing?
Common causes from this lab: wrong module name, export not in the dynamic table (missing -rdynamic on a toy binary, or stripped/hidden exports on a real one), or short-circuiting so the hooked function never runs. Log onEnter on every function in the check chain.
Do I need frida-compile for Java hooks?
Not for one-off REPL work — the Frida CLI still bundles the Java bridge. For compiled custom agents on Frida 17+, yes: import frida-java-bridge and compile with frida-compile as described in the Bridges docs.
Is it safe to paste Frida session output into an LLM prompt?
Paste module lists, export names, signatures and error strings. Do not paste captured credentials, session cookies, or traffic from targets outside your authorization. Use Zero Data Retention only when your engagement requires it; it is opt-in and off by default — see the data handling docs.
Related guides
Sources
- Frida 17.0.0 release notes: Runtime bridges, legacy Memory APIs, static Module helpers removed. Checked November 20, 2026.
- Frida Docs: JavaScript API, Bridges, Android, Android examples, Installation, Frida CLI, Modes of operation. Checked November 20, 2026.
- Frida release tag used in the lab: 17.27.4. frida-tools on PyPI. Checked November 20, 2026.
- RedRouter Docs: Quickstart, Models and pricing, Data handling. Checked November 20, 2026.
- Tool outputs: Frida 17.27.4 + frida-tools 14.13.2 in a Python 3.13 venv on Linux x86_64; lab binary
vaultbuilt with gcc 14.2.0 (-O0 -fno-stack-protector -no-pie -rdynamic); spawn and attach both exercised on localhost.