Bridges
Frida Bridges
Version Constraint
- Frida >= 17.0.0: Bridges are NOT bundled with the GumJS runtime by default.
- Frida < 17.0.0: All bridges were available globally without any import.
- REPL and
frida-trace: Always bundle all three bridges regardless of version (backward compatibility).
Available Bridges
| Bridge | npm Package | Import Statement |
|---|---|---|
| ObjC | frida-objc-bridge | import ObjC from "frida-objc-bridge"; |
| Swift | frida-swift-bridge | import Swift from "frida-swift-bridge"; |
| Java | frida-java-bridge | import Java from "frida-java-bridge"; |
Usage Scenarios
1. REPL / frida-trace — Plain JavaScript (no imports needed)
All three bridges are pre-bundled. Scripts using ObjC, Java, or Swift globals work without any changes.
1// script.js
2console.log(ObjC.available);
1frida -p0 -l script.js
Output:
true
[Local::SystemSession ]->
2. REPL — Automatic TypeScript Compilation
The REPL can compile .ts files automatically. Use frida-create -t agent in an empty directory to scaffold the project; bridges are still bundled in REPL mode.
3. Manual Compilation with frida-compile (TypeScript agents)
Bridges must be explicitly imported in the TypeScript source.
Prerequisites:
- Node.js + npm installed
frida-compileavailable (npm install -g frida-toolsor local)
Steps:
1// script.ts
2import ObjC from "frida-objc-bridge";
3
4console.log(ObjC.available);
1# In an empty directory:
2frida-create -t agent # scaffold tsconfig.json, package.json, etc.
3npm install # install base deps
4npm install frida-objc-bridge # install desired bridge(s)
5
6frida-compile script.ts -o _agent.js -S -c # -S: source maps, -c: compress
7frida -p0 -l _agent.js
frida-compile flags:
| Flag | Meaning |
|---|---|
-o <file> | Output file path |
-S | Omit source maps from output |
-c | Compress (minify) output with Terser |
4. API Usage (Python / Go)
When using Frida bindings programmatically, the workflow is:
- Write TypeScript script with explicit bridge imports.
- Run
frida-create -t agentin the script’s directory to set uptsconfig.json/package.json. - Install bridge package(s) via
npm install. - Use the
CompilerAPI to build the bundle, then load it into the target process.
Python
1import frida
2
3def on_diagnostics(diag):
4 print("diag", diag)
5
6def on_message(message, data):
7 print(message)
8
9compiler = frida.Compiler()
10compiler.on("diagnostics", on_diagnostics)
11# script.ts is located in /tmp; set project_root so tsconfig.json is resolved
12bundle = compiler.build("script.ts", project_root="/tmp")
13
14session = frida.attach(0) # 0 = attach to system session
15
16script = session.create_script(bundle)
17script.on("message", on_message)
18script.load()
Key API:
| Call | Description |
|---|---|
frida.Compiler() | Create a compiler instance |
compiler.on("diagnostics", fn) | Subscribe to compiler diagnostic events |
compiler.build(path, project_root=...) | Compile TypeScript, returns JS bundle string |
frida.attach(pid) | Attach to process by PID (0 = system session) |
session.create_script(source) | Create script from source string |
script.on("message", fn) | Subscribe to send() messages from script |
script.load() | Inject and execute the script |
Go
1package main
2
3import (
4 "bufio"
5 "fmt"
6 "github.com/frida/frida-go/frida"
7 "os"
8)
9
10func main() {
11 comp := frida.NewCompiler()
12 comp.On("diagnostics", func(diag string) {
13 fmt.Printf("Diagnostics: %s\n", diag)
14 })
15
16 bopts := frida.NewCompilerOptions()
17 bopts.SetProjectRoot("/tmp") // directory containing tsconfig.json
18 bopts.SetSourceMaps(frida.SourceMapsOmitted) // omit source maps
19 bopts.SetJSCompression(frida.JSCompressionTerser) // minify with Terser
20
21 bundle, err := comp.Build("script.ts", bopts)
22 if err != nil {
23 panic(err)
24 }
25
26 session, err := frida.Attach(0)
27 if err != nil {
28 panic(err)
29 }
30
31 script, err := session.CreateScript(bundle)
32 if err != nil {
33 panic(err)
34 }
35
36 script.On("message", func(message string, data []byte) {
37 fmt.Printf("%s\n", message)
38 })
39
40 script.Load()
41
42 r := bufio.NewReader(os.Stdin)
43 r.ReadLine() // keep process alive
44}
Key Go API:
| Call | Description |
|---|---|
frida.NewCompiler() | Create compiler instance |
frida.NewCompilerOptions() | Create build options struct |
bopts.SetProjectRoot(path) | Directory containing tsconfig.json / package.json |
bopts.SetSourceMaps(frida.SourceMapsOmitted) | Omit source maps from bundle |
bopts.SetJSCompression(frida.JSCompressionTerser) | Minify with Terser |
comp.Build(file, opts) | Compile TypeScript to JS bundle |
frida.Attach(pid) | Attach to process (0 = system session) |
session.CreateScript(bundle) | Create script from bundle string |
script.Load() | Inject and execute the script |
Summary Decision Table
| Context | Bridge import required? | Compilation needed? |
|---|---|---|
REPL plain JS (frida -l script.js) | No | No |
REPL with .ts file | No (REPL bundles bridges) | Auto (REPL handles it) |
frida-trace | No | No |
frida-compile + TypeScript agent | Yes | Yes (frida-compile) |
| Python/Go API with TypeScript agent | Yes | Yes (compiler.build(...)) |