I'm using Frida to run a script on a process, and I want to wait for it to send the result back to me, as a callback.
My current code looks like this:
def check(target):
global msg
script_to_run = '''
(omitted for brevity)
'''
# callback to handle the output of the script
def on_message(message, data):
global msg
if message['type'] == 'send':
msg = message['payload']
session = device.attach(target.pid)
script = session.create_script(script_to_run)
script.on('message', on_message)
script.load()
# Wait for the script to send us a message
while msg == None:
pass
return msg == 'true'
The while
loop in particular looks a bit unoptimized, and I'm also worried about how I used that global variable... it will pollute the global scope.
EDIT: As it turns out, I was approaching this in the wrong direction. See my answer below for details.
pass
for asleep(0)
: stackoverflow.com/a/790246/12735366 \$\endgroup\$check(target)
used? You're transforming an asynchronous function into a synchronous one, which defeats the entire point. \$\endgroup\$