Scripts
Frida hooks, traffic rules and DNS rewrites kept in the portal, with parameters filled in at launch, applied from the app's very start and tried live in a session.
A Frida script hooks the app from inside its own process: point a WebView at a test host, switch a feature flag, log a call. Holtdroid keeps such scripts in a library and loads the ones you pick into the app before it starts, the same moment as
frida -U -f com.example.app -l game_url.jsHoltdroid already starts apps under Frida to turn on WebView debugging, so your scripts run next to its own script, every time the app starts in the session (also after Restart). The APK is never modified.
Next to Frida code, the library keeps two more kinds of scripts: traffic rules that block, mock, redirect or rewrite the device’s requests in the MITM proxy, and DNS rewrites that answer the device’s DNS queries your way. All three are picked the same way at launch and can be tried in a running session.
The library
Section titled “The library”Scripts in the dock lists two kinds:
- Mine: personal scripts, seen and run only by you.
- Everyone’s: global scripts that everybody can run; only admins create and edit them. Copy to mine makes a personal copy to change.
A script has a name, a description, its parameters and its code. The editor
highlights JavaScript, completes Java, Frida’s globals and your parameters,
and saves with ⌘S / Ctrl S. A new script starts from a
working example.
Parameters
Section titled “Parameters”Values that change between runs (a URL, a flag, a user id) are parameters
instead of constants in the code. Declare each under Parameters and read
it as params.NAME:
| Field | Meaning |
|---|---|
| Name | How the code reads it: params.MY_URL; letters, digits, _ and $ |
| Label | What the launch dialog shows instead of the name |
| Type | Text, number or on/off; the code gets a string, a number or a boolean |
| Default | Used when a launch gives no value |
| Required | A launch without a value (and without a default) is refused |
A script written for the frida CLI needs one change: its constant becomes a
parameter.
Java.perform(function () { var WebView = Java.use("android.webkit.WebView")
WebView.setWebContentsDebuggingEnabled(true)
var oneArg = WebView.loadUrl.overload("java.lang.String") oneArg.implementation = function (url) { console.log("[loadUrl] " + url + " -> " + params.MY_URL) return oneArg.call(this, params.MY_URL) }
var twoArg = WebView.loadUrl.overload("java.lang.String", "java.util.Map") twoArg.implementation = function (url, headers) { console.log("[loadUrl] " + url + " -> " + params.MY_URL) return twoArg.call(this, params.MY_URL, headers) }})with a required text parameter MY_URL.
Running scripts
Section titled “Running scripts”From the launch dialog. On devices that load scripts (virtual devices), the dialog has a Frida scripts section: tick the scripts and fill in their parameters. Launch stays disabled until every required value is there. The dialog remembers your choice and values per app in your browser.
From the API. POST /api/v1/sessions takes the same choice as a list,
with saved scripts by id, or inline Frida code (source), traffic rules
(rules) or DNS rewrites (dns):
{ "source": "uploads", "artifactId": "…", "scripts": [ { "id": "3f9a…", "params": { "MY_URL": "https://test.example/game" } }, { "name": "trace", "source": "console.log('started in', Process.id)" } ]}From WebDriver tests. The same list goes into holtdroid:options.scripts
(see WebDriver):
caps.setCapability("holtdroid:options", Map.of( "target", "app", "source", "uploads", "artifact", artifactId, "scripts", List.of(Map.of("id", scriptId, "params", Map.of("MY_URL", testUrl)))));The editor’s From tests box shows the JSON for the script you have open. Values may be strings or JSON numbers and booleans; Holtdroid converts them to the parameter’s type. An unknown parameter name, a missing required value or a value of the wrong type fails the launch with 422 and says which.
Traffic rules
Section titled “Traffic rules”A traffic script is an ordered list of rules. Each matches a host
(api.example.com, *.example.com for every name under it, empty for any),
a path with its query (/api/*, */config.json; * matches anything) and
methods, and does one thing:
| Action | What it does |
|---|---|
| Block | Answers with an error status (403 by default) and a body; the server never sees the request |
| Mock | Answers with your status, content type and body |
| Redirect | Sends the request to another scheme and host (and path, when you give one), unseen by the app |
| Headers | Sets or removes headers of the request or the response |
| Replace text | Finds text (or a regular expression, with $1 for groups) in the request body, the response body or each SSE event and replaces it |
| Delay | Holds the request or the response for some milliseconds |
{{NAME}} in any text of a rule takes a parameter’s value at launch, for
example https://{{HOST}} as a redirect’s target. Bodies are rewritten up
to 8 MiB; larger ones and media streams pass as they are. Server-sent
events are rewritten one event at a time as they arrive, so a live feed
keeps flowing. WebSocket messages are not rewritten yet.
Rules need the proxy to read HTTPS, so a launch with traffic rules turns Decrypt HTTPS on. Apps that pin their certificates then fail to connect unless an unpinning Frida script runs too. A block rule that names only a host refuses that host even without decryption. The MITM tab lists, for each request, the rules that changed it.
DNS rewrites
Section titled “DNS rewrites”A DNS script is a list of rewrites in the DNS tab’s
format: a name or *.name, answered with addresses, another name, or as
non-existent, with a TTL. They are applied before the app starts, on top of
what the DNS tab holds, and {{NAME}} takes a parameter’s value, for
example an address that changes per test stand.
In a running session
Section titled “In a running session”The session page’s Scripts tab, next to MITM, is for writing and fixing scripts against the live app:
- Frida: open a script from the library (fill in its parameters) or
write one, then Run now loads it into the running app at once, Run
and keep also loads it at every later start, and Restart with it
restarts the app and loads it from the very start. A syntax or runtime
error shows right under the editor, and the log below streams what
scripts print with
console.*and the errors they throw. Running a script again stacks its hooks; restart for a clean start. Save writes over the library script you opened (when it is yours to edit), Save as new makes a personal copy. - Traffic rules: the rules the proxy applies now, editable in place. Apply puts them in force for new requests; rules can be added from a library script with its parameters, and Save as a script keeps the current set in your library.
Only the session’s owner and admins can change a session’s scripts and rules.
Output and errors
Section titled “Output and errors”console.log, console.warn and console.error go to logcat with the tag
frida:<script name>, so they show in the Logcat
tab and in recordings. A script that throws is
logged there as an error, and the app keeps running without it. Scripts run
in order after Holtdroid’s own script, sharing its Java bridge (two bridges
in one process crash the app), each in a function of its own: top-level
vars don’t leak from one script into another.
Java is the frida-java-bridge
of Holtdroid’s own script; Interceptor, Module, Memory and the
rest of Frida’s JavaScript API are there as usual.
Where it works
Section titled “Where it works”Scripts need a device that Holtdroid starts under Frida: virtual devices
(provider-emulator). Phones don’t take them yet, and the launch dialog
hides the section there. A launch with scripts goes only to providers that
load them.
Editing a script changes it for the next launches; running sessions keep the code they started with.
Configuration
Section titled “Configuration”scripts: enabled: true # default; false turns off the library and the launch option # storage: where scripts are kept, the api's storage when unset # storage: { type: s3, s3: { endpoint: …, bucket: …, prefix: scripts, … } }Scripts are small JSON files: global/<id>.json, users/<hash>/<id>.json,
and the list each launch resolved in launch/<id>.json, removed after a
week. Give them a storage of their own when the api’s storage is a cache
volume, or a restart loses them. Creating, editing and deleting a script are
audit events, and a launch’s
session.launch event lists the scripts it loaded.