弗里达跟踪者

其他 社区

技能解读

当前原文的自动摘译,尚未人工审校。

概述

当您需要使用 Frida 的 Stalker API 跟踪 Android 上的本机代码执行时,请使用此技能,并使用适合 ARM/ARM64 和性能安全默认值的模板。此技能假定 Frida 17+ JavaScript 语义。

何时使用此技能

用户在 Android 上明确请求“Frida Stalker”。您需要以较低的开销来测量本机呼叫活动(谁被呼叫,多久一次)。您需要有序的调用事件(调用图重建)或粗略覆盖。您需要通过transform(iterator)在基本块编译上注入逻辑。

快速决策指南

想要每个目标的调用计数并且不关心顺序:使用onCallSummary。想要有序的调用/ret/阻止/编译事件:使用onReceive并使用Stalker.parse()解码。想要指令级匹配和标注:使用transform(iterator)(重;缩小范围)。想要观看一小组调用目标​​:考虑Stalker.addCallProbe()。

核心 API 事实(Frida 17+)

Stalker.follow([threadId, options]) 只提供一个回调:onReceive(events) 或 onCallSummary(summary)。 Stalker.unfollow([threadId]) Stalker.parse(events, { annotate, stringify }) Stalker.flush() 尽早排出缓冲事件(否则定期排出由Stalker.queueDrainInterval控制)。

工作流程

定义目标。选择线程。选择捕捉模式和滤镜。选择一个模板并对其进行调整。运行、调整性能和清理。

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
通用
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@yfe404 · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
需简单配置
是否需要外部接口密钥
不需要
兼容的系统
Windows
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
  • 命令执行
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# Frida Stalker (Android)

## Overview

Use this skill when you need to trace native code execution on Android using Frida's `Stalker` API, with templates geared for ARM/ARM64 and performance-safe defaults.

This skill assumes Frida 17+ JavaScript semantics.

## When To Use This Skill

- User explicitly asks for "Frida Stalker" on Android.
- You need to measure native call activity (who got called, how often) with low overhead.
- You need ordered call events (call graph reconstruction) or coarse coverage.
- You need to inject logic on basic-block compilation through `transform(iterator)`.

## Quick Decision Guide

- Want call counts per target and don't care about ordering: use `onCallSummary`.
- Want ordered call/ret/block/compile events: use `onReceive` and decode with `Stalker.parse()`.
- Want instruction-level matching and callouts: use `transform(iterator)` (heavy; do it narrowly).
- Want to watch a small set of call targets: consider `Stalker.addCallProbe()`.

## Core API Facts (Frida 17+)

- `Stalker.follow([threadId, options])`
- Provide exactly one callback: `onReceive(events)` or `onCallSummary(summary)`.
- `Stalker.unfollow([threadId])`
- `Stalker.parse(events, { annotate, stringify })`
- `Stalker.flush()` drains buffered events early (otherwise periodic draining is controlled by `Stalker.queueDrainInterval`).
- `Stalker.garbageCollect()` should be called after `unfollow()` to free accumulated memory at a safe point.
- `Stalker.exclude({ base, size })` excludes a memory range from stalking (useful to skip noisy/system modules).
- Tuning:
- `Stalker.trustThreshold` default `1` (set `-1` for no trust, `0` to trust immediately, or `N` to trust after `N` executions).
- `Stalker.queueCapacity` default `16384` events.
- `Stalker.queueDrainInterval` default `250` ms (set `0` to disable periodic draining and call `Stalker.flush()` manually).

## Workflow

1. Define objective.
2. Choose thread(s).
3. Choose capture mode and filters.
4. Pick a template and adapt it.
5. Run, tune performance, and clean up.

If you are using the Frida MCP tools, also enable `$frida-mcp-workflow` and follow its phases (Idea -> Scripting -> Execution -> Notes).

## Templates

Start from these and keep scripts file-based.

- `templates/stalker-call-summary.js`: low-overhead call counting via `onCallSummary`.
- `templates/stalker-onreceive-parse.js`: receive binary events and decode with `Stalker.parse()`.
- `templates/stalker-start-stop-around-hook.js`: follow/unfollow only during a specific hooked function call.
- `templates/stalker-call-probe.js`: observe calls to a single target via `Stalker.addCallProbe()`.
- `templates/stalker-transform-skeleton.js`: minimal `transform(iterator)` skeleton with ARM/ARM64 safety check.
- `templates/stalker-filter-modules.js`: helper to select "app modules" on Android and exclude the rest.

## Quick Start

1. If you do not know the thread id yet, start with `templates/stalker-start-stop-around-hook.js`.
2. If you already know the thread id and want low overhead, use `templates/stalker-call-summary.js`.
3. If you need ordered events, use `templates/stalker-onreceive-parse.js` and keep event types narrow.
4. If you only care about calls to one target, start with `templates/stalker-call-probe.js`.

## MCP Usage Notes (If Available)

When driving this through the Frida MCP tools, prefer this flow:

1. Create or attach a session (`mcp__frida__create_interactive_session` / `mcp__frida__attach_to_process`).
2. Load the selected template with `mcp__frida__load_script`.
3. Start tracing through RPC exports using `mcp__frida__call_rpc_export` (templates expose `start()` / `stop()` when appropriate).
4. Use `mcp__frida__get_session_messages` to consume output.

Keep a script ledger (what is loaded, purpose, and teardown path). This is enforced by `$frida-mcp-workflow`.

## Android-Specific Notes (Practical)

- Thread choice matters more than you think.
- If you start stalking the wrong thread, you will see nothing, or only system noise.
- A safe pattern is to start stalking from inside an `Interceptor.attach()` callback, using `Process.getCurrentThreadId()` to capture the thread that is actually executing your target function.

- Module filtering is essential.
- On Android, app code is usually in modules whose `path` contains `/data/app/`, `/data/data/`, or an extracted APK split path.
- Exclude common noise sources (`libart.so`, `libc.so`, `liblog.so`, etc.) using `Stalker.exclude()` when you only care about your app's own native libs.

- 32-bit ARM note.
- If you use raw addresses on 32-bit ARM, Thumb functions require the low bit set. Prefer addresses returned by Frida APIs like `Process.getModuleByName(...).getExportByName(...)`.

- Avoid `Process.runOnThread()` unless you know what you're doing.
- It can interrupt a thread in non-reentrant code and cause deadlocks/crashes.

## Performance Rules Of Thumb

- Avoid `events.exec` unless you truly need instruction-level traces. It produces huge volumes of data.
- Prefer `onCallSummary` over `onReceive` when you can.
- Keep your callbacks lean; push heavy work to the host side when possible.
- Use `Stalker.exclude()` aggressively to reduce time spent in system libraries.
- Prefer manual draining (`Stalker.queueDrainInterval = 0` + `Stalker.flush()`) when you need deterministic windows.
- Call `Stalker.garbageCollect()` after unfollowing, especially if you repeatedly start/stop.

## Cleanup Checklist

- `Stalker.unfollow(threadId)`
- `Stalker.flush()`
- `Stalker.garbageCollect()`

## Troubleshooting

- No output at all.
- You are likely stalking the wrong thread, or your callback isn't being invoked (e.g., you followed a thread that never runs).

- Output is only system noise.
- Add module filters and exclusions. Start stalking from inside a hook where you know you're in app code.

- Target slows to a crawl or dies.
- Reduce enabled events, stop using `exec`, and switch to `onCallSummary`. Exclude large/noisy modules.

For deeper notes, see:
- `references/stalker-api.md`
- `references/android-filtering.md`

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。