Skip to content

Instantly share code, notes, and snippets.

@oleavr

oleavr/README.md Secret

Last active January 24, 2024 08:53
Show Gist options
  • Save oleavr/cae76c895eb7d227216ed3ffe9dbbeb3 to your computer and use it in GitHub Desktop.
Save oleavr/cae76c895eb7d227216ed3ffe9dbbeb3 to your computer and use it in GitHub Desktop.
frida-java-bridge playground example (also: how to use frida-compile)
  1. Set up a local clone of frida-java-bridge:
$ git clone https://github.com/frida/frida-java-bridge.git
$ cd frida-java-bridge
$ npm install
$ npm link
  1. Make a directory someplace outside frida-java-bridge and save the two attached files as package.json and agent/index.js:
$ mkdir frida-java-playground
$ cd frida-java-playground
$ # create the two files
$ npm install
$ npm link frida-java-bridge
  1. Run this in a separate terminal to continuously recompile the code:
$ npm run watch
  1. Load the generated _agent.js using the Frida REPL:
$ frida -U com.google.android.apps.maps --runtime=v8 -l _agent.js

Enter run() in the REPL to call the function defined in agent/index.js. It is recommended to put your code in a function as exceptions thrown during script load might get swallowed by the REPL (something that should be fixed in the REPL).

  1. Edit your local frida-java-bridge and have fun!
const Java = require('frida-java-bridge');
globalThis.run = () => {
Java.perform(() => {
console.log('Enumerating loaded classes...');
const classes = Java.enumerateLoadedClassesSync();
console.log(`Enumerated ${classes.length} classes`);
});
};
{
"name": "frida-java-playground",
"version": "1.0.0",
"description": "Playground for frida-java-bridge",
"private": true,
"main": "agent/index.js",
"scripts": {
"build": "frida-compile agent -o _agent.js",
"watch": "frida-compile agent -o _agent.js -w"
},
"dependencies": {
"frida-compile": "^9.0.8",
"frida-java-bridge": "^3.2.0"
}
}
@oleavr
Copy link
Author

oleavr commented Oct 11, 2019

Should global.run work? The code didn't execute for me, until I wrapped it in

The example code isn't meant to auto-run the code. It just makes that function globally visible so you can do run() in the Frida REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment