Skip to content

Commit

Permalink
gumjs: Support receiving binary data in RPC methods
Browse files Browse the repository at this point in the history
Co-authored-by: Håvard Sørbø <[email protected]>
Co-authored-by: Ole André Vadla Ravnås <[email protected]>
  • Loading branch information
3 people committed May 31, 2024
1 parent 7551907 commit b47d3c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bindings/gumjs/runtime/message-dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit b47d3c3

Please sign in to comment.