This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 356
/
filesync_protocol.txt
84 lines (69 loc) · 2.44 KB
/
filesync_protocol.txt
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
The missing sync.txt from android's ADB.
Message Format:
Every message starts with a single 32-bit word. (Everything is little-endian).
Depending on that first word, the rest of the data can have various meanings.
Messages from the host/desktop to the device always start with a 'request'
message of a u32 command, u32 size, and size more bytes that's a filename,
directory or symlink.
The command here is referred to as 'id' in the code and the 4-letter codes
are prefixed by ID_, eg ID_STAT.
The command IDs are the little endian hexadecimal representations of the
4-letter command codes.
STAT:
request:
u32 command = 'STAT' == 0x54415453
u32 size = len(filename) < 1024
u8 data[size] = filename (no null)
response:
struct stat st = lstat(filename)
u32 command = 'STAT'
u32 mode = st.st_mode
u32 size = st.st_size
u32 time = st.st_mtime
LIST:
request:
u32 command = 'LIST' == 0x5453494C
u32 size = len(path) < 1024
u8 data[size] = path (no null)
response:
for each filename in listing of path:
struct stat st = lstat(filename)
u32 command = 'DENT' == 0x544E4544
u32 mode = st.st_mode
u32 size = st.st_size
u32 time = st.st_mtime
u32 namelen = len(filename)
u8 data[namelen] = filename
done (device -> host):
u32 command = 'DONE' == 0x454E4F44
u32[4] = 0
SEND:
struct stat st = lstat(filename)
request:
fileinfo = sprintf(',%d', st.st_mode)
u32 command = 'SEND' == 0x444E4553
u32 size = len(filename) + len(fileinfo) < 1024
u8 data[size] = filename + fileinfo
repeated data command (host -> device):
u32 command = 'DATA' == 0x41544144
u32 size < (64 * 1024)
u8 data[size] = file contents
finish command (host -> device):
u32 command = 'DONE' == 0x454E4F44
u32 timestamp = st.st_mtime
response (device -> host):
u32 command = 'OKAY' == 0x59414BF4 or 'FAIL' == 0x4C494146
u32 size = 0 if 'OKAY' else len(fail_message)
u8 data[] = fail_message
RECV:
request:
u32 command = 'RECV' == 0x56434552
u32 size = len(filename)
u8 data[size] = filename
repeated data response (device -> host):
u32 command = 'DATA' == 0x41544144
u32 size < (64 * 1024)
u8 data[size] = file contents
finish response (device -> host):
u32 command = 'DONE' == 0x454E4F44
u32 size = 0