8000 feat(frida): generate the bindings from frida-core's GIR, and Frida 17.30.2 by kkuehl · Pull Request #252 · frida/frida-rust · GitHub
[go: up one dir, main page]

Skip to content

feat(frida): generate the bindings from frida-core's GIR, and Frida 17.30.2 - #252

Draft
kkuehl wants to merge 31 commits into
frida:mainfrom
kkuehl:kkuehl/gir-bindings
Draft

kkuehl wants to merge 31 commits into
frida:mainfrom
kkuehl:kkuehl/gir-bindings

Conversation

@kkuehl
@kkuehl kkuehl commented Dec 4, 2026 •
Copy link
Copy Markdown
Contributor

We know this is huge

We realize this is a very large PR. We think it's worth it, because generating the bindings puts frida-rust on the same footing as Frida's other language bindings, and keeping up with Frida becomes much easier.

  • frida-python, frida-node and frida-swift each vendor frida/frida-bindgen as a git submodule. Its frida_bindgen_core holds the introspection model parsed from Frida's .gir files, the naming helpers, and the loader.
  • Each of them adds its own language layer on top: frida/frida_bindgen in frida-python, src/frida_bindgen in frida-node, and frida_swift/codegen.py in frida-swift.
  • frida-swift's Frida/Generated.swift says it is "produced from Frida's .gir files by the shared frida_bindgen_core package".
  • frida_rust/ here is the same kind of layer, for Rust.

The hand-written bindings miss much of frida-core. On main, frida/src calls 55 distinct frida-core functions and defines 21 public types. The generated bindings call 552 and define 151. Among what main lacks entirely:

  • the Compiler, PackageManager and FileMonitor APIs;
  • PortalService, ControlService, Relay, EndpointParameters and the authentication services;
  • Bus and Service;
  • spawn and child gating (Spawn, Child), Crash, and Application;
  • the Barebone device configuration;
  • the kernel-image readers;
  • the pattern language.

That gap only grows by hand.

So a new frida-core release becomes a regeneration (scripts/update-bindings.sh) instead of hand-porting each API change. frida-rust then gets new API when the other bindings do, and its surface matches theirs.

What stays hand-written, and why

Only frida-core's API is generated. Two things stay hand-written on purpose:

  • Gum: frida-gum and frida-gum-sys, unchanged in approach.
    • The devkits ship no GIR for Gum.
    • Gum's users need its in-process API, which frida-core doesn't expose. That means code running inside the target, and above all libafl_frida, which depends on frida-gum and frida-gum-sys (not on frida).
    • So LibAFL keeps working as it does today, and both Gum crates move to the same Frida version as the rest.
  • A thin runtime layer in frida (frida/src/gir/*.rs outside generated/):
    • the object handle and ownership the generated classes are built on;
    • marshalling between Rust and GLib, and signal closures with their disconnect handle;
    • the single Error type;
    • a script's parsed messages, and RPC with rpc.exports (the way frida-python and frida-node do it);
    • the Inject trait shared by Device and Injector;
    • a few *_ext modules that add conveniences on top of generated classes, or work around frida-core. For example, LinuxSystemMap::from_blob reads past the blob's end unless it ends in a NUL.

What

This replaces the hand-written frida bindings with bindings generated from the frida-core.gir that ships in each devkit, and brings every crate to Frida 17.30.2.

  • The generator, frida_rust/:
    • It's built on Frida's shared frida-bindgen core and reads the devkit's GIR.
    • It emits the whole frida-core surface: classes, enumerations, constructors, methods, properties and signals.
    • The API is exported flat as frida::* (DeviceManager, Device, Session, Script, ...). frida::Variant is the single GVariant type the marshalling uses.
  • It fails closed:
    • strict.py rejects any GIR construct it doesn't know.
    • An async namespace function with no _sync form is refused rather than called without its callback. The first one appeared in 17.28.1 (obtain_shared_agent_container) and is skipped by name with that reason.
  • Generated code meets the hand-written rules: no unwrap, expect or panic; public errors; panics and unsafe documented; must_use where a result can't be ignored.
  • scripts/update-bindings.sh regenerates the bindings, then runs rustfmt, clippy --fix and clippy. It runs on Windows as well.
  • Gum stays hand-written. The devkits ship no GIR for Gum, and in-process users (agents, libafl_frida) need Gum's API directly. frida-gum, frida-gum-sys, their examples and their CI jobs stay, at the same Frida version as the rest.
  • clippy::indexing_slicing is denied outside tests. It applies across the workspace and in frida-sys, frida-gum and frida-gum-sys, where buffers sized by C are read. One real fix came out of it: Insn::bytes() no longer panics if capstone reports a size larger than its 24-byte array.
  • Windows: frida builds, lints and passes its tests there, and the inject examples build and run.
  • Docs link to the crate, not the private generated module.

Size

  • 23 commits and 318 files, about 50k added lines, mostly the generated bindings under frida/src.
  • The hand-written frida modules, their tests and their examples are removed.
  • Reviewing commit by commit is easiest. 3394a85 introduces the generator. The later commits are Windows fixes, Gum, the lint, version bumps from 17.27.5 to 17.30.2, and the CI fixes above.

CI fixes for current Rust

  • bindgen 0.73.2 in frida-sys and frida-gum-sys. Older bindgen emits transmutes that rustc's unnecessary_transmutes lint rejects.
  • libc declarations blocklisted. memcpy, malloc, open, exit and the other symbols rustc's suspicious_runtime_symbol_definitions checks are left out of both -sys crates. The devkit headers leak them in with C's types, and nothing uses them.
  • Lint opt-outs, with reasons. The examples and frida-build opt out of the workspace's no-panic lints: examples unwrap to stay short, and a build script fails by panicking.
  • Dependencies. frida drops its unused thiserror and serde dependencies.
  • Docs. The error module's doc example compiles without running.

A Gum bug this found: frida/frida-gum#1235

On linux-x86, reserves_a_register_for_user_data_while_following_a_thread computes 0 instead of 499500. The bug is in Gum's IA-32 Stalker, not here:

  • The cause. An instruction that touches both of the user data register's candidates (ESI and EDI), like mov [esi], edi, ran with EDI holding the user data.
  • The fix. stalker: Fix x86 insns touching all user data regs frida-gum#1235 fixes it, with a regression test that fails without the fix and passes with it.
  • Why the job stays red. frida-rust uses Frida's prebuilt devkits, so this job stays red until a Frida release carries that fix. The test is not skipped.
  • The docs here. The docs for user_data_reg now say what Gum does: an instruction always gets a register.

Testing

  • cargo test --features auto-download passes for frida and frida-gum on aarch64-apple-darwin.
  • Also on aarch64-apple-darwin, for frida, frida-gum, frida-sys and frida-gum-sys:
    • cargo clippy --all-targets -- -D warnings, with --all-features and with --features auto-download;
    • cargo fmt --check and taplo fmt --check.
  • On aarch64-linux-android: cargo clippy --lib --all-features.
  • On Windows: frida-gum ran 127 tests on x86_64 and 126 on i686 with both feature sets, and frida ran 88 on both. fmt, clippy and docs pass there too (at 17.27.4).
  • The second-DeviceManager test: a_second_device_manager_after_attaching_to_this_process faulted in frida-core 17.28.0, and frida-python faulted the same way. It was ignored while the fix landed in darwin: give the agent a file per session frida-core#1306, and it runs with the rest again from 17.28.1.

🤖 Generated with Claude Code

kkuehl and others added 23 commits November 23, 2026 09:17
Replace the hand-written bindings with bindings generated by frida_rust,
which sits on Frida's shared frida-bindgen core and reads the frida-core.gir
that ships in the devkit. The generated API is exported flat as `frida::*`
(`DeviceManager`, `Device`, `Script`, `Session`, ...), with `frida::Variant`
kept as the single GVariant type the generated marshalling uses. The
hand-written modules, their tests and their examples are removed.

The generator emits the whole surface — classes, enumerations, constructors,
methods, properties and signals — and fails closed: `strict.py` rejects any
GIR construct it does not know. The emitted code is held to the same quality
gates as hand-written code (no unwrap/expect/panic, public errors, panics and
unsafe documented, must_use where the return cannot be ignored), and
`scripts/update-bindings.sh` regenerates and then runs rustfmt, clippy --fix
and clippy.
- The unit tests did not compile on Windows: `Path` was imported for a
  test that only Unix has, and the crate denies warnings. The import is
  now inside that test.
- `FileMonitorEvent::from_raw` cast the raw value to `i32`, which clippy
  rejects where the C enum is `i32` already (Windows). `Unknown` now
  holds an `i64` built with `i64::from`, as the generated enumerations
  do.
- `attaching_to_a_pid_that_does_not_exist_is_process_not_found` took the
  pid of a child that had exited. Windows keeps a process, and its pid,
  while anything holds a handle to it, and frida-core 17.27.4 never
  returns from attaching to one: its Windows helper drops the Gum error
  it gets allocating memory in the process, so the call is never
  completed. On Windows the test now uses a pid that cannot exist; other
  systems reap a child as before.
The API is exported flat from the crate root and `gir` is a private
module, so rustdoc refused the six links to it and, as the crate denies
warnings, `cargo doc -p frida` failed.
`cargo fmt --all -- --check` and `taplo fmt --check`, which CI runs,
failed on these.
- inject_lib_blob embedded libinject_example.so, or the .dylib on macOS;
  on Windows the library is inject_example.dll.
- The injected function had Rust's calling convention. Frida calls it as
  a C function, so it is now `extern "C"`.
Under Git Bash or MSYS2:

- Use the cache frida-build uses, which is under %LOCALAPPDATA% there,
  and turn it into a path tar accepts: it took the `C:` of a Windows
  path for a remote host.
- Print the paths of --fetch-only as ones a Windows program can open.
- Run `python` where `python3` is the Microsoft Store's stub.
- Lint with auto-download, so that the binding is checked against the
  devkit of FRIDA_VERSION and not one placed in frida-sys/ by hand.

$CURL names the curl to fetch with. The tests pass their stand-in that
way, as Git Bash puts its own curl before anything in PATH, and the
stand-in is a shell script that runs Python, as a `#!` line cannot hold
a path with a space in it. test_core_usage.py looks in the same cache as
the script.
What `cargo upgrade`, the last step of scripts/update-bindings.sh, gives.
The generated bindings cover frida-core only: there is no GIR for Gum in
the devkits, and what uses Gum (an agent running inside the target, and
libafl_frida) needs an in-process API that frida-core does not expose.
So `frida-gum`, `frida-gum-sys` and the Gum examples return, exactly as
they are on kkuehl/frida-rust-updates at 1013d09 (Frida 17.27.4), and
this branch again holds every crate at one Frida version.

With them come the workspace members, the Gum CI jobs (Test Gum, the
no_std check, the iOS build, the Gum docs and its header check), the Gum
half of scripts/update-headers.sh and scripts/api-coverage.py, and the
README's wording. The Frida docs build added since stays, beside Gum's.

Built and tested on Windows: frida-gum 127 tests on x86_64 and 126 on
i686 with both feature sets, frida 88 on both, fmt, clippy and docs.
Synchronize all three version pins, vendor matching release headers, and regenerate the GIR bindings without unrelated dependency upgrades. Update release instructions and examples.
All three pins move to 17.28.0, the vendored headers are refreshed from the
release's devkits, and the GIR bindings are regenerated. The release is a Gum
release: the regenerated bindings differ only in the version they are stamped
with, and the gum header gains the two module-registry replay entry points.

**It also faults, and that is not ours.** A second `DeviceManager` after a
script was loaded into this process crashes the agent container thread
(`pthread_rwlock_rdlock` on an unmapped address) — through frida-rust, and
identically through frida-python 17.28.0, so it is frida-core, not these
bindings. 17.27.5 runs the same loop three times. Bisected in the fork to
`2dd9ebd2` (darwin: keep the helper and agent in resource dirs); the harness and
the table are on the fork's `kkuehl/fix-17.28-agent-container`.

`a_second_device_manager_after_attaching_to_this_process` is that loop, ignored
so CI stays green: run it with `--ignored` to see the fault. It passes at
17.27.5 and faults at 17.28.0.
17.28.1 adds the first async namespace function, `obtain_shared_agent_container`:
it takes a `Gio.AsyncReadyCallback` and is given no `_sync` form and no `_finish`.
The generator reads namespace functions through the core's readers with a finish
of `None`, so the function looked synchronous, and its callback was dropped from
the arguments like a closure — the generated wrapper then called the C function
with two of its four parameters:

    frida_sys::frida_obtain_shared_agent_container(filename, cancellable)

`Function` now records whether the GIR gave it an `AsyncReadyCallback`, and
`blocking_c_identifier` refuses such a function rather than calling it as if the
callback were not there. Async functions are a later phase; the one in 17.28.1
is skipped by name with that reason until they are.
`mod gir` is private and its items are re-exported at the crate root, so
`frida::gir::deinit()` did not compile: the test target has failed to build since
it was added, and `cargo test --features auto-download` stopped at it before
running anything.
`FRIDA_VERSION` and the vendored devkit headers move to 17.28.1, and the binding is
regenerated from that release's GIR (116 files): the doc comments name 17.28.1, and
`frida-sys/include/frida-core.h` gains the release's new declarations.

`cargo update` and `cargo upgrade`, which the regeneration runs, move lazy_static to
1.5 in the examples, libc to 0.2.191 and bitflags to 2.13.2 in frida-gum.

Checked with `cargo test --features auto-download` in frida: all suites and the
doctests pass.
17.28.0 faulted in the agent container the first time a second device manager's
session machinery ran, and this loop was ignored so CI stayed green while the fix
was in frida-core. The fix is frida/frida-core#1306 (the agent container is shared
across host sessions), which 17.28.1 carries: the loop passes on its devkit, so
the test runs with the rest again.
`FRIDA_VERSION` (all three copies) and the vendored `frida-sys/include/frida-core.h`
move to 17.29.0, and the binding is regenerated from that release's GIR (116 files).

Besides the doc comments naming 17.29.0, the release changes the pattern API, and the
binding follows it:

- `PatternValueStatus` (complete, truncated, failed) is new; `PatternValue` has
  `status` and `error` in place of `truncated`.
- `PatternModule` gains `measure`.
- `PatternModule::call_function` takes the pattern and function before the type
  name, data and address.
- `PatternDecodeOptions` gains `offset`.

`frida-gum-sys/include/frida-gumjs.h` is the same in 17.29.0. `cargo update` and
`cargo upgrade`, which the regeneration runs, changed nothing tracked.

Checked with `cargo test --features auto-download` in frida: all suites and the
doctests pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`FRIDA_VERSION` (all three copies) and the vendored headers move to 17.30.0, and the
binding is regenerated from that release's GIR (116 files). Only the doc comments
naming the release change: 17.30.0 adds and changes nothing in frida-core's GIR API.

`frida-gum-sys/include/frida-gumjs.h` gains the release's one new C function,
`gum_elf_module_find_dynamic_symbol_by_name()`. The release's behaviour changes
(ELF and Android export lookups stay within the module; Node and XPC number
marshalling) need nothing in the binding.

`cargo update` and `cargo upgrade`, which the regeneration runs, changed nothing
tracked.

Checked with `cargo test --features auto-download` in frida and in frida-gum: all
suites and the doctests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`indexing_slicing = "deny"` joins the workspace's clippy lints, which reach frida, and
frida-gum, frida-gum-sys and frida-sys get it in their own `[lints.clippy]` tables:
they do not take the workspace lints, and they are where buffers sized by Frida, Gum
and capstone are read. clippy.toml already lets tests index.

Hits outside tests:

- frida-gum-sys `Insn::bytes()` sliced capstone's fixed 24-byte array by the
  instruction's `size`, which comes from C. It now uses `get()` and, should `size`
  ever exceed the array, returns the whole array instead of panicking.
- frida-gum `CpuContext::reg()` and `set_reg()` (aarch64) index `x` after
  `assert!(index < 29)`, so they keep the assert and allow the lint with that reason;
  their docs now say when they panic.
- The bindgen output frida-sys and frida-gum-sys include trips it in its bitfield
  helpers, so the `bindings` module allows it beside `clippy::all`, which leaves out
  restriction lints.
- frida-gum's macho_module and pe_module integration tests index the images they
  build in helpers outside `#[test]` functions, so those files allow it.

frida itself had no hits.

Checked with `cargo clippy --all-targets -- -D warnings` for frida, frida-gum,
frida-sys and frida-gum-sys with `--all-features` and with `--features auto-download`
on aarch64-apple-darwin; with `--lib --all-features` on aarch64-linux-android (NDK
sysroot for bindgen); `cargo fmt --check`; `taplo fmt --check`; `cargo test
--features auto-download` in frida (90 passed) and frida-gum (118 passed), and
`cargo test --all-features` in frida-gum (118 passed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`FRIDA_VERSION` (all three copies) and the vendored `frida-sys/include/frida-core.h`
move to 17.30.2, and the binding is regenerated from that release's GIR (116 files).
Only the doc comments naming the release change: 17.30.2 adds and changes nothing in
frida-core's GIR API, and the header changes only in `FRIDA_VERSION` and
`FRIDA_MICRO_VERSION`.

`frida-gum-sys/include/frida-gumjs.h` is the same in 17.30.2. `cargo update` and
`cargo upgrade`, which the regeneration runs, changed nothing tracked.

Checked with `cargo test --features auto-download` in frida and in frida-gum: all
suites and the doctests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…indings

Rust 1.100 rejects two things in bindgen's output, so Clippy with -D warnings
failed in frida-sys and frida-gum-sys:

- `unnecessary_transmutes` in bindgen 0.72's bitfield accessors. bindgen 0.73.0
  generates them without the transmutes (rust-bindgen #3335).
- `suspicious_runtime_symbol_definitions`: the devkit headers pull in libc's
  bcmp and malloc, which bindgen declares with C's types (`c_ulong`, `c_uint`)
  where Rust's runtime expects `usize`. The build already blocklisted five of
  the symbols the lint checks (memcmp, memcpy, memmove, memset, strlen); it now
  blocklists all fourteen (adding bcmp, open, read, write, close, malloc,
  realloc, free and exit). Nothing here uses them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cargo 1.100 warns about every member without a `[lints]` table now that the
workspace has `[workspace.lints]`. The examples unwrap to stay short, and
frida-build is a build-script helper whose way to fail is a panic, so each
gets an empty `[lints]` table with a comment saying why, rather than the
workspace's no-panic library lints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…odules used

Cargo 1.100 reports both as unused: the generated bindings and their runtime
use neither.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It only defines a function, like the crate's other examples, which are all
compile-only. Run, it was linked as a program: on the i686 Linux job rustdoc
linked it with the host's 64-bit linker and the job failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gum never answers with no register. When an instruction uses every
candidate (ESI and EDI on 32-bit x86), the register is given back before
the instruction runs. The ia32 failure of this test was a Gum bug there:
frida/frida-gum, "stalker: Fix x86 user data reg for insns touching all
candidates".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kkuehl and others added 6 commits December 4, 2026 11:02
Linked as a plain library, frida's tests crashed at startup on
i686-unknown-linux-gnu: the devkit's Go runtime faults in runtime.rt0_go
on its first TLS store. Linked as static=, as auto-download links it,
they pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t from

The examples table takes a method too, whose example follows its errors. Adds
ScriptOptions, Bus, Injector, PortalService, EndpointParameters and Compiler, and
DeviceManager.find_device_by_type and add_remote_device, Device.enable_spawn_gating
and input, and Session.compile_script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Error's docs no longer mention the older crate::Error, which is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guide in gir's module docs never rendered, as the module is private. The crate
root now has it: getting started, the DeviceManager to Script flow, spawning,
messages and RPC, blocking calls and async, owners and signals, errors, the C API
underneath, and where the generated and hand-written code live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On nightly, with --cfg docsrs, doc_cfg shows "Available on non-Windows only" on what
the generator puts under #[cfg]. docs.rs passes the cfg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Builds frida's and frida-sys's docs on nightly with --cfg docsrs as docs.rs does,
denying rustdoc warnings, on every pull request, and deploys them on pushes to
kkuehl/gir-bindings. The READMEs link them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kkuehl and others added 2 commits December 4, 2026 17:10
docs(frida): a guide, examples, platform badges, and published docs
`FRIDA_VERSION` (all three copies) and both vendored headers move to 17.31.0, and the
binding is regenerated from that release's GIR (116 files). Only the doc comments
naming the release change: 17.31.0 adds and changes nothing in frida-core's GIR API,
and `frida-core.h` changes only in its version macros.

`frida-gum-sys/include/frida-gumjs.h` gains the release's new Gum API:
`gum_memory_read_into()`, `gum_stalker_transformer_make_excluding()`,
`gum_stalker_iterator_put_chaining_jump()`,
`gum_stalker_iterator_release_user_data_reg()`, and a `get_exclusions` slot in
`GumStalkerTransformerInterface`. frida-gum builds its transformers with Gum's own
constructors and never fills that interface itself, so the new slot needs nothing
here; the new functions are reachable through frida-gum-sys and not yet wrapped.

17.31.0 carries frida/frida-gum#1235 (its frida-gum tag is that merge), the x86
Stalker fix the `stalker` test `reserves_a_register_for_user_data_while_following_a_thread`
has been failing CI on.

`cargo update` and `cargo upgrade`, which the regeneration runs, changed nothing
tracked.

Checked with `cargo test --features auto-download` in frida and in frida-gum: all
suites and the doctests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0