frida-python icon indicating copy to clipboard operation
frida-python copied to clipboard

Custom agent with Java bridge

Open rloretan opened this issue 4 months ago • 2 comments

Hi, So with Frida 17, runtime bridges, such as the Java runtime bridge, must be added manually to a custom agent script.

This works for me when concatenating the bridge code with whatever other Frida script I want to load, and then calling script.load from python. The problem is that it's harder to debug bugs in a Frida script, when the error message points to line ~13'000, because the buggy Frida script was appended to the bridge script. Is there a way to load the bridge script separately?

The following script shows the problem:

import frida
import os
import time

process = "SOME APP"
device = frida.get_usb_device()

pid = device.get_process(process).pid

session = device.attach(pid)

with open('/home/user/frida_java_bridge.js', 'r') as bridgefile:
    bridge_source = bridgefile.read()

script1_source = """
console.log('hello form script1')
"""

script2_source = """
console.log('hello form script2a');
Java.perform(function() {console.log('inside Java runtime')});
console.log('hello form script2b');
"""

bridge= session.create_script(bridge_source)
script1 = session.create_script(script1_source)
script2 = session.create_script(script2_source)

print("one by one:")

bridge.load()
script1.load()
script2.load()

print("concatenated:")
script3 = session.create_script(bridge_source + script2_source)
script3.load()

output:

one by one:
hello form script1
hello form script2a

concatenated:
hello form script2a
inside Java runtime
hello form script2b

rloretan avatar Aug 05 '25 16:08 rloretan

Where does this frida_java_bridge come from? I would like a copy too.

jie64 avatar Aug 26 '25 03:08 jie64

@jie64 You can generate it from https://github.com/frida/frida-java-bridge. Or you could take it from some other project, for example https://github.com/Ch0pin/medusa/blob/master/libraries/js/frida_java_bridge.js.

rloretan avatar Sep 01 '25 12:09 rloretan