diff --git a/bindings/gumjs/runtime/message-dispatcher.js b/bindings/gumjs/runtime/message-dispatcher.js index e9539b6fc..035fe03db 100644 --- a/bindings/gumjs/runtime/message-dispatcher.js +++ b/bindings/gumjs/runtime/message-dispatcher.js @@ -26,14 +26,14 @@ function MessageDispatcher() { function handleMessage(rawMessage, data) { const message = JSON.parse(rawMessage); if (message instanceof Array && message[0] === 'frida:rpc') { - handleRpcMessage(message[1], message[2], message.slice(3)); + handleRpcMessage(message[1], message[2], message.slice(3), data); } else { messages.push([message, data]); dispatchMessages(); } } - function handleRpcMessage(id, operation, params) { + function handleRpcMessage(id, operation, params, data) { const exports = rpc.exports; if (operation === 'call') { @@ -46,7 +46,7 @@ function MessageDispatcher() { } try { - const result = exports[method].apply(exports, args); + const result = exports[method].call(exports, ...args, data); if (typeof result === 'object' && result !== null && typeof result.then === 'function') { result diff --git a/tests/gumjs/script.c b/tests/gumjs/script.c index 1fa9ac210..32916329d 100644 --- a/tests/gumjs/script.c +++ b/tests/gumjs/script.c @@ -50,6 +50,7 @@ TESTLIST_BEGIN (script) TESTENTRY (method_can_throw_sync) TESTENTRY (method_can_throw_async) TESTENTRY (method_can_return_null) + TESTENTRY (method_can_receive_binary_data) TESTENTRY (method_can_return_binary_data) TESTENTRY (method_list_can_be_queried) TESTENTRY (calling_inexistent_method_should_throw_error) @@ -6040,6 +6041,25 @@ TESTCASE (method_can_return_null) EXPECT_SEND_MESSAGE_WITH ("[\"frida:rpc\",42,\"ok\",null]"); } +TESTCASE (method_can_receive_binary_data) +{ + const guint8 data_to_send[2] = { 0x13, 0x37 }; + GBytes * bytes; + + COMPILE_AND_LOAD_SCRIPT ( + "rpc.exports.eat = (str, data) => {" + "send(str, data);" + "}"); + + bytes = g_bytes_new_static (data_to_send, sizeof (data_to_send)); + gum_script_post (fixture->script, + "[\"frida:rpc\",42,\"call\",\"eat\",[\"yoghurt\"]]", bytes); + g_bytes_unref (bytes); + + EXPECT_SEND_MESSAGE_WITH_PAYLOAD_AND_DATA ("\"yoghurt\"", "13 37"); + EXPECT_SEND_MESSAGE_WITH ("[\"frida:rpc\",42,\"ok\",null]"); +} + TESTCASE (method_can_return_binary_data) { COMPILE_AND_LOAD_SCRIPT (