@yume-chan/adb 0.0.10 → 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 +26 -0
- package/CHANGELOG.md +15 -1
- package/LICENSE +1 -1
- package/README.md +56 -43
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +141 -146
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +8 -8
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +68 -108
- 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 +49 -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/esm/commands/{shell → 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 -27
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +2 -2
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +16 -20
- 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/{dts → esm}/crypto.d.ts +7 -7
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +26 -29
- 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 -51
- 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/{dts → esm}/utils/encoding.d.ts.map +1 -1
- package/esm/utils/encoding.js +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -5
- package/esm/utils/index.js.map +1 -1
- package/package.json +50 -44
- package/src/adb.ts +147 -143
- package/src/auth.ts +23 -19
- package/src/backend.ts +3 -12
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +26 -15
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +10 -8
- 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 +0 -0
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +7 -6
- package/src/commands/sync/pull.ts +27 -18
- package/src/commands/sync/push.ts +25 -30
- package/src/commands/sync/request.ts +7 -7
- package/src/commands/sync/response.ts +4 -4
- package/src/commands/sync/stat.ts +8 -6
- package/src/commands/sync/sync.ts +64 -32
- package/src/commands/tcpip.ts +3 -3
- package/src/crypto.ts +38 -43
- package/src/index.ts +11 -10
- package/src/packet.ts +37 -52
- package/src/socket/dispatcher.ts +90 -103
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +117 -16
- 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 +1 -1
- package/src/utils/base64.ts +161 -129
- package/src/utils/encoding.ts +3 -3
- package/src/utils/index.ts +3 -5
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- 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 -13
- 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 -46
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -38
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -45
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -47
- 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.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 -28
- 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/encoding.d.ts +0 -3
- 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 -6
- 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 -62
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -49
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -106
- package/esm/commands/shell/protocol.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 -67
- 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 -87
- package/src/commands/shell/legacy.ts +0 -59
- package/src/commands/shell/protocol.ts +0 -121
- package/src/commands/shell/types.ts +0 -55
- 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 -92
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/event-queue.ts +0 -145
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Struct, { StructAsyncDeserializeStream, StructLike, StructValueType } from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { decodeUtf8 } from "../../utils";
|
|
1
|
+
import Struct, { type StructAsyncDeserializeStream, type StructLike, type StructValueType } from '@yume-chan/struct';
|
|
2
|
+
import type { AdbBufferedStream } from '../../stream/index.js';
|
|
3
|
+
import { decodeUtf8 } from "../../utils/index.js";
|
|
4
4
|
|
|
5
5
|
export enum AdbSyncResponseId {
|
|
6
6
|
Entry = 'DENT',
|
|
@@ -51,7 +51,7 @@ export async function adbSyncReadResponse<T extends Record<string, StructLike<an
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (types[id]) {
|
|
54
|
-
return types[id]
|
|
54
|
+
return types[id]!.deserialize(stream);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
throw new Error('Unexpected response id');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Struct, { placeholder } from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
2
|
+
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
|
|
4
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
|
|
5
5
|
|
|
6
6
|
// https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
|
|
7
7
|
export enum LinuxFileType {
|
|
@@ -94,6 +94,7 @@ const Lstat2ResponseType = {
|
|
|
94
94
|
|
|
95
95
|
export async function adbSyncLstat(
|
|
96
96
|
stream: AdbBufferedStream,
|
|
97
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
97
98
|
path: string,
|
|
98
99
|
v2: boolean,
|
|
99
100
|
): Promise<AdbSyncLstatResponse | AdbSyncStatResponse> {
|
|
@@ -108,14 +109,15 @@ export async function adbSyncLstat(
|
|
|
108
109
|
responseType = LstatResponseType;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
await adbSyncWriteRequest(
|
|
112
|
+
await adbSyncWriteRequest(writer, requestId, path);
|
|
112
113
|
return adbSyncReadResponse(stream, responseType);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
export async function adbSyncStat(
|
|
116
117
|
stream: AdbBufferedStream,
|
|
118
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
117
119
|
path: string,
|
|
118
120
|
): Promise<AdbSyncStatResponse> {
|
|
119
|
-
await adbSyncWriteRequest(
|
|
120
|
-
return adbSyncReadResponse(stream, StatResponseType);
|
|
121
|
+
await adbSyncWriteRequest(writer, AdbSyncRequestId.Stat, path);
|
|
122
|
+
return await adbSyncReadResponse(stream, StatResponseType);
|
|
121
123
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
import { Adb } from '../../adb';
|
|
3
|
-
import { AdbFeatures } from '../../features';
|
|
4
|
-
import { AdbSocket } from '../../socket';
|
|
5
|
-
import { AdbBufferedStream } from '../../stream';
|
|
6
|
-
import { AutoResetEvent } from '../../utils';
|
|
7
|
-
import { AdbSyncEntryResponse, adbSyncOpenDir } from './list';
|
|
8
|
-
import { adbSyncPull } from './pull';
|
|
9
|
-
import { adbSyncPush } from './push';
|
|
10
|
-
import { adbSyncLstat, adbSyncStat } from './stat';
|
|
2
|
+
import type { Adb } from '../../adb.js';
|
|
3
|
+
import { AdbFeatures } from '../../features.js';
|
|
4
|
+
import type { AdbSocket } from '../../socket/index.js';
|
|
5
|
+
import { AdbBufferedStream, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
|
|
6
|
+
import { AutoResetEvent } from '../../utils/index.js';
|
|
7
|
+
import { AdbSyncEntryResponse, adbSyncOpenDir } from './list.js';
|
|
8
|
+
import { adbSyncPull } from './pull.js';
|
|
9
|
+
import { adbSyncPush } from './push.js';
|
|
10
|
+
import { adbSyncLstat, adbSyncStat } from './stat.js';
|
|
11
11
|
|
|
12
12
|
export class AdbSync extends AutoDisposable {
|
|
13
13
|
protected adb: Adb;
|
|
14
14
|
|
|
15
15
|
protected stream: AdbBufferedStream;
|
|
16
16
|
|
|
17
|
+
protected writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
18
|
+
|
|
17
19
|
protected sendLock = this.addDisposable(new AutoResetEvent());
|
|
18
20
|
|
|
19
21
|
public get supportsStat(): boolean {
|
|
@@ -25,13 +27,14 @@ export class AdbSync extends AutoDisposable {
|
|
|
25
27
|
|
|
26
28
|
this.adb = adb;
|
|
27
29
|
this.stream = new AdbBufferedStream(socket);
|
|
30
|
+
this.writer = socket.writable.getWriter();
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
public async lstat(path: string) {
|
|
31
34
|
await this.sendLock.wait();
|
|
32
35
|
|
|
33
36
|
try {
|
|
34
|
-
return adbSyncLstat(this.stream, path, this.supportsStat);
|
|
37
|
+
return adbSyncLstat(this.stream, this.writer, path, this.supportsStat);
|
|
35
38
|
} finally {
|
|
36
39
|
this.sendLock.notify();
|
|
37
40
|
}
|
|
@@ -45,7 +48,7 @@ export class AdbSync extends AutoDisposable {
|
|
|
45
48
|
await this.sendLock.wait();
|
|
46
49
|
|
|
47
50
|
try {
|
|
48
|
-
return adbSyncStat(this.stream, path);
|
|
51
|
+
return adbSyncStat(this.stream, this.writer, path);
|
|
49
52
|
} finally {
|
|
50
53
|
this.sendLock.notify();
|
|
51
54
|
}
|
|
@@ -66,7 +69,7 @@ export class AdbSync extends AutoDisposable {
|
|
|
66
69
|
await this.sendLock.wait();
|
|
67
70
|
|
|
68
71
|
try {
|
|
69
|
-
yield* adbSyncOpenDir(this.stream, path);
|
|
72
|
+
yield* adbSyncOpenDir(this.stream, this.writer, path);
|
|
70
73
|
} finally {
|
|
71
74
|
this.sendLock.notify();
|
|
72
75
|
}
|
|
@@ -80,34 +83,63 @@ export class AdbSync extends AutoDisposable {
|
|
|
80
83
|
return results;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Read the content of a file on device.
|
|
88
|
+
*
|
|
89
|
+
* @param filename The full path of the file on device to read.
|
|
90
|
+
* @returns A `ReadableStream` that reads from the file.
|
|
91
|
+
*/
|
|
92
|
+
public read(filename: string): ReadableStream<Uint8Array> {
|
|
93
|
+
return new WrapReadableStream<Uint8Array, ReadableStream<Uint8Array>, undefined>({
|
|
94
|
+
start: async () => {
|
|
95
|
+
await this.sendLock.wait();
|
|
96
|
+
return {
|
|
97
|
+
readable: adbSyncPull(this.stream, this.writer, filename),
|
|
98
|
+
state: undefined,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
close: async () => {
|
|
102
|
+
this.sendLock.notify();
|
|
103
|
+
},
|
|
104
|
+
});
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Write (or overwrite) a file on device.
|
|
109
|
+
*
|
|
110
|
+
* @param filename The full path of the file on device to write.
|
|
111
|
+
* @param mode The unix permissions of the file.
|
|
112
|
+
* @param mtime The modified time of the file.
|
|
113
|
+
* @returns A `WritableStream` that writes to the file.
|
|
114
|
+
*/
|
|
115
|
+
public write(
|
|
94
116
|
filename: string,
|
|
95
|
-
content: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
|
|
96
117
|
mode?: number,
|
|
97
118
|
mtime?: number,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
): WritableStream<Uint8Array> {
|
|
120
|
+
return new WrapWritableStream({
|
|
121
|
+
start: async () => {
|
|
122
|
+
await this.sendLock.wait();
|
|
123
|
+
return {
|
|
124
|
+
writable: adbSyncPush(
|
|
125
|
+
this.stream,
|
|
126
|
+
this.writer,
|
|
127
|
+
filename,
|
|
128
|
+
mode,
|
|
129
|
+
mtime,
|
|
130
|
+
),
|
|
131
|
+
state: undefined,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
close: async () => {
|
|
135
|
+
this.sendLock.notify();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
107
138
|
}
|
|
108
139
|
|
|
109
|
-
public override dispose() {
|
|
140
|
+
public override async dispose() {
|
|
110
141
|
super.dispose();
|
|
111
142
|
this.stream.close();
|
|
143
|
+
await this.writer.close();
|
|
112
144
|
}
|
|
113
145
|
}
|
package/src/commands/tcpip.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdbCommandBase } from './base';
|
|
1
|
+
import { AdbCommandBase } from './base.js';
|
|
2
2
|
|
|
3
3
|
export class AdbTcpIpCommand extends AdbCommandBase {
|
|
4
4
|
public async setPort(port: number): Promise<void> {
|
|
@@ -6,14 +6,14 @@ export class AdbTcpIpCommand extends AdbCommandBase {
|
|
|
6
6
|
throw new Error(`Invalid port ${port}`);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const output = await this.adb.
|
|
9
|
+
const output = await this.adb.createSocketAndWait(`tcpip:${port}`);
|
|
10
10
|
if (output !== `restarting in TCP mode port: ${port}\n`) {
|
|
11
11
|
throw new Error('Invalid response');
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
public async disable(): Promise<void> {
|
|
16
|
-
const output = await this.adb.
|
|
16
|
+
const output = await this.adb.createSocketAndWait('usb:');
|
|
17
17
|
if (output !== 'restarting in USB mode\n') {
|
|
18
18
|
throw new Error('Invalid response');
|
|
19
19
|
}
|
package/src/crypto.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
+
import { getBigUint64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback.js';
|
|
2
|
+
|
|
1
3
|
const BigInt0 = BigInt(0);
|
|
2
4
|
const BigInt1 = BigInt(1);
|
|
3
5
|
const BigInt2 = BigInt(2);
|
|
4
|
-
|
|
5
|
-
const BigInt2To64 = BigInt2 ** BigInt(64);
|
|
6
|
+
const BigInt64 = BigInt(64);
|
|
6
7
|
|
|
7
8
|
export function getBig(
|
|
8
|
-
|
|
9
|
+
array: Uint8Array,
|
|
9
10
|
offset = 0,
|
|
10
|
-
length =
|
|
11
|
+
length = array.byteLength - offset
|
|
11
12
|
): bigint {
|
|
12
|
-
const view = new DataView(buffer);
|
|
13
|
+
const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
13
14
|
|
|
14
15
|
let result = BigInt0;
|
|
15
16
|
|
|
16
|
-
//
|
|
17
|
+
// Currently `length` must be a multiplication of 8
|
|
17
18
|
// Support for arbitrary length can be easily added
|
|
18
19
|
|
|
19
20
|
for (let i = offset; i < offset + length; i += 8) {
|
|
20
|
-
result
|
|
21
|
-
const value =
|
|
21
|
+
result <<= BigInt64;
|
|
22
|
+
const value = getBigUint64(view, i, false);
|
|
22
23
|
result += value;
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -29,22 +30,22 @@ export function setBig(buffer: ArrayBuffer, value: bigint, offset: number = 0) {
|
|
|
29
30
|
const uint64Array: bigint[] = [];
|
|
30
31
|
while (value > BigInt0) {
|
|
31
32
|
uint64Array.push(BigInt.asUintN(64, value));
|
|
32
|
-
value
|
|
33
|
+
value >>= BigInt64;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
const view = new DataView(buffer);
|
|
36
37
|
for (let i = uint64Array.length - 1; i >= 0; i -= 1) {
|
|
37
|
-
|
|
38
|
+
setBigUint64(view, offset, uint64Array[i]!, false);
|
|
38
39
|
offset += 8;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function setBigLE(
|
|
43
|
-
const view = new DataView(buffer);
|
|
43
|
+
export function setBigLE(array: Uint8Array, value: bigint, offset = 0) {
|
|
44
|
+
const view = new DataView(array.buffer, array.byteOffset, array.byteLength);
|
|
44
45
|
while (value > BigInt0) {
|
|
45
|
-
|
|
46
|
+
setBigUint64(view, offset, value, true);
|
|
46
47
|
offset += 8;
|
|
47
|
-
value
|
|
48
|
+
value >>= BigInt64;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -74,7 +75,7 @@ const RsaPrivateKeyNLength = 2048 / 8;
|
|
|
74
75
|
const RsaPrivateKeyDOffset = 303;
|
|
75
76
|
const RsaPrivateKeyDLength = 2048 / 8;
|
|
76
77
|
|
|
77
|
-
export function parsePrivateKey(key:
|
|
78
|
+
export function parsePrivateKey(key: Uint8Array): [n: bigint, d: bigint] {
|
|
78
79
|
let n = getBig(key, RsaPrivateKeyNOffset, RsaPrivateKeyNLength);
|
|
79
80
|
let d = getBig(key, RsaPrivateKeyDOffset, RsaPrivateKeyDLength);
|
|
80
81
|
|
|
@@ -85,11 +86,6 @@ export function parsePrivateKey(key: ArrayBuffer): [n: bigint, d: bigint] {
|
|
|
85
86
|
// I can't understand, but it does work
|
|
86
87
|
// Only used with numbers less than 2^32 so doesn't need BigInt
|
|
87
88
|
export function modInverse(a: number, m: number) {
|
|
88
|
-
// validate inputs
|
|
89
|
-
[a, m] = [Number(a), Number(m)];
|
|
90
|
-
if (Number.isNaN(a) || Number.isNaN(m)) {
|
|
91
|
-
return NaN; // invalid input
|
|
92
|
-
}
|
|
93
89
|
a = (a % m + m) % m;
|
|
94
90
|
if (!a || m < 2) {
|
|
95
91
|
return NaN; // invalid input
|
|
@@ -108,7 +104,7 @@ export function modInverse(a: number, m: number) {
|
|
|
108
104
|
let x = 1;
|
|
109
105
|
let y = 0;
|
|
110
106
|
for (let i = s.length - 2; i >= 0; --i) {
|
|
111
|
-
[x, y] = [y, x - y * Math.floor(s[i]
|
|
107
|
+
[x, y] = [y, x - y * Math.floor(s[i]!.a / s[i]!.b)];
|
|
112
108
|
}
|
|
113
109
|
return (y % m + m) % m;
|
|
114
110
|
}
|
|
@@ -118,18 +114,16 @@ export function calculatePublicKeyLength() {
|
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
export function calculatePublicKey(
|
|
121
|
-
privateKey:
|
|
122
|
-
):
|
|
117
|
+
privateKey: Uint8Array
|
|
118
|
+
): Uint8Array;
|
|
123
119
|
export function calculatePublicKey(
|
|
124
|
-
privateKey:
|
|
125
|
-
output:
|
|
126
|
-
outputOffset?: number
|
|
120
|
+
privateKey: Uint8Array,
|
|
121
|
+
output: Uint8Array,
|
|
127
122
|
): number;
|
|
128
123
|
export function calculatePublicKey(
|
|
129
|
-
privateKey:
|
|
130
|
-
output?:
|
|
131
|
-
|
|
132
|
-
): ArrayBuffer | number {
|
|
124
|
+
privateKey: Uint8Array,
|
|
125
|
+
output?: Uint8Array,
|
|
126
|
+
): Uint8Array | number {
|
|
133
127
|
// Android has its own public key generation algorithm
|
|
134
128
|
// See https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#111
|
|
135
129
|
|
|
@@ -150,20 +144,21 @@ export function calculatePublicKey(
|
|
|
150
144
|
// extract `n` from private key
|
|
151
145
|
const [n] = parsePrivateKey(privateKey);
|
|
152
146
|
|
|
153
|
-
let outputType: '
|
|
147
|
+
let outputType: 'Uint8Array' | 'number';
|
|
154
148
|
const outputLength = calculatePublicKeyLength();
|
|
155
149
|
if (!output) {
|
|
156
|
-
output = new
|
|
157
|
-
outputType = '
|
|
150
|
+
output = new Uint8Array(outputLength);
|
|
151
|
+
outputType = 'Uint8Array';
|
|
158
152
|
} else {
|
|
159
|
-
if (output.byteLength
|
|
153
|
+
if (output.byteLength < outputLength) {
|
|
160
154
|
throw new Error('output buffer is too small');
|
|
161
155
|
}
|
|
162
156
|
|
|
163
157
|
outputType = 'number';
|
|
164
158
|
}
|
|
165
159
|
|
|
166
|
-
const outputView = new DataView(output);
|
|
160
|
+
const outputView = new DataView(output.buffer, output.byteOffset, output.byteLength);
|
|
161
|
+
let outputOffset = 0;
|
|
167
162
|
|
|
168
163
|
// modulusLengthInWords
|
|
169
164
|
outputView.setUint32(outputOffset, 2048 / 8 / 4, true);
|
|
@@ -189,7 +184,7 @@ export function calculatePublicKey(
|
|
|
189
184
|
outputView.setUint32(outputOffset, 65537, true);
|
|
190
185
|
outputOffset += 4;
|
|
191
186
|
|
|
192
|
-
if (outputType === '
|
|
187
|
+
if (outputType === 'Uint8Array') {
|
|
193
188
|
return output;
|
|
194
189
|
} else {
|
|
195
190
|
return outputLength;
|
|
@@ -231,14 +226,14 @@ export const Asn1Null = 0x05;
|
|
|
231
226
|
export const Asn1Oid = 0x06;
|
|
232
227
|
|
|
233
228
|
// PKCS#1 SHA-1 hash digest info
|
|
234
|
-
export const Sha1DigestInfo = [
|
|
229
|
+
export const Sha1DigestInfo = new Uint8Array([
|
|
235
230
|
Asn1Sequence, 0x0d + Sha1DigestLength,
|
|
236
231
|
Asn1Sequence, 0x09,
|
|
237
232
|
// SHA-1 (1 3 14 3 2 26)
|
|
238
233
|
Asn1Oid, 0x05, 1 * 40 + 3, 14, 3, 2, 26,
|
|
239
234
|
Asn1Null, 0x00,
|
|
240
235
|
Asn1OctetString, Sha1DigestLength
|
|
241
|
-
];
|
|
236
|
+
]);
|
|
242
237
|
|
|
243
238
|
// SubtleCrypto.sign() will hash the given data and sign the hash
|
|
244
239
|
// But we don't need the hashing step
|
|
@@ -246,7 +241,7 @@ export const Sha1DigestInfo = [
|
|
|
246
241
|
// encrypt the given data with its private key)
|
|
247
242
|
// However SubtileCrypto.encrypt() doesn't accept 'RSASSA-PKCS1-v1_5' algorithm
|
|
248
243
|
// So we need to implement the encryption by ourself
|
|
249
|
-
export function sign(privateKey:
|
|
244
|
+
export function sign(privateKey: Uint8Array, data: Uint8Array): ArrayBuffer {
|
|
250
245
|
const [n, d] = parsePrivateKey(privateKey);
|
|
251
246
|
|
|
252
247
|
// PKCS#1 padding
|
|
@@ -259,7 +254,7 @@ export function sign(privateKey: ArrayBuffer, data: ArrayBuffer): ArrayBuffer {
|
|
|
259
254
|
padded[index] = 1;
|
|
260
255
|
index += 1;
|
|
261
256
|
|
|
262
|
-
const fillLength = padded.length - Sha1DigestInfo.length - data.
|
|
257
|
+
const fillLength = padded.length - Sha1DigestInfo.length - data.length - 1;
|
|
263
258
|
while (index < fillLength) {
|
|
264
259
|
padded[index] = 0xff;
|
|
265
260
|
index += 1;
|
|
@@ -268,14 +263,14 @@ export function sign(privateKey: ArrayBuffer, data: ArrayBuffer): ArrayBuffer {
|
|
|
268
263
|
padded[index] = 0;
|
|
269
264
|
index += 1;
|
|
270
265
|
|
|
271
|
-
padded.set(
|
|
266
|
+
padded.set(Sha1DigestInfo, index);
|
|
272
267
|
index += Sha1DigestInfo.length;
|
|
273
268
|
|
|
274
|
-
padded.set(
|
|
269
|
+
padded.set(data, index);
|
|
275
270
|
|
|
276
271
|
// Encryption
|
|
277
272
|
// signature = padded ** d % n
|
|
278
|
-
let signature = powMod(getBig(padded
|
|
273
|
+
let signature = powMod(getBig(padded), d, n);
|
|
279
274
|
|
|
280
275
|
// Put into an ArrayBuffer
|
|
281
276
|
const result = new ArrayBuffer(256);
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
1
|
+
|
|
2
|
+
export * from './adb.js';
|
|
3
|
+
export * from './auth.js';
|
|
4
|
+
export * from './backend.js';
|
|
5
|
+
export * from './commands/index.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
export * from './features.js';
|
|
8
|
+
export * from './packet.js';
|
|
9
|
+
export * from './socket/index.js';
|
|
10
|
+
export * from './stream/index.js';
|
|
11
|
+
export * from './utils/index.js';
|
package/src/packet.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Struct from '@yume-chan/struct';
|
|
2
|
-
import {
|
|
3
|
-
import { BufferedStream } from './stream';
|
|
2
|
+
import { TransformStream } from "./stream/index.js";
|
|
4
3
|
|
|
5
4
|
export enum AdbCommand {
|
|
6
5
|
Auth = 0x48545541, // 'AUTH'
|
|
@@ -20,65 +19,51 @@ const AdbPacketHeader =
|
|
|
20
19
|
.uint32('checksum')
|
|
21
20
|
.int32('magic');
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
type AdbPacketHeaderInit = typeof AdbPacketHeader['TInit'];
|
|
23
|
+
|
|
24
|
+
export const AdbPacket =
|
|
24
25
|
new Struct({ littleEndian: true })
|
|
25
26
|
.fields(AdbPacketHeader)
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
export type AdbPacket = typeof AdbPacketStruct['TDeserializeResult'];
|
|
27
|
+
.uint8Array('payload', { lengthField: 'payloadLength' });
|
|
29
28
|
|
|
30
|
-
export type
|
|
29
|
+
export type AdbPacket = typeof AdbPacket['TDeserializeResult'];
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// Detect boundary
|
|
35
|
-
// Note that it relies on the backend to only return data from one write operation
|
|
36
|
-
let buffer: ArrayBuffer;
|
|
37
|
-
do {
|
|
38
|
-
// Maybe it's a payload from last connection.
|
|
39
|
-
// Ignore and try again
|
|
40
|
-
buffer = await backend.read(24);
|
|
41
|
-
} while (buffer.byteLength !== 24);
|
|
31
|
+
// All the useful fields
|
|
32
|
+
export type AdbPacketCore = Omit<typeof AdbPacket['TInit'], 'checksum' | 'magic'>;
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
async read(length: number) {
|
|
46
|
-
if (!bufferUsed) {
|
|
47
|
-
bufferUsed = true;
|
|
48
|
-
return buffer;
|
|
49
|
-
}
|
|
50
|
-
return backend.read(length);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
34
|
+
// All fields except `magic`, which can be calculated in `AdbPacketSerializeStream`
|
|
35
|
+
export type AdbPacketInit = Omit<typeof AdbPacket['TInit'], 'magic'>;
|
|
53
36
|
|
|
54
|
-
|
|
37
|
+
export function calculateChecksum(payload: Uint8Array): number;
|
|
38
|
+
export function calculateChecksum(init: AdbPacketCore): AdbPacketInit;
|
|
39
|
+
export function calculateChecksum(payload: Uint8Array | AdbPacketCore): number | AdbPacketInit {
|
|
40
|
+
if (payload instanceof Uint8Array) {
|
|
41
|
+
return payload.reduce((result, item) => result + item, 0);
|
|
42
|
+
} else {
|
|
43
|
+
(payload as AdbPacketInit).checksum = calculateChecksum(payload.payload);
|
|
44
|
+
return payload as AdbPacketInit;
|
|
55
45
|
}
|
|
46
|
+
}
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const array = new Uint8Array(init.payload);
|
|
65
|
-
checksum = array.reduce((result, item) => result + item, 0);
|
|
66
|
-
} else {
|
|
67
|
-
checksum = 0;
|
|
68
|
-
}
|
|
48
|
+
export class AdbPacketSerializeStream extends TransformStream<AdbPacketInit, Uint8Array>{
|
|
49
|
+
public constructor() {
|
|
50
|
+
super({
|
|
51
|
+
transform: async (init, controller) => {
|
|
52
|
+
// This syntax is ugly, but I don't want to create an new object.
|
|
53
|
+
(init as unknown as AdbPacketHeaderInit).magic = init.command ^ 0xFFFFFFFF;
|
|
54
|
+
(init as unknown as AdbPacketHeaderInit).payloadLength = init.payload.byteLength;
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
56
|
+
controller.enqueue(
|
|
57
|
+
AdbPacketHeader.serialize(
|
|
58
|
+
init as unknown as AdbPacketHeaderInit
|
|
59
|
+
)
|
|
60
|
+
);
|
|
76
61
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
62
|
+
if (init.payload.byteLength) {
|
|
63
|
+
// Enqueue payload separately to avoid copying
|
|
64
|
+
controller.enqueue(init.payload);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
83
68
|
}
|
|
84
69
|
}
|