FridaPython返回值并将其写入文件

2024-06-10 08:03:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用frida python连接到ios应用程序中的函数,我希望函数的输出写入CSV文件中。我该怎么做

Python脚本:

import frida, sys

script = 'script.js'
bundle = 'application'
f = open(script, "r")
s = f.read()

device = frida.get_usb_device(1000)
pid = device.spawn([bundle])
session = device.attach(pid)
script = session.create_script(s)
script.load()
device.resume(pid)
sys.stdin.read()

script.js

Interceptor.attach(intercept.implementation, {
        onEnter: function (args) {
            var instance = ObjC.chooseSync(ObjC.classes.CLASS)[0];
            send(instance.toString());
            }
        },

目前,我的脚本只能在截获函数后控制台注销这些值。是否有任何方法可以将值返回到python,以便将它们写入CSV文件


Tags: 文件csvinstance函数脚本readsessiondevice
2条回答

是的,有办法。您可以更改在javascript中处理send()函数的on_message()函数

即python中的默认\u消息:

def on_message(message, data):
    if message['type'] == 'send':
        print("[* ] + message)

.... 


device = frida.get_usb_device()
pid = device.spawn(["pgk"])
session = device.attach(pid)

script = open("filepath")

drop = session.create_script(script.read())
drop.on('message', on_message)
drop.load()
time.sleep(1)  # fails without this sleep
device.resume(pid)
sys.stdin.read()

在javascript中,只需调用

send("Method called") // Same as console log just handled through frida

您可以在此处找到相关文档:

https://frida.re/docs/messages/

在Javascript端使用send

在python方面

f = open('/tmp/log', 'w')    
# ...
def on_message(msg, _data):
    f.write(msg['payload'] + '\n')
# ...
script.on('message', on_message)
# don't forget f.close()

相关问题 更多 >