Skip to content

Commit 06bd475

Browse files
cpholgueraCopilotTheDauntless
authored
Update Frida script instructions for Frida 17 (#3678)
* Update Frida script instructions for Frida 17 Added guidelines for using Frida 17 APIs exclusively and updated instructions for writing Frida scripts. * Apply suggestion from @cpholguera * Update Frida script instructions for Frida 17 compatibility * Update section title for Frida API usage and validation * Update Frida 17 documentation to reflect changes in runtime bridges and API updates * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Apply suggestions from code review Co-authored-by: Jeroen Beckers <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Jeroen Beckers <[email protected]>
1 parent 4190f57 commit 06bd475

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

.github/instructions/mastg-frida-scripts.instructions.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ This guide defines how to write and use Frida scripts in MASTG demos. Scripts li
77

88
**Note:** Prefer Frooky hooks over Frida scripts where possible, as they require less code. See `mastg-frooky-scripts.instructions.md` for details.
99

10-
Version requirement
11-
12-
- Use Frida 17 or later. See @MASTG-TOOL-0031 ([Frida 17](https://mas.owasp.org/MASTG/tools/generic/MASTG-TOOL-0031/#frida-17)
13-
1410
## Location and naming
1511

1612
- Place scripts inside the demo folder and name them `script.js` unless multiple scripts are needed.
@@ -36,6 +32,34 @@ Examples:
3632
- Backtraces: use `DebugSymbol.fromAddress` and cap lines.
3733
- In `onEnter/onLeave`, capture context first (for example, `const ctx = this.context;`) before using nested arrow functions.
3834

35+
## Use and Validation of Frida APIs
36+
37+
When writing new Frida scripts for MASTG demos, always validate against the latest [frida-gum typings](https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/refs/heads/master/types/frida-gum/index.d.ts) (human-readable version: [JavaScript API](https://frida.re/docs/javascript-api/)).
38+
39+
Consider the following key changes introduced in Frida 17 and if you encounter any of the old APIs in existing scripts, update them accordingly:
40+
41+
| Area | Before Frida 17 | Frida 17 and later | Notes |
42+
| -------------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
43+
| Global exports | `Module.getExportByName(null, "open")` and `Module.findExportByName(null, "open")` | `Module.getGlobalExportByName("open")` and `Module.findGlobalExportByName("open")` | Global lookups are now explicit. `get*` throws if missing, `find*` returns null. |
44+
| Global symbol special case | `Module.getSymbolByName(null, "open")` | `Module.getGlobalExportByName("open")` | Only the null module symbol case maps to global exports. Not a general symbol replacement. |
45+
| Module exports | `Module.getExportByName("libc.so", "open")` and `Module.findExportByName("libc.so", "open")` | `Process.getModuleByName("libc.so").getExportByName("open")` and `Process.getModuleByName("libc.so").findExportByName("open")` | Static helpers removed. Use a `Module` instance. `get*` throws, `find*` returns null. |
46+
| Module symbols | `Module.getSymbolByName("libart.so", "ExecuteNterpImpl")` | `Process.getModuleByName("libart.so").getSymbolByName("ExecuteNterpImpl")` | Symbol lookup still exists but only on `Module` instances, not statically and not on pointers. |
47+
| Module base | `Module.getBaseAddress("libc.so")` | `Process.getModuleByName("libc.so").base` | Base address helpers removed. Base is a property of a `Module` instance. |
48+
| Module initialization | `Module.ensureInitialized("libobjc.A.dylib")` | `Process.getModuleByName("libobjc.A.dylib").ensureInitialized()` | Static initializer removed. Instance method ensures initializers have run for that module. |
49+
| Enumeration | `Process.enumerateModules({ onMatch, onComplete })` | `Process.enumerateModules()` | Callback based enumeration removed. Now returns arrays. Same model for threads and ranges. |
50+
| Memory access | `Memory.read*`, `Memory.write*`, `Memory.readUtf8String`, `Memory.writeUtf8String`, `Memory.readByteArray`, `Memory.writeByteArray` | `ptr.read*`, `ptr.write*`, `ptr.readUtf8String()`, `ptr.writeUtf8String()`, `ptr.readByteArray()`, `ptr.writeByteArray()` | All memory read and write helpers moved onto `NativePointer` instances, including numeric reads and writes, strings, and byte arrays. The `Memory.*` forms are replaced by instance methods on the pointer you want to access. |
51+
52+
Here's one example of updating code for Frida 17 that can serve as a reference: <https://patch-diff.githubusercontent.com/raw/AloneMonkey/frida-ios-dump/pull/200.diff>.
53+
54+
**Using ObjC and Java runtime bridges in Frida 17+:**
55+
56+
The Frida scripts we're creating for MASTG demos are meant to be run with the Frida CLI, so you can keep using the `ObjC` and `Java` runtime bridges as before. However, be aware that starting with Frida 17, these APIs are no longer part of the [frida-gum typings](https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/refs/heads/master/types/frida-gum/index.d.ts). The Frida CLI pre-bundles these runtime bridges for you.
57+
58+
For more details, see:
59+
60+
- <https://mas.owasp.org/MASTG/tools/generic/MASTG-TOOL-0031/#frida-17>
61+
- <https://frida.re/news/2025/05/17/frida-17-0-0-released/>
62+
3963
## Inspiration
4064

4165
- Don't reinvent the wheel when something already exists. Use existing open-source sources when available, for example, <https://codeshare.frida.re/browse>.
@@ -55,24 +79,6 @@ var config = {
5579
...
5680
```
5781
58-
```js
59-
// SOURCE: https://github.com/iddoeldor/frida-snippets?tab=readme-ov-file#os-log
60-
61-
var m = 'libsystem_trace.dylib';
62-
// bool os_log_type_enabled(os_log_t oslog, os_log_type_t type);
63-
var isEnabledFunc = Module.findExportByName(m, 'os_log_type_enabled');
64-
// _os_log_impl(void *dso, os_log_t log, os_log_type_t type, const char *format, uint8_t *buf, unsigned int size);
65-
var logFunc = Module.findExportByName(m, '_os_log_impl');
66-
67-
// Enable all logs
68-
Interceptor.attach(isEnabledFunc, {
69-
onLeave: function (ret) {
70-
ret.replace(0x1);
71-
}
72-
});
73-
...
74-
```
75-
7682
## Logging and outputs
7783
7884
- Redirect script output to `output.txt` from `run.sh`.

tools/generic/MASTG-TOOL-0031.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Frida 17 introduces [breaking changes](https://frida.re/news/2025/05/17/frida-17
5353

5454
**Bridges:**
5555

56-
Frida 17 removes the bundled [runtime bridges](https://frida.re/docs/bridges/) (`frida-{objc,swift,java}-bridge`) within Frida's GumJS runtime. When you use the commands `frida` and `frida-trace`, this doesn't have any noticeable impact, as they come with the Java, Objective-C, and Swift bridges pre-bundled, so you can still use them as before.
56+
Frida 17 removes the bundled [runtime bridges](https://frida.re/docs/bridges/) (`frida-{objc,swift,java}-bridge`) within Frida's GumJS runtime. When you use CLI tools such as `frida`, `frida-trace` or @MASTG-TOOL-0145, this doesn't have any noticeable impact, as they come with the Java, Objective-C, and Swift bridges pre-bundled, so you can still use them as before.
5757

5858
However, if you are writing your own custom Frida-based tooling or scripts that depend on these bridges, you will now need to install them separately via `frida-pm`, Frida's package manager. For example, to install the Java bridge, run:
5959

@@ -76,7 +76,9 @@ npx frida-compile -o agent.js -o _agent.js
7676

7777
**API Changes:**
7878

79-
Frida has made changes to its native APIs. While these changes may break some of your existing scripts, they encourage you to write more readable and performant code. For instance, now, `Process.enumerateModules()` returns an array of `Module` objects, allowing you to work with them directly.
79+
Frida has made changes to its native APIs. While these changes may break some of your existing scripts, they encourage you to write more readable and performant code. See a full overview in the [MASTG Frida scripts writing guide](https://mas.owasp.org/contributing/writing-content/mastg-frida-scripts.instructions#use-and-validation-of-frida-apis).
80+
81+
For instance, now, `Process.enumerateModules()` returns an array of `Module` objects, allowing you to work with them directly.
8082

8183
```js
8284
for (const module of Process.enumerateModules()) {
@@ -94,7 +96,11 @@ Process.getModuleByName('libc.so').getExportByName('open')
9496
Module.getGlobalExportByName('open');
9597
```
9698

97-
For more details, refer to the [Frida 17.0.0 Release Notes](https://frida.re/news/2025/05/17/frida-17-0-0-released/).
99+
For more details, see:
100+
101+
- the [Frida 17.0.0 Release Notes](https://frida.re/news/2025/05/17/frida-17-0-0-released/)
102+
- the [updated Frida JavaScript API documentation](https://frida.re/docs/javascript-api/)
103+
- the [frida-gum typings](https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/refs/heads/master/types/frida-gum/index.d.ts)
98104

99105
## Tools
100106

0 commit comments

Comments
 (0)