Frida python 将输出重定向到文件

Frida python redirect outpout to file

我正在使用 frida-python 来挂钩 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);
};

你知道我该怎么做吗??

谢谢。

使用send

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)

除非您想写入 phone

上的文件
    var f = new File("/sdcard/log.txt", "w");
    f.write("line\n");
    f.flush();
    f.close();