agentleFS
Rudra-raviRudra-ravi/frida-skills/frida-native-hooks/SKILL.md

frida-native-hooks

Skill3 starsChanged 6 months agoMITView on GitHub

Build Frida native hooks for C/C++/Objective-C functions, exports, imports, symbols, memory, Interceptor, NativeFunction, Stalker, and CModule.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when the target is a native function or memory behavior.

    line 8
  2. Distinctive:

    If names are stripped, search imports/exports first, then symbols, strings, and byte patterns.

    line 22
  3. Very specific:

    Use Interceptor.attach() for tracing and light argument/return mutation.

    line 43
  4. Very specific:

    Use Interceptor.replace() when fully replacing behavior.

    line 44
  5. Very specific:

    Use Interceptor.replaceFast() only for hot functions where lower overhead is required.

    line 45
  6. Very specific:

    Call Interceptor.flush() only when a just-installed hook must be invoked immediately from the same script.

    line 47
  7. Distinctive:

    When names are stripped, combine static strings, imports, cross-references from a disassembler, runtime module load logs, and …

    line 52
  8. Very specific:

    Use Thread.backtrace() early to find who called a generic boundary such as open, connect, SSL_write, CCCrypt, strcmp, or memcmp.

    line 53
  9. Distinctive:

    Use Stalker for bounded questions only: a specific thread, during a specific function call, with call/block summaries before …

    line 54
  10. Very specific:

    Treat anti-Frida checks as native work when they involve /proc, ptrace, loaded module scans, thread names, ports, or symbol/string scans.

    line 55
  11. Distinctive:

    Do not write a longer string into an existing buffer unless the buffer size is proven.

    line 59
  12. Distinctive:

    Prefer allocating a new string and replacing the pointer argument.

    line 60
  13. Distinctive:

    Keep allocated replacement strings reachable for the required lifetime:

    line 61
  14. Very specific:

    Read references/native-patterns.md for templates covering exports, imports, pattern scans, backtraces, replacements, and performance notes.

    line 84

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Frida Native Hooks

Use this skill when the target is a native function or memory behavior.

Discovery First

  1. Identify process architecture and module:
    console.log(Process.arch, Process.platform, Process.pointerSize);
    for (const m of Process.enumerateModules()) console.log(m.name, m.base, m.size);
  2. Resolve addresses through Frida APIs when possible:
    const mod = Process.getModuleByName("libtarget.so");
    const fn = mod.getExportByName("target_function");
  3. If names are stripped, search imports/exports first, then symbols, strings, and byte patterns.
  4. On ARM/Thumb, prefer addresses returned by Frida APIs so instruction-set details are handled correctly.

Hook Pattern

const target = Process.getModuleByName("libc.so").getExportByName("open");

Interceptor.attach(target, {
  onEnter(args) {
    this.path = args[0].readUtf8String();
    console.log("[open] path=", this.path);
  },
  onLeave(retval) {
    console.log("[open] fd=", retval.toInt32());
  }
});

Replacement Rules

  • Use Interceptor.attach() for tracing and light argument/return mutation.
  • Use Interceptor.replace() when fully replacing behavior.
  • Use Interceptor.replaceFast() only for hot functions where lower overhead is required; call the original through the returned pointer.
  • Wrap original functions with NativeFunction using the correct ABI, return type, and argument types.
  • Call Interceptor.flush() only when a just-installed hook must be invoked immediately from the same script.

Practitioner Patterns

  • Hook boundaries before internals: exported API, imported libc/crypto/TLS calls, file/network/syscall wrappers, then app-specific stripped functions.
  • When names are stripped, combine static strings, imports, cross-references from a disassembler, runtime module load logs, and Stalker/caller summaries.
  • Use Thread.backtrace() early to find who called a generic boundary such as open, connect, SSL_write, CCCrypt, strcmp, or memcmp.
  • Use Stalker for bounded questions only: a specific thread, during a specific function call, with call/block summaries before instruction-level tracing.
  • Treat anti-Frida checks as native work when they involve /proc, ptrace, loaded module scans, thread names, ports, or symbol/string scans.

Memory Safety

  • Do not write a longer string into an existing buffer unless the buffer size is proven.
  • Prefer allocating a new string and replacing the pointer argument.
  • Keep allocated replacement strings reachable for the required lifetime:
    const keepalive = [];
    Interceptor.attach(target, {
      onEnter(args) {
        const s = Memory.allocUtf8String("replacement");
        keepalive.push(s);
        args[0] = s;
      }
    });
  • Copy retval/argument data inside callbacks if it is needed later.

Native Investigation Checklist

  • Module loaded before resolving address.
  • Function signature verified from headers, decompiler, debug symbols, or observed calling convention.
  • Pointer reads guarded for null and readability.
  • Logs include enough context to prove the right call path.
  • Mutation has a rollback path: detach, revert, restart, or remove Gadget config.

References

Read references/native-patterns.md for templates covering exports, imports, pattern scans, backtraces, replacements, and performance notes.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.