Frida python return 值并将它们写入文件
Frida python return values and write them into file
我目前正在使用 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());
}
},
目前,我的脚本只能在我拦截函数时控制台注销值。有什么方法可以 return 将值 python 写入 CSV 文件吗?
在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()
是的,有办法。您更改 javascript.
中处理 send() 函数的 on_message() 函数
即 python 中的默认值 on_message:
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
您可以在此处找到相关文档:
我目前正在使用 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());
}
},
目前,我的脚本只能在我拦截函数时控制台注销值。有什么方法可以 return 将值 python 写入 CSV 文件吗?
在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()
是的,有办法。您更改 javascript.
中处理 send() 函数的 on_message() 函数即 python 中的默认值 on_message:
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
您可以在此处找到相关文档: