javascript代码:
rpc.exports = {
something: function (data, size) {
// data maybe ArrayBuffer
}
}
python代码:
zip = gzip.compress(json.dumps(info).encode('utf8')) # zip -> bytes
script.exports.something(zip, len(zip))
根据Frida的文档,JavaScript可以通过send
方法将字节数组传递给python,那么有没有什么方法可以将字节数组从python传递给JavaScript呢?
回答你的问题
Python
script.exports.something([0x33, 0x34, 0x35], 3)
JS
rpc.exports = {
something: function (data, size) {
console.log(JSON.stringify(data), size);
// output: [51,52,53] 3
}
}
更复杂的例子,希望能回答未来的问题;
python侧:
def on_message(msg, data):
if msg['payload'] == 'tag1':
print('bytes from js:', data)
# sending bytes to js
script.post({'type': 'tag2', 'payload': list([0x33, 0x34, 0x35])})
javascript端:
// send bytes to python
send("tag1", ptr(0x1234).readByteArray(64));
recv('tag2', function (value) {
var data = value.payload;
console.log('received bytes from python:', data, 'size:', data.length);
})
.wait(); // block until python respond