@yume-chan/adb 0.0.8 → 0.0.11
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 +49 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -21
- package/README.md +240 -257
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +141 -145
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +17 -7
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +69 -109
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +21 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +50 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +57 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +83 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +28 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +44 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +38 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +155 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +47 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/types.js +0 -0
- package/{cjs/commands/shell → esm/commands/subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/{dts → esm}/commands/sync/list.d.ts +4 -4
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +16 -19
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +3 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +24 -26
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +3 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +16 -19
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +4 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +22 -27
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +83 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +92 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +24 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +33 -31
- package/esm/crypto.js.map +1 -1
- package/{dts → esm}/features.d.ts +0 -0
- package/{dts → esm}/features.d.ts.map +0 -0
- package/esm/features.js +1 -1
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +28 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +26 -53
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/{dts → esm}/socket/dispatcher.d.ts +10 -23
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +148 -164
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +34 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +69 -14
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +18 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +6 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +6 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +352 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +11 -0
- package/esm/utils/encoding.js.map +1 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -4
- package/esm/utils/index.js.map +1 -1
- package/package.json +49 -50
- package/src/adb.ts +247 -242
- package/src/auth.ts +170 -156
- package/src/backend.ts +11 -24
- package/src/commands/base.ts +11 -11
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -21
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +136 -133
- package/src/commands/subprocess/index.ts +124 -0
- package/src/commands/subprocess/legacy.ts +58 -0
- package/src/commands/subprocess/protocol.ts +185 -0
- package/src/commands/subprocess/types.ts +55 -0
- package/src/commands/{shell → subprocess}/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +40 -39
- package/src/commands/sync/pull.ts +43 -34
- package/src/commands/sync/push.ts +41 -46
- package/src/commands/sync/request.ts +49 -48
- package/src/commands/sync/response.ts +58 -57
- package/src/commands/sync/stat.ts +123 -121
- package/src/commands/sync/sync.ts +145 -113
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +280 -280
- package/src/features.ts +5 -5
- package/src/index.ts +11 -10
- package/src/packet.ts +69 -89
- package/src/socket/dispatcher.ts +256 -269
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +129 -28
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +25 -0
- package/src/stream/detect.ts +25 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +427 -0
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +306 -274
- package/src/utils/encoding.ts +13 -0
- package/src/utils/index.ts +3 -4
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/cjs/adb.js +0 -205
- package/cjs/adb.js.map +0 -1
- package/cjs/auth.js +0 -141
- package/cjs/auth.js.map +0 -1
- package/cjs/backend.js +0 -3
- package/cjs/backend.js.map +0 -1
- package/cjs/commands/base.js +0 -12
- package/cjs/commands/base.js.map +0 -1
- package/cjs/commands/demo-mode.js +0 -174
- package/cjs/commands/demo-mode.js.map +0 -1
- package/cjs/commands/framebuffer.js +0 -66
- package/cjs/commands/framebuffer.js.map +0 -1
- package/cjs/commands/index.js +0 -12
- package/cjs/commands/index.js.map +0 -1
- package/cjs/commands/install.js +0 -20
- package/cjs/commands/install.js.map +0 -1
- package/cjs/commands/reverse.js +0 -105
- package/cjs/commands/reverse.js.map +0 -1
- package/cjs/commands/shell/index.js +0 -56
- package/cjs/commands/shell/index.js.map +0 -1
- package/cjs/commands/shell/legacy.js +0 -37
- package/cjs/commands/shell/legacy.js.map +0 -1
- package/cjs/commands/shell/protocol.js +0 -83
- package/cjs/commands/shell/protocol.js.map +0 -1
- package/cjs/commands/shell/types.js +0 -3
- package/cjs/commands/shell/utils.js +0 -23
- package/cjs/commands/shell/utils.js.map +0 -1
- package/cjs/commands/sync/index.js +0 -11
- package/cjs/commands/sync/index.js.map +0 -1
- package/cjs/commands/sync/list.js +0 -36
- package/cjs/commands/sync/list.js.map +0 -1
- package/cjs/commands/sync/pull.js +0 -34
- package/cjs/commands/sync/pull.js.map +0 -1
- package/cjs/commands/sync/push.js +0 -49
- package/cjs/commands/sync/push.js.map +0 -1
- package/cjs/commands/sync/request.js +0 -48
- package/cjs/commands/sync/request.js.map +0 -1
- package/cjs/commands/sync/response.js +0 -53
- package/cjs/commands/sync/response.js.map +0 -1
- package/cjs/commands/sync/stat.js +0 -109
- package/cjs/commands/sync/stat.js.map +0 -1
- package/cjs/commands/sync/sync.js +0 -118
- package/cjs/commands/sync/sync.js.map +0 -1
- package/cjs/commands/tcpip.js +0 -28
- package/cjs/commands/tcpip.js.map +0 -1
- package/cjs/crypto.js +0 -231
- package/cjs/crypto.js.map +0 -1
- package/cjs/features.js +0 -10
- package/cjs/features.js.map +0 -1
- package/cjs/index.js +0 -14
- package/cjs/index.js.map +0 -1
- package/cjs/packet.js +0 -77
- package/cjs/packet.js.map +0 -1
- package/cjs/socket/close-event-emitter.js +0 -32
- package/cjs/socket/close-event-emitter.js.map +0 -1
- package/cjs/socket/controller.js +0 -84
- package/cjs/socket/controller.js.map +0 -1
- package/cjs/socket/data-event-emitter.js +0 -29
- package/cjs/socket/data-event-emitter.js.map +0 -1
- package/cjs/socket/dispatcher.js +0 -219
- package/cjs/socket/dispatcher.js.map +0 -1
- package/cjs/socket/index.js +0 -10
- package/cjs/socket/index.js.map +0 -1
- package/cjs/socket/logger.js +0 -3
- package/cjs/socket/logger.js.map +0 -1
- package/cjs/socket/socket.js +0 -24
- package/cjs/socket/socket.js.map +0 -1
- package/cjs/stream/buffered-stream.js +0 -78
- package/cjs/stream/buffered-stream.js.map +0 -1
- package/cjs/stream/index.js +0 -6
- package/cjs/stream/index.js.map +0 -1
- package/cjs/stream/stream.js +0 -45
- package/cjs/stream/stream.js.map +0 -1
- package/cjs/utils/auto-reset-event.js +0 -37
- package/cjs/utils/auto-reset-event.js.map +0 -1
- package/cjs/utils/base64.js +0 -210
- package/cjs/utils/base64.js.map +0 -1
- package/cjs/utils/chunk.js +0 -75
- package/cjs/utils/chunk.js.map +0 -1
- package/cjs/utils/event-queue.js +0 -108
- package/cjs/utils/event-queue.js.map +0 -1
- package/cjs/utils/index.js +0 -8
- package/cjs/utils/index.js.map +0 -1
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -15
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -20
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -27
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -37
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -15
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -17
- package/dts/crypto.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -30
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -5
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -52
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -33
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -79
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/types.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -73
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -68
- package/src/commands/shell/legacy.ts +0 -42
- package/src/commands/shell/protocol.ts +0 -94
- package/src/commands/shell/types.ts +0 -21
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -100
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/event-queue.ts +0 -145
- package/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -28
- package/tsconfig.esm.tsbuildinfo +0 -1305
- package/tsconfig.json +0 -18
package/esm/commands/reverse.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// cspell: ignore killforward
|
|
2
2
|
import { AutoDisposable } from '@yume-chan/event';
|
|
3
3
|
import Struct from '@yume-chan/struct';
|
|
4
|
-
import { AdbBufferedStream } from '../stream';
|
|
4
|
+
import { AdbBufferedStream } from '../stream/index.js';
|
|
5
|
+
import { decodeUtf8 } from "../utils/index.js";
|
|
5
6
|
const AdbReverseStringResponse = new Struct({ littleEndian: true })
|
|
6
7
|
.string('length', { length: 4 })
|
|
7
8
|
.string('content', { lengthField: 'length', lengthFieldBase: 16 });
|
|
@@ -11,11 +12,12 @@ const AdbReverseErrorResponse = new Struct({ littleEndian: true })
|
|
|
11
12
|
throw new Error(value.content);
|
|
12
13
|
});
|
|
13
14
|
export class AdbReverseCommand extends AutoDisposable {
|
|
15
|
+
localPortToHandler = new Map();
|
|
16
|
+
deviceAddressToLocalPort = new Map();
|
|
17
|
+
dispatcher;
|
|
18
|
+
listening = false;
|
|
14
19
|
constructor(dispatcher) {
|
|
15
20
|
super();
|
|
16
|
-
this.localPortToHandler = new Map();
|
|
17
|
-
this.deviceAddressToLocalPort = new Map();
|
|
18
|
-
this.listening = false;
|
|
19
21
|
this.dispatcher = dispatcher;
|
|
20
22
|
this.addDisposable(this.dispatcher.onIncomingSocket(this.handleIncomingSocket, this));
|
|
21
23
|
}
|
|
@@ -23,40 +25,34 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
23
25
|
if (e.handled) {
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
|
-
const address =
|
|
27
|
-
// tcp:
|
|
28
|
+
const address = decodeUtf8(e.packet.payload);
|
|
29
|
+
// Address format: `tcp:12345\0`
|
|
28
30
|
const port = Number.parseInt(address.substring(4));
|
|
29
31
|
if (this.localPortToHandler.has(port)) {
|
|
30
32
|
this.localPortToHandler.get(port).onSocket(e.packet, e.socket);
|
|
31
33
|
e.handled = true;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
createBufferedStream(service) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return new AdbBufferedStream(socket);
|
|
38
|
-
});
|
|
36
|
+
async createBufferedStream(service) {
|
|
37
|
+
const socket = await this.dispatcher.createSocket(service);
|
|
38
|
+
return new AdbBufferedStream(socket);
|
|
39
39
|
}
|
|
40
|
-
sendRequest(service) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return stream;
|
|
48
|
-
});
|
|
40
|
+
async sendRequest(service) {
|
|
41
|
+
const stream = await this.createBufferedStream(service);
|
|
42
|
+
const success = decodeUtf8(await stream.read(4)) === 'OKAY';
|
|
43
|
+
if (!success) {
|
|
44
|
+
await AdbReverseErrorResponse.deserialize(stream);
|
|
45
|
+
}
|
|
46
|
+
return stream;
|
|
49
47
|
}
|
|
50
|
-
list() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return { deviceSerial, localName, remoteName };
|
|
57
|
-
});
|
|
58
|
-
// No need to close the stream, device will close it
|
|
48
|
+
async list() {
|
|
49
|
+
const stream = await this.createBufferedStream('reverse:list-forward');
|
|
50
|
+
const response = await AdbReverseStringResponse.deserialize(stream);
|
|
51
|
+
return response.content.split('\n').map(line => {
|
|
52
|
+
const [deviceSerial, localName, remoteName] = line.split(' ');
|
|
53
|
+
return { deviceSerial, localName, remoteName };
|
|
59
54
|
});
|
|
55
|
+
// No need to close the stream, device will close it
|
|
60
56
|
}
|
|
61
57
|
/**
|
|
62
58
|
* @param deviceAddress The address adbd on device is listening on. Can be `tcp:0` to let adbd choose an available TCP port by itself.
|
|
@@ -64,38 +60,32 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
64
60
|
* @param handler A callback to handle incoming connections
|
|
65
61
|
* @returns If `deviceAddress` is `tcp:0`, return `tcp:{ACTUAL_LISTENING_PORT}`; otherwise, return `deviceAddress`.
|
|
66
62
|
*/
|
|
67
|
-
add(deviceAddress, localPort, handler) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// No need to close the stream, device will close it
|
|
80
|
-
});
|
|
63
|
+
async add(deviceAddress, localPort, handler) {
|
|
64
|
+
const stream = await this.sendRequest(`reverse:forward:${deviceAddress};tcp:${localPort}`);
|
|
65
|
+
// `tcp:0` tells the device to pick an available port.
|
|
66
|
+
// However, device will response with the selected port for all `tcp:` requests.
|
|
67
|
+
if (deviceAddress.startsWith('tcp:')) {
|
|
68
|
+
const response = await AdbReverseStringResponse.deserialize(stream);
|
|
69
|
+
deviceAddress = `tcp:${Number.parseInt(response.content, 10)}`;
|
|
70
|
+
}
|
|
71
|
+
this.localPortToHandler.set(localPort, handler);
|
|
72
|
+
this.deviceAddressToLocalPort.set(deviceAddress, localPort);
|
|
73
|
+
return deviceAddress;
|
|
74
|
+
// No need to close the stream, device will close it
|
|
81
75
|
}
|
|
82
|
-
remove(deviceAddress) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// No need to close the stream, device will close it
|
|
90
|
-
});
|
|
76
|
+
async remove(deviceAddress) {
|
|
77
|
+
await this.sendRequest(`reverse:killforward:${deviceAddress}`);
|
|
78
|
+
if (this.deviceAddressToLocalPort.has(deviceAddress)) {
|
|
79
|
+
this.localPortToHandler.delete(this.deviceAddressToLocalPort.get(deviceAddress));
|
|
80
|
+
this.deviceAddressToLocalPort.delete(deviceAddress);
|
|
81
|
+
}
|
|
82
|
+
// No need to close the stream, device will close it
|
|
91
83
|
}
|
|
92
|
-
removeAll() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// No need to close the stream, device will close it
|
|
98
|
-
});
|
|
84
|
+
async removeAll() {
|
|
85
|
+
await this.sendRequest(`reverse:killforward-all`);
|
|
86
|
+
this.deviceAddressToLocalPort.clear();
|
|
87
|
+
this.localPortToHandler.clear();
|
|
88
|
+
// No need to close the stream, device will close it
|
|
99
89
|
}
|
|
100
90
|
}
|
|
101
91
|
//# sourceMappingURL=reverse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse.js","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reverse.js","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAc/C,MAAM,wBAAwB,GAC1B,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7B,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;KAC/B,MAAM,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;AAE3E,MAAM,uBAAuB,GACzB,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7B,MAAM,CAAC,wBAAwB,CAAC;KAChC,eAAe,CAAC,CAAC,KAAK,EAAE,EAAE;IACvB,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEX,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IACvC,kBAAkB,GAAG,IAAI,GA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AAC,CAAC;QAC5D,OAAO,aAAa,CAAC;QAErB,oDAAoD;IACxD,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,aAAqB;QACrC,MAAM,IAAI,CAAC,WAAW,CAAC,uBAAuB,aAAa,EAAE,CAAC,CAAC;QAE/D,IAAI,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YAClD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAE,CAAC,CAAC;YAClF,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;SACvD;QAED,oDAAoD;IACxD,CAAC;IAEM,KAAK,CAAC,SAAS;QAClB,MAAM,IAAI,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;QAElD,IAAI,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAEhC,oDAAoD;IACxD,CAAC;CACJ"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Adb } from '../../adb.js';
|
|
2
|
+
import type { AdbSubprocessProtocol, AdbSubprocessProtocolConstructor } from './types.js';
|
|
3
|
+
export * from './legacy.js';
|
|
4
|
+
export * from './protocol.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export * from './utils.js';
|
|
7
|
+
export interface AdbSubprocessOptions {
|
|
8
|
+
/**
|
|
9
|
+
* A list of `AdbShellConstructor`s to be used.
|
|
10
|
+
*
|
|
11
|
+
* Different `AdbShell` has different capabilities, thus requires specific adaptations.
|
|
12
|
+
* Check each `AdbShell`'s documentation for details.
|
|
13
|
+
*
|
|
14
|
+
* The first one whose `isSupported` returns `true` will be used.
|
|
15
|
+
* If no `AdbShell` is supported, an error will be thrown.
|
|
16
|
+
*
|
|
17
|
+
* The default value is `[AdbShellProtocol, AdbLegacyShell]`.
|
|
18
|
+
*/
|
|
19
|
+
protocols: AdbSubprocessProtocolConstructor[];
|
|
20
|
+
}
|
|
21
|
+
export interface SubprocessResult {
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
exitCode: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class AdbSubprocess {
|
|
27
|
+
readonly adb: Adb;
|
|
28
|
+
constructor(adb: Adb);
|
|
29
|
+
private createProtocol;
|
|
30
|
+
/**
|
|
31
|
+
* Spawns the default shell in interactive mode.
|
|
32
|
+
* @param options The options for creating the `AdbShell`
|
|
33
|
+
* @returns A new `AdbShell` instance connecting to the spawned shell process.
|
|
34
|
+
*/
|
|
35
|
+
shell(options?: Partial<AdbSubprocessOptions>): Promise<AdbSubprocessProtocol>;
|
|
36
|
+
/**
|
|
37
|
+
* Spawns a new process using the given `command`.
|
|
38
|
+
* @param command The command to run, or an array of strings containing both command and args.
|
|
39
|
+
* @param options The options for creating the `AdbShell`
|
|
40
|
+
* @returns A new `AdbShell` instance connecting to the spawned process.
|
|
41
|
+
*/
|
|
42
|
+
spawn(command: string | string[], options?: Partial<AdbSubprocessOptions>): Promise<AdbSubprocessProtocol>;
|
|
43
|
+
/**
|
|
44
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
45
|
+
* @param command The command to run
|
|
46
|
+
* @param options The options for creating the `AdbShell`
|
|
47
|
+
* @returns The entire output of the command
|
|
48
|
+
*/
|
|
49
|
+
spawnAndWait(command: string | string[], options?: Partial<AdbSubprocessOptions>): Promise<SubprocessResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
52
|
+
* @param command The command to run
|
|
53
|
+
* @returns The entire output of the command
|
|
54
|
+
*/
|
|
55
|
+
spawnAndWaitLegacy(command: string | string[]): Promise<string>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/subprocess/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAIxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,gCAAgC,EAAE,MAAM,YAAY,CAAC;AAE1F,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAE3B,MAAM,WAAW,oBAAoB;IACjC;;;;;;;;;;OAUG;IACH,SAAS,EAAE,gCAAgC,EAAE,CAAC;CACjD;AAMD,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,aAAa;IACtB,SAAgB,GAAG,EAAE,GAAG,CAAC;gBAEN,GAAG,EAAE,GAAG;YAIb,cAAc;IAkB5B;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIrF;;;;;OAKG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAOjH;;;;;OAKG;IACU,YAAY,CACrB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACxC,OAAO,CAAC,gBAAgB,CAAC;IAsB5B;;;;OAIG;IACU,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAI/E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DecodeUtf8Stream, GatherStringStream } from "../../stream/index.js";
|
|
2
|
+
import { AdbNoneSubprocessProtocol } from './legacy.js';
|
|
3
|
+
import { AdbShellSubprocessProtocol } from './protocol.js';
|
|
4
|
+
export * from './legacy.js';
|
|
5
|
+
export * from './protocol.js';
|
|
6
|
+
export * from './types.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
|
+
const DefaultOptions = {
|
|
9
|
+
protocols: [AdbShellSubprocessProtocol, AdbNoneSubprocessProtocol],
|
|
10
|
+
};
|
|
11
|
+
export class AdbSubprocess {
|
|
12
|
+
adb;
|
|
13
|
+
constructor(adb) {
|
|
14
|
+
this.adb = adb;
|
|
15
|
+
}
|
|
16
|
+
async createProtocol(command, options) {
|
|
17
|
+
let { protocols } = { ...DefaultOptions, ...options };
|
|
18
|
+
let Constructor;
|
|
19
|
+
for (const item of protocols) {
|
|
20
|
+
if (await item.isSupported(this.adb)) {
|
|
21
|
+
Constructor = item;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!Constructor) {
|
|
26
|
+
throw new Error('No specified protocol is supported by the device');
|
|
27
|
+
}
|
|
28
|
+
return await Constructor.spawn(this.adb, command);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Spawns the default shell in interactive mode.
|
|
32
|
+
* @param options The options for creating the `AdbShell`
|
|
33
|
+
* @returns A new `AdbShell` instance connecting to the spawned shell process.
|
|
34
|
+
*/
|
|
35
|
+
shell(options) {
|
|
36
|
+
return this.createProtocol('', options);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Spawns a new process using the given `command`.
|
|
40
|
+
* @param command The command to run, or an array of strings containing both command and args.
|
|
41
|
+
* @param options The options for creating the `AdbShell`
|
|
42
|
+
* @returns A new `AdbShell` instance connecting to the spawned process.
|
|
43
|
+
*/
|
|
44
|
+
spawn(command, options) {
|
|
45
|
+
if (Array.isArray(command)) {
|
|
46
|
+
command = command.join(' ');
|
|
47
|
+
}
|
|
48
|
+
return this.createProtocol(command, options);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
52
|
+
* @param command The command to run
|
|
53
|
+
* @param options The options for creating the `AdbShell`
|
|
54
|
+
* @returns The entire output of the command
|
|
55
|
+
*/
|
|
56
|
+
async spawnAndWait(command, options) {
|
|
57
|
+
const shell = await this.spawn(command, options);
|
|
58
|
+
const stdout = new GatherStringStream();
|
|
59
|
+
shell.stdout
|
|
60
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
61
|
+
.pipeThrough(stdout);
|
|
62
|
+
const stderr = new GatherStringStream();
|
|
63
|
+
shell.stderr
|
|
64
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
65
|
+
.pipeThrough(stderr);
|
|
66
|
+
const exitCode = await shell.exit;
|
|
67
|
+
return {
|
|
68
|
+
stdout: stdout.result,
|
|
69
|
+
stderr: stderr.result,
|
|
70
|
+
exitCode,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
75
|
+
* @param command The command to run
|
|
76
|
+
* @returns The entire output of the command
|
|
77
|
+
*/
|
|
78
|
+
async spawnAndWaitLegacy(command) {
|
|
79
|
+
const { stdout } = await this.spawnAndWait(command, { protocols: [AdbNoneSubprocessProtocol] });
|
|
80
|
+
return stdout;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/subprocess/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAG3D,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC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CAAC,CAAC;QAEjD,MAAM,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACxC,KAAK,CAAC,MAAM;aACP,WAAW,CAAC,IAAI,gBAAgB,EAAE,CAAC;aACnC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEzB,MAAM,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACxC,KAAK,CAAC,MAAM;aACP,WAAW,CAAC,IAAI,gBAAgB,EAAE,CAAC;aACnC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEzB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;QAElC,OAAO;YACH,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ;SACX,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,kBAAkB,CAAC,OAA0B;QACtD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;QAChG,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Adb } from "../../adb.js";
|
|
2
|
+
import type { AdbSocket } from "../../socket/index.js";
|
|
3
|
+
import { type ReadableStream } from "../../stream/index.js";
|
|
4
|
+
import type { AdbSubprocessProtocol } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* The legacy shell
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* * `stderr`: No
|
|
10
|
+
* * `exit` exit code: No
|
|
11
|
+
* * `resize`: No
|
|
12
|
+
*/
|
|
13
|
+
export declare class AdbNoneSubprocessProtocol implements AdbSubprocessProtocol {
|
|
14
|
+
static isSupported(): boolean;
|
|
15
|
+
static spawn(adb: Adb, command: string): Promise<AdbNoneSubprocessProtocol>;
|
|
16
|
+
private readonly socket;
|
|
17
|
+
get stdin(): import("web-streams-polyfill").WritableStream<Uint8Array>;
|
|
18
|
+
private _stdout;
|
|
19
|
+
get stdout(): ReadableStream<Uint8Array>;
|
|
20
|
+
private _stderr;
|
|
21
|
+
get stderr(): ReadableStream<Uint8Array>;
|
|
22
|
+
private _exit;
|
|
23
|
+
get exit(): Promise<number>;
|
|
24
|
+
constructor(socket: AdbSocket);
|
|
25
|
+
resize(): void;
|
|
26
|
+
kill(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/commands/subprocess/legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,qBAAqB;WACrD,WAAW;WAEL,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAInD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IAGnC,IAAW,KAAK,8DAAmC;IAEnD,OAAO,CAAC,OAAO,CAA6B;IAE5C,IAAW,MAAM,+BAA2B;IAG5C,OAAO,CAAC,OAAO,CAA6B;IAC5C,IAAW,MAAM,+BAA2B;IAE5C,OAAO,CAAC,KAAK,CAAkB;IAC/B,IAAW,IAAI,oBAAyB;gBAErB,MAAM,EAAE,SAAS;IAc7B,MAAM;IAIN,IAAI;CAGd"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DuplexStreamFactory } from "../../stream/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The legacy shell
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* * `stderr`: No
|
|
7
|
+
* * `exit` exit code: No
|
|
8
|
+
* * `resize`: No
|
|
9
|
+
*/
|
|
10
|
+
export class AdbNoneSubprocessProtocol {
|
|
11
|
+
static isSupported() { return true; }
|
|
12
|
+
static async spawn(adb, command) {
|
|
13
|
+
return new AdbNoneSubprocessProtocol(await adb.createSocket(`shell:${command}`));
|
|
14
|
+
}
|
|
15
|
+
socket;
|
|
16
|
+
// Legacy shell forwards all data to stdin.
|
|
17
|
+
get stdin() { return this.socket.writable; }
|
|
18
|
+
_stdout;
|
|
19
|
+
// Legacy shell doesn't support splitting output streams.
|
|
20
|
+
get stdout() { return this._stdout; }
|
|
21
|
+
// `stderr` of Legacy shell is always empty.
|
|
22
|
+
_stderr;
|
|
23
|
+
get stderr() { return this._stderr; }
|
|
24
|
+
_exit;
|
|
25
|
+
get exit() { return this._exit; }
|
|
26
|
+
constructor(socket) {
|
|
27
|
+
this.socket = socket;
|
|
28
|
+
const factory = new DuplexStreamFactory({
|
|
29
|
+
close: async () => {
|
|
30
|
+
await this.socket.close();
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
this._stdout = factory.createWrapReadable(this.socket.readable);
|
|
34
|
+
this._stderr = factory.createReadable();
|
|
35
|
+
this._exit = factory.closed.then(() => 0);
|
|
36
|
+
}
|
|
37
|
+
resize() {
|
|
38
|
+
// Not supported
|
|
39
|
+
}
|
|
40
|
+
kill() {
|
|
41
|
+
return this.socket.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=legacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../src/commands/subprocess/legacy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAuB,MAAM,uBAAuB,CAAC;AAGjF;;;;;;;GAOG;AACH,MAAM,OAAO,yBAAyB;IAC3B,MAAM,CAAC,WAAW,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,CAAC;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Adb } from "../../adb.js";
|
|
2
|
+
import type { AdbSocket } from "../../socket/index.js";
|
|
3
|
+
import { ReadableStream, WritableStream } from "../../stream/index.js";
|
|
4
|
+
import type { AdbSubprocessProtocol } from "./types.js";
|
|
5
|
+
export declare enum AdbShellProtocolId {
|
|
6
|
+
Stdin = 0,
|
|
7
|
+
Stdout = 1,
|
|
8
|
+
Stderr = 2,
|
|
9
|
+
Exit = 3,
|
|
10
|
+
CloseStdin = 4,
|
|
11
|
+
WindowSizeChange = 5
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Shell v2 a.k.a Shell Protocol
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* * `stderr`: Yes
|
|
18
|
+
* * `exit` exit code: Yes
|
|
19
|
+
* * `resize`: Yes
|
|
20
|
+
*/
|
|
21
|
+
export declare class AdbShellSubprocessProtocol implements AdbSubprocessProtocol {
|
|
22
|
+
static isSupported(adb: Adb): boolean;
|
|
23
|
+
static spawn(adb: Adb, command: string): Promise<AdbShellSubprocessProtocol>;
|
|
24
|
+
private readonly _socket;
|
|
25
|
+
private _socketWriter;
|
|
26
|
+
private _stdin;
|
|
27
|
+
get stdin(): WritableStream<Uint8Array>;
|
|
28
|
+
private _stdout;
|
|
29
|
+
get stdout(): ReadableStream<Uint8Array>;
|
|
30
|
+
private _stderr;
|
|
31
|
+
get stderr(): ReadableStream<Uint8Array>;
|
|
32
|
+
private readonly _exit;
|
|
33
|
+
get exit(): Promise<number>;
|
|
34
|
+
constructor(socket: AdbSocket);
|
|
35
|
+
resize(rows: number, cols: number): Promise<void>;
|
|
36
|
+
kill(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/commands/subprocess/protocol.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAsB,cAAc,EAAmE,cAAc,EAAkE,MAAM,uBAAuB,CAAC;AAE5N,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,oBAAY,kBAAkB;IAC1B,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,gBAAgB,IAAA;CACnB;AA6ED;;;;;;;GAOG;AACH,qBAAa,0BAA2B,YAAW,qBAAqB;WACtD,WAAW,CAAC,GAAG,EAAE,GAAG;WAId,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAMnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,OAAO,CAAC,aAAa,CAA0D;IAE/E,OAAO,CAAC,MAAM,CAA6B;IAC3C,IAAW,KAAK,+BAA0B;IAE1C,OAAO,CAAC,OAAO,CAA6B;IAC5C,IAAW,MAAM,+BAA2B;IAE5C,OAAO,CAAC,OAAO,CAA6B;IAC5C,IAAW,MAAM,+BAA2B;IAE5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,IAAW,IAAI,oBAAiC;gBAE7B,MAAM,EAAE,SAAS;IA0CvB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAYvC,IAAI;CAGd"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import Struct, { placeholder } from "@yume-chan/struct";
|
|
3
|
+
import { AdbFeatures } from "../../features.js";
|
|
4
|
+
import { PushReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream } from "../../stream/index.js";
|
|
5
|
+
import { encodeUtf8 } from "../../utils/index.js";
|
|
6
|
+
export var AdbShellProtocolId;
|
|
7
|
+
(function (AdbShellProtocolId) {
|
|
8
|
+
AdbShellProtocolId[AdbShellProtocolId["Stdin"] = 0] = "Stdin";
|
|
9
|
+
AdbShellProtocolId[AdbShellProtocolId["Stdout"] = 1] = "Stdout";
|
|
10
|
+
AdbShellProtocolId[AdbShellProtocolId["Stderr"] = 2] = "Stderr";
|
|
11
|
+
AdbShellProtocolId[AdbShellProtocolId["Exit"] = 3] = "Exit";
|
|
12
|
+
AdbShellProtocolId[AdbShellProtocolId["CloseStdin"] = 4] = "CloseStdin";
|
|
13
|
+
AdbShellProtocolId[AdbShellProtocolId["WindowSizeChange"] = 5] = "WindowSizeChange";
|
|
14
|
+
})(AdbShellProtocolId = AdbShellProtocolId || (AdbShellProtocolId = {}));
|
|
15
|
+
// This packet format is used in both direction.
|
|
16
|
+
const AdbShellProtocolPacket = new Struct({ littleEndian: true })
|
|
17
|
+
.uint8('id', placeholder())
|
|
18
|
+
.uint32('length')
|
|
19
|
+
.uint8Array('data', { lengthField: 'length' });
|
|
20
|
+
class StdinSerializeStream extends TransformStream {
|
|
21
|
+
constructor() {
|
|
22
|
+
super({
|
|
23
|
+
transform(chunk, controller) {
|
|
24
|
+
controller.enqueue({
|
|
25
|
+
id: AdbShellProtocolId.Stdin,
|
|
26
|
+
data: chunk,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
flush() {
|
|
30
|
+
// TODO: AdbShellSubprocessProtocol: support closing stdin
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class StdoutDeserializeStream extends TransformStream {
|
|
36
|
+
constructor(type) {
|
|
37
|
+
super({
|
|
38
|
+
transform(chunk, controller) {
|
|
39
|
+
if (chunk.id === type) {
|
|
40
|
+
controller.enqueue(chunk.data);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class MultiplexStream {
|
|
47
|
+
_readable;
|
|
48
|
+
_readableController;
|
|
49
|
+
get readable() { return this._readable; }
|
|
50
|
+
_activeCount = 0;
|
|
51
|
+
constructor() {
|
|
52
|
+
this._readable = new PushReadableStream(controller => {
|
|
53
|
+
this._readableController = controller;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
createWriteable() {
|
|
57
|
+
return new WritableStream({
|
|
58
|
+
start: () => {
|
|
59
|
+
this._activeCount += 1;
|
|
60
|
+
},
|
|
61
|
+
write: async (chunk) => {
|
|
62
|
+
await this._readableController.enqueue(chunk);
|
|
63
|
+
},
|
|
64
|
+
abort: async (e) => {
|
|
65
|
+
this._activeCount -= 1;
|
|
66
|
+
if (this._activeCount === 0) {
|
|
67
|
+
this._readableController.close();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
close: async () => {
|
|
71
|
+
this._activeCount -= 1;
|
|
72
|
+
if (this._activeCount === 0) {
|
|
73
|
+
this._readableController.close();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Shell v2 a.k.a Shell Protocol
|
|
81
|
+
*
|
|
82
|
+
* Features:
|
|
83
|
+
* * `stderr`: Yes
|
|
84
|
+
* * `exit` exit code: Yes
|
|
85
|
+
* * `resize`: Yes
|
|
86
|
+
*/
|
|
87
|
+
export class AdbShellSubprocessProtocol {
|
|
88
|
+
static isSupported(adb) {
|
|
89
|
+
return adb.features.includes(AdbFeatures.ShellV2);
|
|
90
|
+
}
|
|
91
|
+
static async spawn(adb, command) {
|
|
92
|
+
// TODO: AdbShellSubprocessProtocol: Support raw mode
|
|
93
|
+
// TODO: AdbShellSubprocessProtocol: Support setting `XTERM` environment variable
|
|
94
|
+
return new AdbShellSubprocessProtocol(await adb.createSocket(`shell,v2,pty:${command}`));
|
|
95
|
+
}
|
|
96
|
+
_socket;
|
|
97
|
+
_socketWriter;
|
|
98
|
+
_stdin;
|
|
99
|
+
get stdin() { return this._stdin; }
|
|
100
|
+
_stdout;
|
|
101
|
+
get stdout() { return this._stdout; }
|
|
102
|
+
_stderr;
|
|
103
|
+
get stderr() { return this._stderr; }
|
|
104
|
+
_exit = new PromiseResolver();
|
|
105
|
+
get exit() { return this._exit.promise; }
|
|
106
|
+
constructor(socket) {
|
|
107
|
+
this._socket = socket;
|
|
108
|
+
// Check this image to help you understand the stream graph
|
|
109
|
+
// cspell: disable-next-line
|
|
110
|
+
// https://www.plantuml.com/plantuml/png/bL91QiCm4Bpx5SAdv90lb1JISmiw5XzaQKf5PIkiLZIqzEyLSg8ks13gYtOykpFhiOw93N6UGjVDqK7rZsxKqNw0U_NTgVAy4empOy2mm4_olC0VEVEE47GUpnGjKdgXoD76q4GIEpyFhOwP_m28hW0NNzxNUig1_JdW0bA7muFIJDco1daJ_1SAX9bgvoPJPyIkSekhNYctvIGXrCH6tIsPL5fs-s6J5yc9BpWXhKtNdF2LgVYPGM_6GlMwfhWUsIt4lbScANrwlgVVUifPSVi__t44qStnwPvZwobdSmHHlL57p2vFuHS0
|
|
111
|
+
// TODO: AdbShellSubprocessProtocol: Optimize stream graph
|
|
112
|
+
const [stdout, stderr] = socket.readable
|
|
113
|
+
.pipeThrough(new StructDeserializeStream(AdbShellProtocolPacket))
|
|
114
|
+
.pipeThrough(new TransformStream({
|
|
115
|
+
transform: (chunk, controller) => {
|
|
116
|
+
if (chunk.id === AdbShellProtocolId.Exit) {
|
|
117
|
+
this._exit.resolve(new Uint8Array(chunk.data)[0]);
|
|
118
|
+
// We can let `StdoutTransformStream` to process `AdbShellProtocolId.Exit`,
|
|
119
|
+
// but since we need this `TransformStream` to capture the exit code anyway,
|
|
120
|
+
// terminating child streams here is killing two birds with one stone.
|
|
121
|
+
controller.terminate();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
controller.enqueue(chunk);
|
|
125
|
+
}
|
|
126
|
+
}))
|
|
127
|
+
.tee();
|
|
128
|
+
this._stdout = stdout
|
|
129
|
+
.pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stdout));
|
|
130
|
+
this._stderr = stderr
|
|
131
|
+
.pipeThrough(new StdoutDeserializeStream(AdbShellProtocolId.Stderr));
|
|
132
|
+
const multiplexer = new MultiplexStream();
|
|
133
|
+
multiplexer.readable
|
|
134
|
+
.pipeThrough(new StructSerializeStream(AdbShellProtocolPacket))
|
|
135
|
+
.pipeTo(socket.writable);
|
|
136
|
+
const { readable, writable } = new StdinSerializeStream();
|
|
137
|
+
this._stdin = writable;
|
|
138
|
+
readable.pipeTo(multiplexer.createWriteable());
|
|
139
|
+
this._socketWriter = multiplexer.createWriteable().getWriter();
|
|
140
|
+
}
|
|
141
|
+
async resize(rows, cols) {
|
|
142
|
+
await this._socketWriter.write({
|
|
143
|
+
id: AdbShellProtocolId.WindowSizeChange,
|
|
144
|
+
data: encodeUtf8(
|
|
145
|
+
// The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
|
|
146
|
+
// However, according to https://linux.die.net/man/4/tty_ioctl
|
|
147
|
+
// `x_pixels` and `y_pixels` are not used, so always passing `0` is fine.
|
|
148
|
+
`${rows}x${cols},0x0\0`),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
kill() {
|
|
152
|
+
return this._socket.close();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/commands/subprocess/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,MAAM,EAAE,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAkB,uBAAuB,EAAE,qBAAqB,EAAE,eAAe,EAAE,cAAc,EAAkE,MAA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