Commit 3469f56012c5311187dbded8d102d1a11ec4cf3c
Add builtin handler for Android Debug Bridge (ADB) protocol
This allows Android devices to run multiple services on one port. A common use case involves muxing SSH for SCP / SFTP, and ADB for sideloading packages or running CTS. Signed-off-by: Kevin Cernekee <cernekee@chromium.org>Kevin Cernekee authored on 6/9/2015, 10:09:44 PM
Kevin Cernekee committed on 6/9/2015, 10:30:27 PM
Parent: 7c35ef8528d47b97894a6495275b57dc1ae3f8c7
Files changed
probe.c | changed |
probe.c | ||
---|---|---|
@@ -32,8 +32,9 @@ | ||
32 | 32 | static int is_tinc_protocol(const char *p, int len, struct proto*); |
33 | 33 | static int is_xmpp_protocol(const char *p, int len, struct proto*); |
34 | 34 | static int is_http_protocol(const char *p, int len, struct proto*); |
35 | 35 | static int is_tls_protocol(const char *p, int len, struct proto*); |
36 | +static int is_adb_protocol(const char *p, int len, struct proto*); | |
36 | 37 | static int is_true(const char *p, int len, struct proto* proto) { return 1; } |
37 | 38 | |
38 | 39 | /* Table of protocols that have a built-in probe |
39 | 40 | */ |
@@ -45,8 +46,9 @@ | ||
45 | 46 | { "xmpp", NULL, NULL, is_xmpp_protocol }, |
46 | 47 | { "http", NULL, NULL, is_http_protocol }, |
47 | 48 | { "ssl", NULL, NULL, is_tls_protocol }, |
48 | 49 | { "tls", NULL, NULL, is_tls_protocol }, |
50 | + { "adb", NULL, NULL, is_adb_protocol }, | |
49 | 51 | { "anyprot", NULL, NULL, is_true } |
50 | 52 | }; |
51 | 53 | |
52 | 54 | static struct proto *protocols; |
@@ -223,8 +225,24 @@ | ||
223 | 225 | */ |
224 | 226 | return p[0] == 0x16 && p[1] == 0x03 && ( p[2] >= 0 && p[2] <= 0x03); |
225 | 227 | } |
226 | 228 | |
229 | +static int is_adb_protocol(const char *p, int len, struct proto *proto) | |
230 | +{ | |
231 | + if (len < 30) | |
232 | + return PROBE_AGAIN; | |
233 | + | |
234 | + /* The initial ADB host->device packet has a command type of CNXN, and a | |
235 | + * data payload starting with "host:". Note that current versions of the | |
236 | + * client hardcode "host::" (with empty serialno and banner fields) but | |
237 | + * other clients may populate those fields. | |
238 | + * | |
239 | + * We aren't checking amessage.data_length, under the assumption that | |
240 | + * a packet >= 30 bytes long will have "something" in the payload field. | |
241 | + */ | |
242 | + return !memcmp(&p[0], "CNXN", 4) && !memcmp(&p[24], "host:", 5); | |
243 | +} | |
244 | + | |
227 | 245 | static int regex_probe(const char *p, int len, struct proto *proto) |
228 | 246 | { |
229 | 247 | regex_t **probe = proto->data; |
230 | 248 | regmatch_t pos = { 0, len }; |
Built with git-ssb-web