我正在使用 frida-python 来 Hook android 函数,并且我正在尝试将输出重定向到文件。
我尝试将标准输出重定向到文件:
sys.stdout = open(os.path.join(self.dump_path,'apk_hook.txt'), 'w')
打电话之前
script = self.session.create_script(open("java_hook.js").read())
script.load()
但这会重定向所有内容,而不仅仅是 frida-python 的结果。
我还尝试将结果直接写入 javascript 文件(java_hook.js) 但我不知道如何将变量 self.dump_path 从 python 文件传递到 javascript 文件。
Java.use('java.net.URL').$init.overload('java.lang.String').implementation = function(str1) {
var file = new File(How_can_i_pass_this_dynamic_variable,"w");
file.write("helloworld");
return this.$init(str1);
};
你知道我该怎么做吗?
谢谢。
最佳答案
使用发送
Java.use('java.net.URL').$init.overload('java.lang.String').implementation = function(str1) {
send(dynamic_variable);
return this.$init(str1);
};
在Python端
f = open('/tmp/log', 'w')
# ...
def on_message(msg, _data):
f.write(msg['payload'] + '\n')
# ...
script.on('message', on_message)
除非您想写入手机上的文件
var f = new File("/sdcard/log.txt", "w");
f.write("line\n");
f.flush();
f.close();
关于python - Frida python 将输出重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62072031/