forked from facebookarchive/fb-adb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.h
228 lines (193 loc) · 5.32 KB
/
proto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in
* the LICENSE file in the root directory of this source tree. An
* additional grant of patent rights can be found in the PATENTS file
* in the same directory.
*
*/
#pragma once
#include <stdint.h>
#pragma pack(push, 1)
/* The world is little-endian */
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
# error "fb-adb is not ported to big-endian systems"
#endif
#define ENUM_MSG_TYPES(_m) \
_m(MSG_CHANNEL_DATA) \
_m(MSG_CHANNEL_DATA_LZ4) \
_m(MSG_CHANNEL_WINDOW) \
_m(MSG_CHANNEL_CLOSE) \
_m(MSG_CHILD_EXIT) \
_m(MSG_ERROR) \
_m(MSG_WINDOW_SIZE) \
_m(MSG_SHEX_HELLO) \
_m(MSG_CMDLINE_ARGUMENT) \
_m(MSG_CMDLINE_ARGUMENT_JUMBO) \
_m(MSG_CLEARENV) \
_m(MSG_ENVIRONMENT_VARIABLE_SET) \
_m(MSG_ENVIRONMENT_VARIABLE_UNSET) \
_m(MSG_ENVIRONMENT_VARIABLE_SET_JUMBO) \
_m(MSG_ENVIRONMENT_VARIABLE_UNSET_JUMBO) \
_m(MSG_CMDLINE_DEFAULT_SH) \
_m(MSG_CMDLINE_DEFAULT_SH_LOGIN) \
_m(MSG_CMDLINE_EXEC_FILE) \
_m(MSG_CMDLINE_SELF_ARGV0) \
_m(MSG_EXEC_AS_ROOT) \
_m(MSG_EXEC_AS_USER) \
_m(MSG_CHDIR) \
_m(MSG_REBIND_TO_UNIX_SOCKET) \
_m(MSG_REBIND_TO_TCP4_SOCKET) \
_m(MSG_REBIND_TO_TCP6_SOCKET) \
_m(MSG_LISTENING_ON_SOCKET) \
_m(MSG_OPEN_EXEC_FILE) \
_m(MSG_EXEC_FILE_OK) \
_m(MSG_EXEC_FILE_MISMATCH)
enum msg_type {
MSG_TYPE_PRE = 39, // Make sure zero is not a valid message
#define M(_name) _name,
ENUM_MSG_TYPES(M)
#undef M
};
#define MSG_MAX_SIZE UINT16_MAX
struct msg {
uint16_t size;
uint16_t type;
};
struct msg_channel_data {
struct msg msg;
uint8_t channel;
char data[0];
};
struct msg_channel_data_lz4 {
struct msg msg;
uint16_t uncompressed_size;
uint8_t channel;
char data[0];
};
struct msg_channel_window {
struct msg msg;
uint32_t window_delta;
uint8_t channel;
};
struct msg_channel_close {
struct msg msg;
uint8_t channel;
};
struct msg_error {
struct msg msg;
char text[0];
};
struct msg_child_exit {
struct msg msg;
uint8_t exit_status;
};
struct window_size {
uint16_t row;
uint16_t col;
uint16_t xpixel;
uint16_t ypixel;
};
struct msg_window_size {
struct msg msg;
struct window_size ws;
};
struct term_control {
uint8_t value;
char name[9];
};
struct stream_information {
uint32_t bufsz;
unsigned pty_p : 1;
unsigned compress : 1;
};
struct msg_shex_hello {
struct msg msg;
uint32_t stub_recv_bufsz;
uint32_t stub_send_bufsz;
uint32_t nr_argv;
uint32_t ispeed;
uint32_t ospeed;
uint16_t maxmsg;
struct window_size ws;
uint8_t have_ws;
uint8_t posix_vdisable_value;
uint8_t ctty_p;
struct stream_information si[3];
struct term_control tctl[0]; // Must be last
};
struct msg_cmdline_argument {
struct msg msg;
char value[0];
};
struct msg_cmdline_argument_jumbo {
struct msg msg;
uint32_t actual_size;
// Large argument follows.
};
struct msg_environment_variable_set {
struct msg msg;
char value[0]; // NUL separates name and value.
};
struct msg_environment_variable_set_jumbo {
struct msg msg;
uint32_t name_length;
uint32_t value_length;
};
struct msg_environment_variable_unset {
struct msg msg;
char name[0];
};
struct msg_environment_variable_unset_jumbo {
struct msg msg;
uint32_t name_length;
// Name follows
};
struct msg_exec_as_user {
struct msg msg;
uint8_t shell_thunk;
char username[0];
};
struct msg_chdir {
struct msg msg;
char dir[0];
};
struct msg_rebind_to_unix_socket {
struct msg msg;
char socket[0];
};
struct msg_rebind_to_tcp4_socket {
struct msg msg;
uint16_t port;
uint32_t addr; // Like in_addr
};
struct msg_rebind_to_tcp6_socket {
struct msg msg;
uint16_t port;
uint8_t addr[16]; // Like in6_addr
};
struct msg_open_exec_file {
struct msg msg;
// No need for all 32 bytes of the hash
uint8_t expected_sha256_hash[16];
char basename[0];
};
struct msg_exec_file_mismatch {
struct msg msg;
char filename_to_update[0];
};
#pragma pack(pop)
static const unsigned CHILD_STDIN = 2;
static const unsigned CHILD_STDOUT = 3;
static const unsigned CHILD_STDERR = 4;
// Base64 of 128 bits is 22 characters long; plus NUL, 23
#define FB_ADB_ARCH_X86 (1<<0)
#define FB_ADB_ARCH_AMD64 (1<<1)
#define FB_ADB_ARCH_ARM (1<<2)
#define FB_ADB_ARCH_AARCH64 (1<<3)
#define FB_ADB_FINGERPRINT_LENGTH 22
#define FB_ADB_PROTO_START_LINE "FB_ADB %22s (x=%x) (u=%x) (a=%x)"
#define FB_ADB_STUB_DAEMON_SOCKET_NAME_LENGTH 44
#define FB_ADB_STUB_DAEMON_LINE "FB_ADB %22s (listening@%44s pid=%u)"