Runtime

Writing hooks

A hook is a runtime instrument the Rutken bespoke agent installs inside a running Android app: it binds to a specific method or function and, each time that site runs, either observes what passed through it or changes it. This guide covers the whole authoring surface — how a hook is chosen (the analyzer derives one, you request one by name, or you hand-author an install), the authorization gate that separates watching from changing, the full pack-symbol catalog, the mutation tier that persists a change, and how to do all of it from the GUI. Every symbol and rule here is taken from the agent source, not invented.

What a hook is

Rutken's static engine reads an app's code and emits findings. A hook is the dynamic counterpart: it runs inside the live app and reports what actually happened at a chosen site. The bespoke agent is Rutken's own in-house hooking engine — it rewrites the target function's prologue to a trampoline, so a hook is real instrumentation, not a log scrape.

Every hook is one of two kinds:

  • Observe. The hook watches a site and records what passed through it — an argument, a return value, a file mode — and changes nothing. This is the default, and the only kind allowed without an escalating acknowledgement.
  • Change (persist a change). The hook rewrites what the app's own code sees or returns: an argument before the method reads it, a return value before the caller sees it, or an instance field. These are the mutation tier, and they are gated (see below).

A hook is armed only when it corroborates a finding this target actually has; a hook with nothing to confirm on this app is shown as watch, not armed. That distinction matters: an armed hook that never fires is evidence of absence, while a watch hook that never fires simply had no reason to.

Hooks are not plugins. A plugin is a static rule pack — pure JSON data evaluated against the app's code. A hook is runtime instrumentation installed into a running process on a device or emulator. They are authored and run completely differently.

Authorization: watch vs change

The agent is capability-gated. You only ever test an app you are authorized to test, and the agent makes the line between watching and changing structural, not advisory.

AcknowledgementCapabilityWhat it allows
--bespoke-authorize / --bespoke-ack Observation Install and fire observe hooks. No mutation site will arm.
--i-am-authorized-bespoke-active ActiveAppTesting Additionally arm hooks that change the app: argument mutation, return override, return-value transform, field write.

Without the active acknowledgement, every change-the-app site refuses by name — the run proceeds with those hooks left as observation only. The active ack never falls through a default: a symbol the agent does not recognise as safe is fail-closed, never silently granted mutation.

Three ways to choose hooks

A hook run is rutken <apk> run --bespoke … against a connected device or emulator. There are three ways to decide which hooks to install, and they are mutually exclusive.

1. Derived — let the analyzer choose (recommended)

--bespoke-derived computes the hook set from this app's own findings. The static engine already read the APK, so it knows which TLS stack, which crypto calls, and which root checks are present, and it installs exactly the hooks that could corroborate them. This is the path that keeps hooks and findings in lock-step.

rutken app.apk run --bespoke --bespoke-derived \
  --bespoke-authorize "pentest: acme-engagement-2026"

Optional refinement passes compose on top of derivation (each requires --bespoke-derived):

  • --bespoke-hierarchy-seeds — a second pass that follows class-hierarchy seeds to reach subclasses the first pass missed.
  • --bespoke-force-void-trust, --bespoke-force-true-hostname, --bespoke-force-void-cert-pinner — interventional passes for TLS pinning (these change behaviour, so they need the active ack). See TLS pinning bypass.
  • --bespoke-return-capture — attach a return site to eligible derived candidates, to capture what a getter actually returned.

2. Pack symbol — request a hook by name

--bespoke-pack <SYMBOL> (repeatable) requests a specific catalog hook. Rutken builds the install document for you: hook IDs are assigned so they cannot collide with the agent's own probes, and an unknown symbol is refused at parse time — before any device round-trip — with the full list of valid symbols printed. Name a symbol twice and it is rejected: one hook per site.

rutken app.apk run --bespoke \
  --bespoke-pack java.root.file_exists \
  --bespoke-pack java.tls.certificatepinner_check \
  --bespoke-authorize "pentest: acme-engagement-2026"

3. Hand-authored install — full control (advanced)

--bespoke-hooks <PATH> loads an agent_spec::Install JSON document directly. An Install is a list of [HookId, ObserveParams] pairs; the hook id is a bare integer and must be ≥ 5 (ids 0–4 are reserved for the agent's own probes). A Java pack hook names the sentinel module __artbridge_java_pack__ with a catalog symbol — exactly what --bespoke-pack builds for you:

{
  "hooks": [
    [5, {
      "module": "__artbridge_java_pack__",
      "symbol": "java.crypto.cipher_get_instance",
      "captures": [],
      "dedup_key": null,
      "emit_label": "my.cipher",
      "target": null
    }]
  ]
}

A native hook is the case this format was designed for: name the real .so and an exported symbol, and declare which arguments to read and how.

[5, {
  "module": "libnative.so",
  "symbol": "do_sign",
  "captures": [ { "arg_index": 0, "read_kind": { "CStr": { "max_len": 256 } } } ],
  "dedup_key": null,
  "emit_label": "native.do_sign",
  "target": null
}]

read_kind is one of "U64", "I64", {"CStr":{"max_len":N}}, {"Bytes":{"max_len":N}}, "SockAddr", or "LooksLikePointer" (which reports whether a value looks like a pointer without dereferencing it). An optional dedup_key of {"arg_index":N} collapses repeat firings that share that argument's value.

This composes hooks the agent already implements. An Install is "parameterised pre-compiled hooks, not a hook-description DSL" — you select and parameterise existing packs and native module/symbol sites, you do not describe new Java behaviour in JSON. To hook a Java method no pack covers yet, author a new pack (below).

Authoring a brand-new hook (Rust)

A genuinely new Java hook is a small Rust pack, not a JSON file. The spec and the implementation live in two crates:

  • The spec — crates/agent-spec/. The wire types are in src/frame.rs (Install, ObserveParams, Capture, ReadKind, HookId); the pack-symbol catalog and capability tiers (which symbols exist, and which are observation vs Active) are in src/capability.rs.
  • The implementation — crates/agent/src/packs/. Model a new file on java/crypto.rs: declare a JavaMethodSpec (class / method / signature / is_static) and an install function that calls JavaRuntime::install_argument_capture and emits a HookEvent / CaptureValue. Then register the symbol in capability.rs so --bespoke-pack accepts it, and build with --features bespoke-agent.

One chooser per run. --bespoke-pack, --bespoke-derived, and --bespoke-hooks are mutually exclusive. Pick one.

The pack-symbol catalog

Pack symbols are the named, ready-made hooks you request with --bespoke-pack. The authoritative list is whatever your binary accepts — pass any unknown symbol and the agent prints every valid one:

rutken app.apk run --bespoke-pack ? 2>&1 | sed -n '/valid symbols/,$p'

The families, with representative members:

FamilyPrefixWhat it hooks
Root / tamperjava.root.*file_exists, file_canread, runtime_exec, packagemanager_getpackageinfo, the RootBeer family (rootbeer_is_rooted, rootbeer_native_checkforroot).
TLS / pinningjava.tls.*certificatepinner_check, okhttp2_certificate_pinner_check, trustmanager_checkservertrusted, the trustmanagerimpl_* and certificatetransparency_* sites, httpsurlconnection_sethostnameverifier.
Cryptojava.crypto.*, java.keymat.*cipher_get_instance, cipher_init, messagedigest_get_instance, secretkeyspec_init, ivparameterspec_init.
File I/Ojava.fileio.*context_open_file_output, context_get_shared_preferences, context_open_or_create_database, file_set_readable, file_set_writable.
WebViewjava.webview.*loadurl, addjavascriptinterface, onreceivedsslerror, setjavascriptenabled, setallowuniversalaccessfromfileurls, setwebcontentsdebuggingenabled.
PII sourcespii_source.*, framework.*Device identifiers and message bodies: telephonymanager_getimei, getsubscriberid, getline1number, cursor_getstring, smsmessage_getmessagebody.
Other app surfacesvariousjava.clipboard.clipboardmanager_settext, java.broadcast.context_register_receiver, java.classload.dexclassloader_init, java.biometric.*, java.integrity.signature_check.
Mutation (Active)*_mutation, field/returnThe hooks that persist a change — see below.
Self-check / experimentjava.selfcheck.*, experiment.*Fixture-only sites used to prove a mechanism on-device (e.g. throw_check, return_override_check). Empty on real apps by design.

Several java.selfcheck.* and experiment.* symbols exist to exercise a capability against Rutken's own test fixture. They install nothing on a real app — that is intentional, and lets a new mechanism ship with a device-testable site and zero approved real-app sites until one is reviewed in.

Hooks that persist a change

A mutation hook does not just watch a site — it rewrites what the target app's own code sees, and that change persists for the rest of the call. There are four chokepoints, each a separate, gated install path in the agent:

KindWhat it rewritesExample symbol
Argument mutationAn argument, before the method body reads it.java.root.packagemanager_getpackageinfo_flags_mutation (forces flags to 0); …_pkgname_mutation (rewrites the package name).
Return-value transformThe value returned, before the caller sees it.java.framework.settings_secure_getstring_spoof_android_id (returns a fixed fake Android ID).
Field writeAn instance primitive field on the receiver.java.selfcheck.field_write_debug_flag (fixture).
Return overrideThe whole return of a check function.java.selfcheck.return_override_check (fixture); native access, stat, fopen.

Three rules govern every one of them:

  • Active-only. Each is classified Active and arms only under --i-am-authorized-bespoke-active — never the observation ack. In the GUI they are structurally excluded from the observe picker, so a mutation can never be armed by an operator who only acknowledged observation.
  • Narrow by design. The real-app footprint is deliberately small. Most mutation symbols are fixture-only today — the mechanism ships with a device-provable site and an allowlist, not a licence to rewrite arbitrary methods. The shipped real-app mutations are a short, reviewed set (the Android-ID spoof, the root-package-name and flags rewrites on a root-check allowlist).
  • Bounded. Firings are capped per run, so a mutation that would otherwise fire on every call cannot run away — enough firings to change the behaviour under test, not an open-ended rewrite.

Prove a change the honest way: A / B / A. Run once observing (A), once with the mutation armed (B), and once observing again (A). A real persisted change shows the app's own behaviour differ in B and return in the second A. A single mutated run on its own is a claim, not a proof.

In the GUI

The desktop app exposes the same engine through the Runtime console (the Dynamic view). It is three columns: HOOKS on the left, the live event stream in the middle, and the selected hook's script on the right.

  • Armed vs watch. The HOOKS column shows each hook Rutken can inject for this target and its state. A hook that corroborates one of this app's findings shows as armed; one with nothing to confirm shows as watch — the same distinction as on the command line.
  • Add hooks by hand. The Bespoke hook-script pane has an “Available hooks (author)” picker, built from the same pack-symbol catalog. Tick the symbols you want installed in addition to the auto-derived set, and they are applied on the next Record run. Your selection persists with the project.
  • Authorization is explicit. As on the CLI, the observe acknowledgement arms observe hooks only; the mutation symbols are not offered in the observe picker at all. Changing the app requires the active acknowledgement.
  • Record, then read. Start a Record run and the middle column fills with firings as the app exercises each hooked site; selecting a hook on the left shows the exact script on the right and filters the stream to its events.

See Dynamic & network capture for driving the app, capturing flows, and exporting a session.

Reading the result

A hook has an install outcome and a firing record, and Rutken keeps them honest and separate:

  • Bound — the hook installed at a real address. Resolution origin is recorded (an in-memory resolution is a weaker guarantee than an ordinary symbol lookup and stays distinguishable).
  • Fired — the site ran while the hook was installed, and the firing was captured. Back-pressure can discard firings under load; that is reported, not hidden.
  • Corroborated — a firing's payload actually matches the finding the hook was armed for. Binding alone is not proof a firing would have happened; a bound hook that never fired is reported as exactly that, never dressed up as a confirmation.

An install can also fail for reasons that are about the target (the symbol is not in the module) versus about the build (this agent ships no implementation for that symbol). Rutken keeps those two apart, because conflating them sends an investigation in the wrong direction.

New to the runtime side? Start with Dynamic & network capture for a first Record run, then come back here to author a specific hook set.