如何在 python 和 frida 中的 js 之间传递字节(ArrayBuffer)?

How to pass bytes(ArrayBuffer) between python & js in frida?

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传给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