Skip to content

Commit

Permalink
fruity: Advertise our RemoteXPC protocol support
Browse files Browse the repository at this point in the history
Like macOS does, but with most of the properties omitted.

We do this to more closely mimic macOS' behavior, and to avoid an error
ending up in the syslog:

    Invalid or missing remote device connection version flags

Co-authored-by: Håvard Sørbø <[email protected]>
  • Loading branch information
oleavr and hsorbo committed Sep 18, 2024
1 parent 24a1f79 commit 7e21f5c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/base/value.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Frida {
public abstract unowned ObjectBuilder add_uint64_value (uint64 val);
public abstract unowned ObjectBuilder add_data_value (Bytes val);
public abstract unowned ObjectBuilder add_string_value (string val);
public abstract unowned ObjectBuilder add_uuid_value (uint8[] val);
public abstract unowned ObjectBuilder add_raw_value (Bytes val);

public abstract Bytes build ();
Expand Down Expand Up @@ -238,6 +239,10 @@ namespace Frida {
return this;
}

public unowned ObjectBuilder add_uuid_value (uint8[] val) {
assert_not_reached ();
}

public unowned ObjectBuilder add_raw_value (Bytes val) {
string uuid = Uuid.string_random ();
builder.add_string_value (uuid);
Expand Down
38 changes: 37 additions & 1 deletion src/fruity/xpc.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Frida.Fruity {
private Promise<Variant> handshake_promise = new Promise<Variant> ();
private Variant handshake_body;

private Cancellable io_cancellable = new Cancellable ();

public static async DiscoveryService open (IOStream stream, Cancellable? cancellable = null) throws Error, IOError {
var service = new DiscoveryService (stream);

Expand Down Expand Up @@ -42,6 +44,7 @@ namespace Frida.Fruity {
}

public void close () {
io_cancellable.cancel ();
connection.cancel ();
}

Expand Down Expand Up @@ -87,8 +90,30 @@ namespace Frida.Fruity {
reader.read_member ("MessageType");
unowned string message_type = reader.get_string_value ();

if (message_type == "Handshake")
if (message_type == "Handshake") {
handshake_promise.resolve (msg.body);

connection.post.begin (
new XpcBodyBuilder ()
.begin_dictionary ()
.set_member_name ("MessageType")
.add_string_value ("Handshake")
.set_member_name ("MessagingProtocolVersion")
.add_uint64_value (5)
.set_member_name ("Services")
.begin_dictionary ()
.end_dictionary ()
.set_member_name ("Properties")
.begin_dictionary ()
.set_member_name ("RemoteXPCVersionFlags")
.add_uint64_value (0x100000000000006)
.end_dictionary ()
.set_member_name ("UUID")
.add_uuid_value (make_random_v4_uuid ())
.end_dictionary ()
.build (),
io_cancellable);
}
} catch (Error e) {
}
}
Expand Down Expand Up @@ -3778,4 +3803,15 @@ namespace Frida.Fruity {

return result.str;
}

private uint8[] make_random_v4_uuid () {
uint8 uuid[16];
OpenSSL.Rng.generate (uuid);

const uint8 uuid_version = 4;
uuid[6] = (uuid_version << 4) | (uuid[6] & 0xf);
uuid[8] = 0x80 | (uuid[8] & 0x3f);

return uuid;
}
}

0 comments on commit 7e21f5c

Please sign in to comment.