Skip to content

Instantly share code, notes, and snippets.

@oleavr

oleavr/README.md Secret

Last active January 24, 2024 08:53
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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"
}
}
@cryptax
Copy link

cryptax commented Jul 12, 2019

Note you need to install frida-compile for that:
https://github.com/frida/frida-compile

@leonjza
Copy link

leonjza commented Jul 12, 2019

@cryptax frida-compile should resolve with the npm install step.

@cryptax
Copy link

cryptax commented Jul 12, 2019

@cryptax frida-compile should resolve with the npm install step.

You're right. True.
I had an blocking errors I hadn't seen during npm install. I fixed those by updating nodejs and npm. I still have a warning compiling fsevents@2.0.7, used by frida-compile, but it seems it is optional.

@Alien-AV
Copy link

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

setTimeout(function() {
    Java.perform(function() {
        //code
    });
}, 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