diff --git a/inject/inject.vala b/inject/inject.vala index fbb86b3e6..032d14b16 100644 --- a/inject/inject.vala +++ b/inject/inject.vala @@ -415,7 +415,7 @@ namespace Frida.Inject { buf[n] = 0; if (script_runner.terminal_mode == TerminalMode.BINARY) { - var bytes = new Bytes (buf[0:n]); + var bytes = new Bytes (buf[:n]); script_runner.on_stdin ("", bytes); } else { script_runner.on_stdin ((string) buf, null); @@ -740,14 +740,13 @@ namespace Frida.Inject { return false; var tuple = payload.get_array (); - if (tuple.get_length () < 1) + var tuple_len = tuple.get_length (); + if (tuple_len == 0) return false; - var first_element = tuple.get_element (0); - if (first_element.get_value_type () != typeof (string)) + var type = tuple.get_element (0).get_string (); + if (type == null) return false; - - var type = first_element.get_string (); switch (type) { case "frida:stdout": case "frida:stderr": @@ -756,26 +755,21 @@ namespace Frida.Inject { return false; } - if (tuple.get_length () > 1) { - var second_element = tuple.get_element (1); - - if (second_element.get_value_type () != typeof (string)) + if (tuple_len >= 2) { + var str = tuple.get_element (1).get_string (); + if (str == null) return false; - var str = second_element.get_string (); - - if (str != null) { - switch (type) { - case "frida:stdout": - stdout.write (str.data); - stdout.flush (); - break; - case "frida:stderr": - stderr.write (str.data); - break; - default: - return false; - } + switch (type) { + case "frida:stdout": + stdout.write (str.data); + stdout.flush (); + break; + case "frida:stderr": + stderr.write (str.data); + break; + default: + return false; } } @@ -792,6 +786,7 @@ namespace Frida.Inject { return false; } } + return true; } diff --git a/src/barebone/script.vala b/src/barebone/script.vala index d99325709..fb769cc90 100644 --- a/src/barebone/script.vala +++ b/src/barebone/script.vala @@ -420,7 +420,7 @@ namespace Frida { public void post (string json, Bytes? data) { var json_val = ctx.make_string (json); - var data_val = ctx.make_array_buffer (data.get_data ()); + var data_val = (data != null) ? ctx.make_array_buffer (data.get_data ()) : QuickJS.Null; invoke_void (dispatch_message_func, { json_val, data_val }, runtime_obj); ctx.free_value (data_val); ctx.free_value (json_val); diff --git a/src/host-session-service.vala b/src/host-session-service.vala index cd8f01e08..1ac80ca60 100644 --- a/src/host-session-service.vala +++ b/src/host-session-service.vala @@ -1335,7 +1335,8 @@ namespace Frida { protected virtual void on_event (string type, Json.Array event) { } - protected async Json.Node call (string method, Json.Node[] args, Bytes? data, Cancellable? cancellable) throws Error, IOError { + protected async Json.Node call (string method, Json.Node[] args, Bytes? data, Cancellable? cancellable) + throws Error, IOError { yield ensure_loaded (cancellable); return yield rpc_client.call (method, args, data, cancellable);