@yume-chan/adb 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +54 -0
- package/CHANGELOG.md +25 -1
- package/README.md +220 -103
- package/esm/adb.d.ts +43 -60
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +68 -249
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +17 -0
- package/esm/banner.d.ts.map +1 -0
- package/esm/banner.js +67 -0
- package/esm/banner.js.map +1 -0
- package/esm/commands/base.d.ts +6 -6
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +8 -8
- package/esm/commands/framebuffer.d.ts +53 -53
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +46 -46
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +7 -8
- package/esm/commands/index.d.ts.map +1 -1
- package/esm/commands/index.js +7 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/power.d.ts +22 -22
- package/esm/commands/power.js +48 -48
- package/esm/commands/reverse.d.ts +40 -28
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +130 -100
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +57 -51
- package/esm/commands/subprocess/command.d.ts.map +1 -1
- package/esm/commands/subprocess/command.js +86 -80
- package/esm/commands/subprocess/command.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -3
- package/esm/commands/subprocess/index.js +3 -3
- package/esm/commands/subprocess/protocols/index.d.ts +3 -3
- package/esm/commands/subprocess/protocols/index.js +3 -3
- package/esm/commands/subprocess/protocols/none.d.ts +30 -35
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +65 -55
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +33 -38
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +172 -162
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +48 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/types.js +1 -1
- package/esm/commands/subprocess/utils.d.ts +1 -1
- package/esm/commands/subprocess/utils.js +18 -18
- package/esm/commands/sync/index.d.ts +8 -7
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +8 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +42 -40
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +67 -47
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +13 -11
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +35 -37
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +57 -7
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +89 -22
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +26 -23
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +40 -42
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +19 -19
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +54 -54
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +22 -0
- package/esm/commands/sync/socket.d.ts.map +1 -0
- package/esm/commands/sync/socket.js +69 -0
- package/esm/commands/sync/socket.js.map +1 -0
- package/esm/commands/sync/stat.d.ts +72 -72
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +116 -104
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +65 -60
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +123 -149
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +5 -5
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +20 -18
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/{auth.d.ts → daemon/auth.d.ts} +50 -51
- package/esm/daemon/auth.d.ts.map +1 -0
- package/esm/{auth.js → daemon/auth.js} +95 -96
- package/esm/daemon/auth.js.map +1 -0
- package/esm/daemon/connection.d.ts +11 -0
- package/esm/daemon/connection.d.ts.map +1 -0
- package/esm/daemon/connection.js +2 -0
- package/esm/daemon/connection.js.map +1 -0
- package/esm/{crypto.d.ts → daemon/crypto.d.ts} +36 -36
- package/esm/daemon/crypto.d.ts.map +1 -0
- package/esm/{crypto.js → daemon/crypto.js} +244 -248
- package/esm/daemon/crypto.js.map +1 -0
- package/esm/daemon/device.d.ts +9 -0
- package/esm/daemon/device.d.ts.map +1 -0
- package/esm/daemon/device.js +2 -0
- package/esm/daemon/device.js.map +1 -0
- package/esm/daemon/dispatcher.d.ts +42 -0
- package/esm/daemon/dispatcher.d.ts.map +1 -0
- package/esm/{socket → daemon}/dispatcher.js +225 -234
- package/esm/daemon/dispatcher.js.map +1 -0
- package/esm/daemon/index.d.ts +8 -0
- package/esm/daemon/index.d.ts.map +1 -0
- package/esm/daemon/index.js +8 -0
- package/esm/daemon/index.js.map +1 -0
- package/esm/{packet.d.ts → daemon/packet.d.ts} +45 -46
- package/esm/daemon/packet.d.ts.map +1 -0
- package/esm/{packet.js → daemon/packet.js} +43 -48
- package/esm/daemon/packet.js.map +1 -0
- package/esm/daemon/socket.d.ts +58 -0
- package/esm/daemon/socket.d.ts.map +1 -0
- package/esm/{socket → daemon}/socket.js +121 -118
- package/esm/daemon/socket.js.map +1 -0
- package/esm/daemon/transport.d.ts +45 -0
- package/esm/daemon/transport.d.ts.map +1 -0
- package/esm/daemon/transport.js +184 -0
- package/esm/daemon/transport.js.map +1 -0
- package/esm/features.d.ts +10 -7
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +13 -10
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +7 -9
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -9
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +78 -0
- package/esm/server/client.d.ts.map +1 -0
- package/esm/server/client.js +329 -0
- package/esm/server/client.js.map +1 -0
- package/esm/server/index.d.ts +3 -0
- package/esm/server/index.d.ts.map +1 -0
- package/esm/server/index.js +3 -0
- package/esm/server/index.js.map +1 -0
- package/esm/server/transport.d.ts +19 -0
- package/esm/server/transport.d.ts.map +1 -0
- package/esm/server/transport.js +44 -0
- package/esm/server/transport.js.map +1 -0
- package/esm/utils/auto-reset-event.d.ts +8 -9
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +33 -33
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +27 -27
- package/esm/utils/base64.js +246 -246
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/conditional-variable.d.ts +8 -0
- package/esm/utils/conditional-variable.d.ts.map +1 -0
- package/esm/utils/conditional-variable.js +34 -0
- package/esm/utils/conditional-variable.js.map +1 -0
- package/esm/utils/hex.d.ts +3 -0
- package/esm/utils/hex.d.ts.map +1 -0
- package/esm/utils/hex.js +55 -0
- package/esm/utils/hex.js.map +1 -0
- package/esm/utils/index.d.ts +6 -3
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +6 -3
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/no-op.d.ts +7 -0
- package/esm/utils/no-op.d.ts.map +1 -0
- package/esm/utils/no-op.js +12 -0
- package/esm/utils/no-op.js.map +1 -0
- package/package.json +14 -12
- package/src/adb.ts +47 -248
- package/src/banner.ts +82 -0
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +7 -8
- package/src/commands/power.ts +2 -2
- package/src/commands/reverse.ts +90 -70
- package/src/commands/subprocess/command.ts +12 -4
- package/src/commands/subprocess/index.ts +3 -3
- package/src/commands/subprocess/protocols/index.ts +3 -3
- package/src/commands/subprocess/protocols/none.ts +36 -23
- package/src/commands/subprocess/protocols/shell.ts +94 -74
- package/src/commands/subprocess/protocols/types.ts +7 -7
- package/src/commands/subprocess/utils.ts +1 -1
- package/src/commands/sync/index.ts +8 -7
- package/src/commands/sync/list.ts +44 -25
- package/src/commands/sync/pull.ts +40 -45
- package/src/commands/sync/push.ts +158 -39
- package/src/commands/sync/request.ts +21 -16
- package/src/commands/sync/response.ts +10 -9
- package/src/commands/sync/socket.ts +99 -0
- package/src/commands/sync/stat.ts +47 -42
- package/src/commands/sync/sync.ts +73 -116
- package/src/commands/tcpip.ts +9 -7
- package/src/{auth.ts → daemon/auth.ts} +24 -23
- package/src/{crypto.ts → daemon/crypto.ts} +25 -33
- package/src/daemon/device.ts +14 -0
- package/src/{socket → daemon}/dispatcher.ts +95 -117
- package/src/daemon/index.ts +7 -0
- package/src/daemon/packet.ts +75 -0
- package/src/{socket → daemon}/socket.ts +71 -56
- package/src/daemon/transport.ts +269 -0
- package/src/features.ts +9 -6
- package/src/index.ts +3 -5
- package/src/server/client.ts +476 -0
- package/src/server/index.ts +2 -0
- package/src/server/transport.ts +77 -0
- package/src/utils/auto-reset-event.ts +14 -15
- package/src/utils/conditional-variable.ts +45 -0
- package/src/utils/hex.ts +58 -0
- package/src/utils/index.ts +6 -3
- package/src/utils/no-op.ts +12 -0
- package/tsconfig.build.json +12 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/auth.d.ts.map +0 -1
- package/esm/auth.js.map +0 -1
- package/esm/backend.d.ts +0 -9
- package/esm/backend.d.ts.map +0 -1
- package/esm/backend.js +0 -2
- package/esm/backend.js.map +0 -1
- package/esm/commands/install.d.ts +0 -4
- package/esm/commands/install.d.ts.map +0 -1
- package/esm/commands/install.js +0 -29
- package/esm/commands/install.js.map +0 -1
- package/esm/crypto.d.ts.map +0 -1
- package/esm/crypto.js.map +0 -1
- package/esm/packet.d.ts.map +0 -1
- package/esm/packet.js.map +0 -1
- package/esm/socket/dispatcher.d.ts +0 -60
- package/esm/socket/dispatcher.d.ts.map +0 -1
- package/esm/socket/dispatcher.js.map +0 -1
- package/esm/socket/index.d.ts +0 -3
- package/esm/socket/index.d.ts.map +0 -1
- package/esm/socket/index.js +0 -3
- package/esm/socket/index.js.map +0 -1
- package/esm/socket/socket.d.ts +0 -60
- package/esm/socket/socket.d.ts.map +0 -1
- package/esm/socket/socket.js.map +0 -1
- package/src/backend.ts +0 -14
- package/src/commands/install.ts +0 -40
- package/src/packet.ts +0 -90
- package/src/socket/index.ts +0 -2
|
@@ -1,235 +1,226 @@
|
|
|
1
|
-
import { AsyncOperationManager, PromiseResolver } from "@yume-chan/async";
|
|
2
|
-
import { AbortController, WritableStream, } from "@yume-chan/stream-extra";
|
|
3
|
-
import { EMPTY_UINT8_ARRAY } from "@yume-chan/struct";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
/**
|
|
8
|
-
* The dispatcher is the "dumb" part of the connection handling logic.
|
|
9
|
-
*
|
|
10
|
-
* Except some options to change some minor behaviors,
|
|
11
|
-
* its only job is forwarding packets between authenticated underlying streams
|
|
12
|
-
* and abstracted socket objects.
|
|
13
|
-
*
|
|
14
|
-
* The `Adb` class is responsible for doing the authentication,
|
|
15
|
-
* negotiating the options, and has shortcuts to high-level services.
|
|
16
|
-
*/
|
|
17
|
-
export class AdbPacketDispatcher {
|
|
18
|
-
// ADB socket id starts from 1
|
|
19
|
-
// (0 means open failed)
|
|
20
|
-
initializers = new AsyncOperationManager(1);
|
|
21
|
-
/**
|
|
22
|
-
* Socket local ID to the socket controller.
|
|
23
|
-
*/
|
|
24
|
-
sockets = new Map();
|
|
25
|
-
|
|
26
|
-
options;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get disconnected() {
|
|
30
|
-
return this.
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
constructor(connection, options) {
|
|
35
|
-
this.options = options;
|
|
36
|
-
connection.readable
|
|
37
|
-
.pipeTo(new WritableStream({
|
|
38
|
-
write: async (packet) => {
|
|
39
|
-
switch (packet.command) {
|
|
40
|
-
case AdbCommand.OK:
|
|
41
|
-
this.handleOk(packet);
|
|
42
|
-
break;
|
|
43
|
-
case AdbCommand.Close:
|
|
44
|
-
await this.handleClose(packet);
|
|
45
|
-
break;
|
|
46
|
-
case AdbCommand.Write:
|
|
47
|
-
if (this
|
|
48
|
-
await this
|
|
49
|
-
.get(packet.arg1)
|
|
50
|
-
.enqueue(packet.payload);
|
|
51
|
-
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
throw new Error(`Unknown local socket id: ${packet.arg1}`);
|
|
55
|
-
case AdbCommand.Open:
|
|
56
|
-
await this.handleOpen(packet);
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
// Junk data may only appear in the authentication phase,
|
|
60
|
-
// since the dispatcher only works after authentication,
|
|
61
|
-
// all packets should have a valid command.
|
|
62
|
-
// (although it's possible that Adb added new commands in the future)
|
|
63
|
-
throw new Error(`Unknown command: ${packet.command.toString(16)}`);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
}), {
|
|
67
|
-
// There are multiple reasons for the pipe to stop,
|
|
68
|
-
// (device disconnection, protocol error, or user abortion)
|
|
69
|
-
// if the underlying streams are still open,
|
|
70
|
-
// it's still possible to create another ADB connection.
|
|
71
|
-
// So don't close `readable` here.
|
|
72
|
-
preventCancel: true,
|
|
73
|
-
signal: this.
|
|
74
|
-
})
|
|
75
|
-
.then(() => {
|
|
76
|
-
this.dispose();
|
|
77
|
-
}, (e) => {
|
|
78
|
-
if (!this
|
|
79
|
-
this.
|
|
80
|
-
}
|
|
81
|
-
this.dispose();
|
|
82
|
-
});
|
|
83
|
-
this
|
|
84
|
-
}
|
|
85
|
-
handleOk(packet) {
|
|
86
|
-
if (this
|
|
87
|
-
// Device successfully created the socket
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const socket = this
|
|
91
|
-
if (socket) {
|
|
92
|
-
// Device has received last `WRTE` to the socket
|
|
93
|
-
socket.ack();
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
// Maybe the device is responding to a packet of last connection
|
|
97
|
-
// Tell the device to close the socket
|
|
98
|
-
void this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
99
|
-
}
|
|
100
|
-
async handleClose(packet) {
|
|
101
|
-
// If the socket is still pending
|
|
102
|
-
if (packet.arg0 === 0 &&
|
|
103
|
-
this
|
|
104
|
-
// Device failed to create the socket
|
|
105
|
-
// (unknown service string, failed to execute command, etc.)
|
|
106
|
-
// it doesn't break the connection,
|
|
107
|
-
// so only reject the socket creation promise,
|
|
108
|
-
// don't throw an error here.
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
// From https://android.googlesource.com/platform/packages/modules/adb/+/65d18e2c1cc48b585811954892311b28a4c3d188/adb.cpp#459
|
|
112
|
-
/* According to protocol.txt, p->msg.arg0 might be 0 to indicate
|
|
113
|
-
* a failed OPEN only. However, due to a bug in previous ADB
|
|
114
|
-
* versions, CLOSE(0, remote-id, "") was also used for normal
|
|
115
|
-
* CLOSE() operations.
|
|
116
|
-
*/
|
|
117
|
-
// Ignore `arg0` and search for the socket
|
|
118
|
-
const socket = this
|
|
119
|
-
if (socket) {
|
|
120
|
-
// The device want to close the socket
|
|
121
|
-
if (!socket.closed) {
|
|
122
|
-
await this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
123
|
-
}
|
|
124
|
-
await socket.dispose();
|
|
125
|
-
this
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
// TODO: adb: is double closing an socket a catastrophic error?
|
|
129
|
-
// If the client sends two `CLSE` packets for one socket,
|
|
130
|
-
// the device may also respond with two `CLSE` packets.
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
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
|
-
const
|
|
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
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
dispose() {
|
|
227
|
-
for (const socket of this.sockets.values()) {
|
|
228
|
-
socket.dispose().catch((e) => {
|
|
229
|
-
void e;
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
this._disconnected.resolve();
|
|
233
|
-
}
|
|
234
|
-
}
|
|
1
|
+
import { AsyncOperationManager, PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { AbortController, ConsumableWritableStream, WritableStream, } from "@yume-chan/stream-extra";
|
|
3
|
+
import { EMPTY_UINT8_ARRAY } from "@yume-chan/struct";
|
|
4
|
+
import { decodeUtf8, encodeUtf8, unreachable } from "../utils/index.js";
|
|
5
|
+
import { AdbCommand, calculateChecksum } from "./packet.js";
|
|
6
|
+
import { AdbDaemonSocketController } from "./socket.js";
|
|
7
|
+
/**
|
|
8
|
+
* The dispatcher is the "dumb" part of the connection handling logic.
|
|
9
|
+
*
|
|
10
|
+
* Except some options to change some minor behaviors,
|
|
11
|
+
* its only job is forwarding packets between authenticated underlying streams
|
|
12
|
+
* and abstracted socket objects.
|
|
13
|
+
*
|
|
14
|
+
* The `Adb` class is responsible for doing the authentication,
|
|
15
|
+
* negotiating the options, and has shortcuts to high-level services.
|
|
16
|
+
*/
|
|
17
|
+
export class AdbPacketDispatcher {
|
|
18
|
+
// ADB socket id starts from 1
|
|
19
|
+
// (0 means open failed)
|
|
20
|
+
#initializers = new AsyncOperationManager(1);
|
|
21
|
+
/**
|
|
22
|
+
* Socket local ID to the socket controller.
|
|
23
|
+
*/
|
|
24
|
+
#sockets = new Map();
|
|
25
|
+
#writer;
|
|
26
|
+
options;
|
|
27
|
+
#closed = false;
|
|
28
|
+
#disconnected = new PromiseResolver();
|
|
29
|
+
get disconnected() {
|
|
30
|
+
return this.#disconnected.promise;
|
|
31
|
+
}
|
|
32
|
+
#incomingSocketHandlers = new Map();
|
|
33
|
+
#readAbortController = new AbortController();
|
|
34
|
+
constructor(connection, options) {
|
|
35
|
+
this.options = options;
|
|
36
|
+
connection.readable
|
|
37
|
+
.pipeTo(new WritableStream({
|
|
38
|
+
write: async (packet) => {
|
|
39
|
+
switch (packet.command) {
|
|
40
|
+
case AdbCommand.OK:
|
|
41
|
+
this.handleOk(packet);
|
|
42
|
+
break;
|
|
43
|
+
case AdbCommand.Close:
|
|
44
|
+
await this.handleClose(packet);
|
|
45
|
+
break;
|
|
46
|
+
case AdbCommand.Write:
|
|
47
|
+
if (this.#sockets.has(packet.arg1)) {
|
|
48
|
+
await this.#sockets
|
|
49
|
+
.get(packet.arg1)
|
|
50
|
+
.enqueue(packet.payload);
|
|
51
|
+
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`Unknown local socket id: ${packet.arg1}`);
|
|
55
|
+
case AdbCommand.Open:
|
|
56
|
+
await this.handleOpen(packet);
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
// Junk data may only appear in the authentication phase,
|
|
60
|
+
// since the dispatcher only works after authentication,
|
|
61
|
+
// all packets should have a valid command.
|
|
62
|
+
// (although it's possible that Adb added new commands in the future)
|
|
63
|
+
throw new Error(`Unknown command: ${packet.command.toString(16)}`);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
}), {
|
|
67
|
+
// There are multiple reasons for the pipe to stop,
|
|
68
|
+
// (device disconnection, protocol error, or user abortion)
|
|
69
|
+
// if the underlying streams are still open,
|
|
70
|
+
// it's still possible to create another ADB connection.
|
|
71
|
+
// So don't close `readable` here.
|
|
72
|
+
preventCancel: true,
|
|
73
|
+
signal: this.#readAbortController.signal,
|
|
74
|
+
})
|
|
75
|
+
.then(() => {
|
|
76
|
+
this.dispose();
|
|
77
|
+
}, (e) => {
|
|
78
|
+
if (!this.#closed) {
|
|
79
|
+
this.#disconnected.reject(e);
|
|
80
|
+
}
|
|
81
|
+
this.dispose();
|
|
82
|
+
});
|
|
83
|
+
this.#writer = connection.writable.getWriter();
|
|
84
|
+
}
|
|
85
|
+
handleOk(packet) {
|
|
86
|
+
if (this.#initializers.resolve(packet.arg1, packet.arg0)) {
|
|
87
|
+
// Device successfully created the socket
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const socket = this.#sockets.get(packet.arg1);
|
|
91
|
+
if (socket) {
|
|
92
|
+
// Device has received last `WRTE` to the socket
|
|
93
|
+
socket.ack();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Maybe the device is responding to a packet of last connection
|
|
97
|
+
// Tell the device to close the socket
|
|
98
|
+
void this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
99
|
+
}
|
|
100
|
+
async handleClose(packet) {
|
|
101
|
+
// If the socket is still pending
|
|
102
|
+
if (packet.arg0 === 0 &&
|
|
103
|
+
this.#initializers.reject(packet.arg1, new Error("Socket open failed"))) {
|
|
104
|
+
// Device failed to create the socket
|
|
105
|
+
// (unknown service string, failed to execute command, etc.)
|
|
106
|
+
// it doesn't break the connection,
|
|
107
|
+
// so only reject the socket creation promise,
|
|
108
|
+
// don't throw an error here.
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// From https://android.googlesource.com/platform/packages/modules/adb/+/65d18e2c1cc48b585811954892311b28a4c3d188/adb.cpp#459
|
|
112
|
+
/* According to protocol.txt, p->msg.arg0 might be 0 to indicate
|
|
113
|
+
* a failed OPEN only. However, due to a bug in previous ADB
|
|
114
|
+
* versions, CLOSE(0, remote-id, "") was also used for normal
|
|
115
|
+
* CLOSE() operations.
|
|
116
|
+
*/
|
|
117
|
+
// Ignore `arg0` and search for the socket
|
|
118
|
+
const socket = this.#sockets.get(packet.arg1);
|
|
119
|
+
if (socket) {
|
|
120
|
+
// The device want to close the socket
|
|
121
|
+
if (!socket.closed) {
|
|
122
|
+
await this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
123
|
+
}
|
|
124
|
+
await socket.dispose();
|
|
125
|
+
this.#sockets.delete(packet.arg1);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// TODO: adb: is double closing an socket a catastrophic error?
|
|
129
|
+
// If the client sends two `CLSE` packets for one socket,
|
|
130
|
+
// the device may also respond with two `CLSE` packets.
|
|
131
|
+
}
|
|
132
|
+
addReverseTunnel(service, handler) {
|
|
133
|
+
this.#incomingSocketHandlers.set(service, handler);
|
|
134
|
+
}
|
|
135
|
+
removeReverseTunnel(address) {
|
|
136
|
+
this.#incomingSocketHandlers.delete(address);
|
|
137
|
+
}
|
|
138
|
+
clearReverseTunnels() {
|
|
139
|
+
this.#incomingSocketHandlers.clear();
|
|
140
|
+
}
|
|
141
|
+
async handleOpen(packet) {
|
|
142
|
+
// `AsyncOperationManager` doesn't support skipping IDs
|
|
143
|
+
// Use `add` + `resolve` to simulate this behavior
|
|
144
|
+
const [localId] = this.#initializers.add();
|
|
145
|
+
this.#initializers.resolve(localId, undefined);
|
|
146
|
+
const remoteId = packet.arg0;
|
|
147
|
+
let service = decodeUtf8(packet.payload);
|
|
148
|
+
if (service.endsWith("\0")) {
|
|
149
|
+
service = service.substring(0, service.length - 1);
|
|
150
|
+
}
|
|
151
|
+
const handler = this.#incomingSocketHandlers.get(service);
|
|
152
|
+
if (!handler) {
|
|
153
|
+
await this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const controller = new AdbDaemonSocketController({
|
|
157
|
+
dispatcher: this,
|
|
158
|
+
localId,
|
|
159
|
+
remoteId,
|
|
160
|
+
localCreated: false,
|
|
161
|
+
service,
|
|
162
|
+
});
|
|
163
|
+
try {
|
|
164
|
+
await handler(controller.socket);
|
|
165
|
+
this.#sockets.set(localId, controller);
|
|
166
|
+
await this.sendPacket(AdbCommand.OK, localId, remoteId);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
await this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async createSocket(service) {
|
|
173
|
+
if (this.options.appendNullToServiceString) {
|
|
174
|
+
service += "\0";
|
|
175
|
+
}
|
|
176
|
+
const [localId, initializer] = this.#initializers.add();
|
|
177
|
+
await this.sendPacket(AdbCommand.Open, localId, 0, service);
|
|
178
|
+
// Fulfilled by `handleOk`
|
|
179
|
+
const remoteId = await initializer;
|
|
180
|
+
const controller = new AdbDaemonSocketController({
|
|
181
|
+
dispatcher: this,
|
|
182
|
+
localId,
|
|
183
|
+
remoteId,
|
|
184
|
+
localCreated: true,
|
|
185
|
+
service,
|
|
186
|
+
});
|
|
187
|
+
this.#sockets.set(localId, controller);
|
|
188
|
+
return controller.socket;
|
|
189
|
+
}
|
|
190
|
+
async sendPacket(command, arg0, arg1, payload = EMPTY_UINT8_ARRAY) {
|
|
191
|
+
if (typeof payload === "string") {
|
|
192
|
+
payload = encodeUtf8(payload);
|
|
193
|
+
}
|
|
194
|
+
if (payload.byteLength > this.options.maxPayloadSize) {
|
|
195
|
+
throw new Error("payload too large");
|
|
196
|
+
}
|
|
197
|
+
await ConsumableWritableStream.write(this.#writer, {
|
|
198
|
+
command,
|
|
199
|
+
arg0,
|
|
200
|
+
arg1,
|
|
201
|
+
payload,
|
|
202
|
+
checksum: this.options.calculateChecksum
|
|
203
|
+
? calculateChecksum(payload)
|
|
204
|
+
: 0,
|
|
205
|
+
magic: command ^ 0xffffffff,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async close() {
|
|
209
|
+
// Send `CLSE` packets for all sockets
|
|
210
|
+
await Promise.all(Array.from(this.#sockets.values(), (socket) => socket.close()));
|
|
211
|
+
// Stop receiving
|
|
212
|
+
// It's possible that we haven't received all `CLSE` confirm packets,
|
|
213
|
+
// but it doesn't matter, the next connection can cope with them.
|
|
214
|
+
this.#closed = true;
|
|
215
|
+
this.#readAbortController.abort();
|
|
216
|
+
this.#writer.releaseLock();
|
|
217
|
+
// `pipe().then()` will call `dispose`
|
|
218
|
+
}
|
|
219
|
+
dispose() {
|
|
220
|
+
for (const socket of this.#sockets.values()) {
|
|
221
|
+
socket.dispose().catch(unreachable);
|
|
222
|
+
}
|
|
223
|
+
this.#disconnected.resolve();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
235
226
|
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/daemon/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAM1E,OAAO,EACH,eAAe,EACf,wBAAwB,EACxB,cAAc,GACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGxE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAcxD;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAmB;IAC5B,8BAA8B;IAC9B,wBAAwB;IACf,aAAa,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACtD;;OAEG;IACM,QAAQ,GAAG,IAAI,GAAG,EAAqC,CAAC;IAEjE,OAAO,CAAyD;IAEhD,OAAO,CAA6B;IAEpD,OAAO,GAAG,KAAK,CAAC;IAChB,aAAa,GAAG,IAAI,eAAe,EAAQ,CAAC;IAC5C,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;IACtC,CAAC;IAED,uBAAuB,GAAG,IAAI,GAAG,EAAoC,CAAC;IACtE,oBAAoB,GAAG,IAAI,eAAe,EAAE,CAAC;IAE7C,YACI,UAGC,EACD,OAAmC;QAEnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,UAAU,CAAC,QAAQ;aACd,MAAM,CACH,IAAI,cAAc,CAAC;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AO,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;SACvC;QAED,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/daemon/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/daemon/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,47 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Struct from "@yume-chan/struct";
|
|
3
|
-
export declare enum AdbCommand {
|
|
4
|
-
Auth = 1213486401,
|
|
5
|
-
Close = 1163086915,
|
|
6
|
-
Connect = 1314410051,
|
|
7
|
-
OK = 1497451343,
|
|
8
|
-
Open = 1313165391,
|
|
9
|
-
Write = 1163154007
|
|
10
|
-
}
|
|
11
|
-
export declare const AdbPacketHeader: Struct<{
|
|
12
|
-
command: number;
|
|
13
|
-
arg0: number;
|
|
14
|
-
arg1: number;
|
|
15
|
-
payloadLength: number;
|
|
16
|
-
checksum: number;
|
|
17
|
-
magic: number;
|
|
18
|
-
}, never, Record<never, never>, undefined>;
|
|
19
|
-
export type AdbPacketHeader = typeof AdbPacketHeader["TDeserializeResult"];
|
|
20
|
-
export declare const AdbPacket: Struct<{
|
|
21
|
-
command: number;
|
|
22
|
-
arg0: number;
|
|
23
|
-
arg1: number;
|
|
24
|
-
payloadLength: number;
|
|
25
|
-
checksum: number;
|
|
26
|
-
magic: number;
|
|
27
|
-
payload: Uint8Array;
|
|
28
|
-
}, "payloadLength", Record<never, never>, undefined>;
|
|
29
|
-
export type AdbPacket = typeof AdbPacket["TDeserializeResult"];
|
|
30
|
-
/**
|
|
31
|
-
* `AdbPacketData` contains all the useful fields of `AdbPacket`.
|
|
32
|
-
*
|
|
33
|
-
* `
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* `
|
|
37
|
-
* however, `
|
|
38
|
-
* so `AdbSocket#writable#write` only needs `AdbPacketData`.
|
|
39
|
-
*/
|
|
40
|
-
export type AdbPacketData = Omit<typeof AdbPacket["TInit"], "checksum" | "magic">;
|
|
41
|
-
export type AdbPacketInit =
|
|
42
|
-
export declare function calculateChecksum(payload: Uint8Array): number;
|
|
43
|
-
export declare
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
1
|
+
import { ConsumableTransformStream } from "@yume-chan/stream-extra";
|
|
2
|
+
import Struct from "@yume-chan/struct";
|
|
3
|
+
export declare enum AdbCommand {
|
|
4
|
+
Auth = 1213486401,
|
|
5
|
+
Close = 1163086915,
|
|
6
|
+
Connect = 1314410051,
|
|
7
|
+
OK = 1497451343,
|
|
8
|
+
Open = 1313165391,
|
|
9
|
+
Write = 1163154007
|
|
10
|
+
}
|
|
11
|
+
export declare const AdbPacketHeader: Struct<{
|
|
12
|
+
command: number;
|
|
13
|
+
arg0: number;
|
|
14
|
+
arg1: number;
|
|
15
|
+
payloadLength: number;
|
|
16
|
+
checksum: number;
|
|
17
|
+
magic: number;
|
|
18
|
+
}, never, Record<never, never>, undefined>;
|
|
19
|
+
export type AdbPacketHeader = (typeof AdbPacketHeader)["TDeserializeResult"];
|
|
20
|
+
export declare const AdbPacket: Struct<{
|
|
21
|
+
command: number;
|
|
22
|
+
arg0: number;
|
|
23
|
+
arg1: number;
|
|
24
|
+
payloadLength: number;
|
|
25
|
+
checksum: number;
|
|
26
|
+
magic: number;
|
|
27
|
+
payload: Uint8Array;
|
|
28
|
+
}, "payloadLength", Record<never, never>, undefined>;
|
|
29
|
+
export type AdbPacket = (typeof AdbPacket)["TDeserializeResult"];
|
|
30
|
+
/**
|
|
31
|
+
* `AdbPacketData` contains all the useful fields of `AdbPacket`.
|
|
32
|
+
*
|
|
33
|
+
* `AdvDaemonConnection#connect` will return a `ReadableStream<AdbPacketData>`,
|
|
34
|
+
* allow each connection to encode `AdbPacket` in different methods.
|
|
35
|
+
*
|
|
36
|
+
* `AdbDaemonConnection#connect` will return a `WritableStream<AdbPacketInit>`,
|
|
37
|
+
* however, `AdbDaemonTransport` will transform `AdbPacketData` to `AdbPacketInit` for you,
|
|
38
|
+
* so `AdbSocket#writable#write` only needs `AdbPacketData`.
|
|
39
|
+
*/
|
|
40
|
+
export type AdbPacketData = Omit<(typeof AdbPacket)["TInit"], "checksum" | "magic">;
|
|
41
|
+
export type AdbPacketInit = (typeof AdbPacket)["TInit"];
|
|
42
|
+
export declare function calculateChecksum(payload: Uint8Array): number;
|
|
43
|
+
export declare class AdbPacketSerializeStream extends ConsumableTransformStream<AdbPacketInit, Uint8Array> {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
47
46
|
//# sourceMappingURL=packet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packet.d.ts","sourceRoot":"","sources":["../../src/daemon/packet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,oBAAY,UAAU;IAClB,IAAI,aAAa;IACjB,KAAK,aAAa;IAClB,OAAO,aAAa;IACpB,EAAE,aAAa;IACf,IAAI,aAAa;IACjB,KAAK,aAAa;CACrB;AAED,eAAO,MAAM,eAAe;;;;;;;0CAMT,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,oBAAoB,CAAC,CAAC;AAI7E,eAAO,MAAM,SAAS;;;;;;;;oDAEsC,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;AAEjE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAC5B,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,EAC3B,UAAU,GAAG,OAAO,CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;AAExD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAE7D;AAED,qBAAa,wBAAyB,SAAQ,yBAAyB,CACnE,aAAa,EACb,UAAU,CACb;;CAoBA"}
|