@yume-chan/adb 0.0.9 → 0.0.10
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 +23 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -21
- package/README.md +227 -257
- package/dts/adb.d.ts.map +1 -1
- package/dts/auth.d.ts +11 -1
- package/dts/auth.d.ts.map +1 -1
- package/dts/backend.d.ts +3 -5
- package/dts/backend.d.ts.map +1 -1
- package/dts/commands/demo-mode.d.ts +3 -3
- package/dts/commands/demo-mode.d.ts.map +1 -1
- package/dts/commands/reverse.d.ts +2 -2
- package/dts/commands/reverse.d.ts.map +1 -1
- package/dts/commands/shell/index.d.ts +31 -5
- package/dts/commands/shell/index.d.ts.map +1 -1
- package/dts/commands/shell/legacy.d.ts +13 -2
- package/dts/commands/shell/legacy.d.ts.map +1 -1
- package/dts/commands/shell/protocol.d.ts +11 -3
- package/dts/commands/shell/protocol.d.ts.map +1 -1
- package/dts/commands/shell/types.d.ts +35 -3
- package/dts/commands/shell/types.d.ts.map +1 -1
- package/dts/commands/sync/request.d.ts +1 -1
- package/dts/commands/sync/request.d.ts.map +1 -1
- package/dts/commands/sync/response.d.ts +2 -2
- package/dts/commands/sync/response.d.ts.map +1 -1
- package/dts/commands/sync/sync.d.ts.map +1 -1
- package/dts/crypto.d.ts +7 -0
- package/dts/crypto.d.ts.map +1 -1
- package/dts/packet.d.ts.map +1 -1
- package/dts/socket/close-event-emitter.d.ts.map +1 -1
- package/dts/socket/controller.d.ts.map +1 -1
- package/dts/socket/data-event-emitter.d.ts.map +1 -1
- package/dts/socket/dispatcher.d.ts.map +1 -1
- package/dts/stream/buffered-stream.d.ts +2 -4
- package/dts/stream/buffered-stream.d.ts.map +1 -1
- package/dts/utils/encoding.d.ts +3 -0
- package/dts/utils/encoding.d.ts.map +1 -0
- package/dts/utils/index.d.ts +1 -0
- package/dts/utils/index.d.ts.map +1 -1
- package/esm/adb.js +3 -2
- package/esm/adb.js.map +1 -1
- package/esm/auth.js +2 -2
- package/esm/auth.js.map +1 -1
- package/esm/commands/demo-mode.js +9 -9
- package/esm/commands/demo-mode.js.map +1 -1
- package/esm/commands/reverse.js +3 -2
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/shell/index.js +28 -18
- package/esm/commands/shell/index.js.map +1 -1
- package/esm/commands/shell/legacy.js +16 -0
- package/esm/commands/shell/legacy.js.map +1 -1
- package/esm/commands/shell/protocol.js +36 -9
- package/esm/commands/shell/protocol.js.map +1 -1
- package/esm/commands/sync/request.js +5 -4
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.js +4 -3
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.js +7 -2
- package/esm/crypto.js.map +1 -1
- package/esm/packet.js +12 -14
- package/esm/packet.js.map +1 -1
- package/esm/socket/close-event-emitter.js.map +1 -1
- package/esm/socket/controller.js.map +1 -1
- package/esm/socket/data-event-emitter.js.map +1 -1
- package/esm/socket/dispatcher.js +7 -7
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/stream/buffered-stream.js +0 -6
- package/esm/stream/buffered-stream.js.map +1 -1
- package/esm/utils/encoding.js +11 -0
- package/esm/utils/encoding.js.map +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/package.json +44 -51
- package/src/adb.ts +243 -242
- package/src/auth.ts +166 -156
- package/src/backend.ts +20 -24
- package/src/commands/base.ts +11 -11
- package/src/commands/demo-mode.ts +160 -160
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +21 -21
- package/src/commands/reverse.ts +134 -133
- package/src/commands/shell/index.ts +87 -68
- package/src/commands/shell/legacy.ts +59 -42
- package/src/commands/shell/protocol.ts +121 -94
- package/src/commands/shell/types.ts +55 -21
- package/src/commands/shell/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +39 -39
- package/src/commands/sync/pull.ts +34 -34
- package/src/commands/sync/push.ts +46 -46
- package/src/commands/sync/request.ts +49 -48
- package/src/commands/sync/response.ts +58 -57
- package/src/commands/sync/stat.ts +121 -121
- package/src/commands/sync/sync.ts +113 -113
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +285 -280
- package/src/features.ts +5 -5
- package/src/index.ts +10 -10
- package/src/packet.ts +84 -89
- package/src/socket/close-event-emitter.ts +28 -28
- package/src/socket/controller.ts +105 -105
- package/src/socket/data-event-emitter.ts +27 -27
- package/src/socket/dispatcher.ts +269 -269
- package/src/socket/index.ts +6 -6
- package/src/socket/logger.ts +12 -12
- package/src/socket/socket.ts +28 -28
- package/src/stream/buffered-stream.ts +92 -100
- package/src/stream/index.ts +2 -2
- package/src/stream/stream.ts +50 -50
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +274 -274
- package/src/utils/chunk.ts +70 -70
- package/src/utils/encoding.ts +13 -0
- package/src/utils/event-queue.ts +145 -145
- package/src/utils/index.ts +5 -4
- 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/types.js.map +0 -1
- 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/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -28
- package/tsconfig.esm.tsbuildinfo +0 -1305
- package/tsconfig.json +0 -18
|
@@ -1,94 +1,121 @@
|
|
|
1
|
-
import { EventEmitter } from "@yume-chan/event";
|
|
2
|
-
import Struct, { placeholder } from "@yume-chan/struct";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
import { EventEmitter } from "@yume-chan/event";
|
|
2
|
+
import Struct, { placeholder } from "@yume-chan/struct";
|
|
3
|
+
import type { Adb } from "../../adb";
|
|
4
|
+
import { AdbFeatures } from "../../features";
|
|
5
|
+
import type { AdbSocket } from "../../socket";
|
|
6
|
+
import { AdbBufferedStream } from "../../stream";
|
|
7
|
+
import { encodeUtf8 } from "../../utils";
|
|
8
|
+
import type { AdbShell } from "./types";
|
|
9
|
+
|
|
10
|
+
export enum AdbShellProtocolId {
|
|
11
|
+
Stdin,
|
|
12
|
+
Stdout,
|
|
13
|
+
Stderr,
|
|
14
|
+
Exit,
|
|
15
|
+
CloseStdin,
|
|
16
|
+
WindowSizeChange,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// This packet format is used in both direction.
|
|
20
|
+
const AdbShellProtocolPacket = new Struct({ littleEndian: true })
|
|
21
|
+
.uint8('id', placeholder<AdbShellProtocolId>())
|
|
22
|
+
.uint32('length')
|
|
23
|
+
.arrayBuffer('data', { lengthField: 'length' });
|
|
24
|
+
|
|
25
|
+
function assertUnreachable(x: never): never {
|
|
26
|
+
throw new Error("Unreachable");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Shell v2 a.k.a Shell Protocol
|
|
31
|
+
*
|
|
32
|
+
* Features:
|
|
33
|
+
* * `onStderr`: Yes
|
|
34
|
+
* * `onExit` exit code: Yes
|
|
35
|
+
* * `resize`: Yes
|
|
36
|
+
*/
|
|
37
|
+
export class AdbShellProtocol implements AdbShell {
|
|
38
|
+
public static isSupported(adb: Adb) {
|
|
39
|
+
return adb.features!.includes(AdbFeatures.ShellV2);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static async spawn(adb: Adb, command: string) {
|
|
43
|
+
// TODO: the service string may support more parameters
|
|
44
|
+
return new AdbShellProtocol(await adb.createSocket(`shell,v2,pty:${command}`));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private readonly stream: AdbBufferedStream;
|
|
48
|
+
|
|
49
|
+
private readonly stdoutEvent = new EventEmitter<ArrayBuffer>();
|
|
50
|
+
public get onStdout() { return this.stdoutEvent.event; }
|
|
51
|
+
|
|
52
|
+
private readonly stderrEvent = new EventEmitter<ArrayBuffer>();
|
|
53
|
+
public get onStderr() { return this.stderrEvent.event; }
|
|
54
|
+
|
|
55
|
+
private readonly exitEvent = new EventEmitter<number>();
|
|
56
|
+
public get onExit() { return this.exitEvent.event; }
|
|
57
|
+
|
|
58
|
+
public constructor(socket: AdbSocket) {
|
|
59
|
+
this.stream = new AdbBufferedStream(socket);
|
|
60
|
+
this.readData();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async readData() {
|
|
64
|
+
while (true) {
|
|
65
|
+
try {
|
|
66
|
+
const packet = await AdbShellProtocolPacket.deserialize(this.stream);
|
|
67
|
+
switch (packet.id) {
|
|
68
|
+
case AdbShellProtocolId.Stdout:
|
|
69
|
+
this.stdoutEvent.fire(packet.data);
|
|
70
|
+
break;
|
|
71
|
+
case AdbShellProtocolId.Stderr:
|
|
72
|
+
this.stderrEvent.fire(packet.data);
|
|
73
|
+
break;
|
|
74
|
+
case AdbShellProtocolId.Exit:
|
|
75
|
+
this.exitEvent.fire(new Uint8Array(packet.data)[0]);
|
|
76
|
+
break;
|
|
77
|
+
case AdbShellProtocolId.CloseStdin:
|
|
78
|
+
case AdbShellProtocolId.Stdin:
|
|
79
|
+
case AdbShellProtocolId.WindowSizeChange:
|
|
80
|
+
// These ids are client-to-server
|
|
81
|
+
throw new Error('unreachable');
|
|
82
|
+
default:
|
|
83
|
+
assertUnreachable(packet.id);
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public async write(data: ArrayBuffer) {
|
|
92
|
+
this.stream.write(
|
|
93
|
+
AdbShellProtocolPacket.serialize(
|
|
94
|
+
{
|
|
95
|
+
id: AdbShellProtocolId.Stdin,
|
|
96
|
+
data,
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async resize(rows: number, cols: number) {
|
|
103
|
+
await this.stream.write(
|
|
104
|
+
AdbShellProtocolPacket.serialize(
|
|
105
|
+
{
|
|
106
|
+
id: AdbShellProtocolId.WindowSizeChange,
|
|
107
|
+
data: encodeUtf8(
|
|
108
|
+
// The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
|
|
109
|
+
// However, according to https://linux.die.net/man/4/tty_ioctl
|
|
110
|
+
// `x_pixels` and `y_pixels` are not used, so always pass `0` is fine.
|
|
111
|
+
`${rows}x${cols},0x0\0`
|
|
112
|
+
),
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public kill() {
|
|
119
|
+
return this.stream.close();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -1,21 +1,55 @@
|
|
|
1
|
-
import { Event } from "@yume-chan/event";
|
|
2
|
-
import { ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import type { Event } from "@yume-chan/event";
|
|
2
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
+
import type { Adb } from "../../adb";
|
|
4
|
+
import type { AdbSocket } from "../../socket";
|
|
5
|
+
|
|
6
|
+
export interface AdbShell {
|
|
7
|
+
/**
|
|
8
|
+
* Notifies that new data has been written into the `stdout` stream.
|
|
9
|
+
*/
|
|
10
|
+
readonly onStdout: Event<ArrayBuffer>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Notifies that new data has been written into the `stderr` stream.
|
|
14
|
+
*
|
|
15
|
+
* Some `AdbShell`s may not support separate output streams
|
|
16
|
+
* and will always fire the `onStdout` event instead.
|
|
17
|
+
*/
|
|
18
|
+
readonly onStderr: Event<ArrayBuffer>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Notifies that the current process has exited.
|
|
22
|
+
*
|
|
23
|
+
* The event arg is the exit code.
|
|
24
|
+
* Some `AdbShell`s may not support returning exit code and will always return `0` instead.
|
|
25
|
+
*/
|
|
26
|
+
readonly onExit: Event<number>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Writes raw PTY data into the `stdin` stream.
|
|
30
|
+
*/
|
|
31
|
+
write(data: ArrayBuffer): Promise<void>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resizes the current shell.
|
|
35
|
+
*
|
|
36
|
+
* Some `AdbShell`s may not support resizing and will always ignore calls to this method.
|
|
37
|
+
*/
|
|
38
|
+
resize(rows: number, cols: number): ValueOrPromise<void>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Kills the current process.
|
|
42
|
+
*/
|
|
43
|
+
kill(): ValueOrPromise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AdbShellConstructor {
|
|
47
|
+
/** Returns `true` if the `adb` instance supports this shell */
|
|
48
|
+
isSupported(adb: Adb): ValueOrPromise<boolean>;
|
|
49
|
+
|
|
50
|
+
/** Creates a new `AdbShell` using the specified `Adb` and `command` */
|
|
51
|
+
spawn(adb: Adb, command: string): ValueOrPromise<AdbShell>;
|
|
52
|
+
|
|
53
|
+
/** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
|
|
54
|
+
new(socket: AdbSocket): AdbShell;
|
|
55
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export function escapeArg(s: string) {
|
|
2
|
-
let result = '';
|
|
3
|
-
result += `'`;
|
|
4
|
-
|
|
5
|
-
let base = 0;
|
|
6
|
-
while (true) {
|
|
7
|
-
const found = s.indexOf(`'`, base);
|
|
8
|
-
if (found === -1) {
|
|
9
|
-
result += s.substring(base);
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
result += s.substring(base, found);
|
|
13
|
-
// a'b becomes a'\'b
|
|
14
|
-
result += String.raw`'\''`;
|
|
15
|
-
base = found + 1;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
result += `'`;
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
1
|
+
export function escapeArg(s: string) {
|
|
2
|
+
let result = '';
|
|
3
|
+
result += `'`;
|
|
4
|
+
|
|
5
|
+
let base = 0;
|
|
6
|
+
while (true) {
|
|
7
|
+
const found = s.indexOf(`'`, base);
|
|
8
|
+
if (found === -1) {
|
|
9
|
+
result += s.substring(base);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
result += s.substring(base, found);
|
|
13
|
+
// a'b becomes a'\'b
|
|
14
|
+
result += String.raw`'\''`;
|
|
15
|
+
base = found + 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
result += `'`;
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './list';
|
|
2
|
-
export * from './pull';
|
|
3
|
-
export * from './request';
|
|
4
|
-
export * from './response';
|
|
5
|
-
export * from './push';
|
|
6
|
-
export * from './stat';
|
|
7
|
-
export * from './sync';
|
|
1
|
+
export * from './list';
|
|
2
|
+
export * from './pull';
|
|
3
|
+
export * from './request';
|
|
4
|
+
export * from './response';
|
|
5
|
+
export * from './push';
|
|
6
|
+
export * from './stat';
|
|
7
|
+
export * from './sync';
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
5
|
-
import { AdbSyncLstatResponse } from './stat';
|
|
6
|
-
|
|
7
|
-
export const AdbSyncEntryResponse =
|
|
8
|
-
new Struct({ littleEndian: true })
|
|
9
|
-
.fields(AdbSyncLstatResponse)
|
|
10
|
-
.uint32('nameLength')
|
|
11
|
-
.string('name', { lengthField: 'nameLength' })
|
|
12
|
-
.extra({ id: AdbSyncResponseId.Entry as const });
|
|
13
|
-
|
|
14
|
-
export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['TDeserializeResult'];
|
|
15
|
-
|
|
16
|
-
const ResponseTypes = {
|
|
17
|
-
[AdbSyncResponseId.Entry]: AdbSyncEntryResponse,
|
|
18
|
-
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncEntryResponse.size),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export async function* adbSyncOpenDir(
|
|
22
|
-
stream: AdbBufferedStream,
|
|
23
|
-
path: string
|
|
24
|
-
): AsyncGenerator<AdbSyncEntryResponse, void, void> {
|
|
25
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.List, path);
|
|
26
|
-
|
|
27
|
-
while (true) {
|
|
28
|
-
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
|
29
|
-
switch (response.id) {
|
|
30
|
-
case AdbSyncResponseId.Entry:
|
|
31
|
-
yield response;
|
|
32
|
-
break;
|
|
33
|
-
case AdbSyncResponseId.Done:
|
|
34
|
-
return;
|
|
35
|
-
default:
|
|
36
|
-
throw new Error('Unexpected response id');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import Struct from '@yume-chan/struct';
|
|
2
|
+
import { AdbBufferedStream } from '../../stream';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
+
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
5
|
+
import { AdbSyncLstatResponse } from './stat';
|
|
6
|
+
|
|
7
|
+
export const AdbSyncEntryResponse =
|
|
8
|
+
new Struct({ littleEndian: true })
|
|
9
|
+
.fields(AdbSyncLstatResponse)
|
|
10
|
+
.uint32('nameLength')
|
|
11
|
+
.string('name', { lengthField: 'nameLength' })
|
|
12
|
+
.extra({ id: AdbSyncResponseId.Entry as const });
|
|
13
|
+
|
|
14
|
+
export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['TDeserializeResult'];
|
|
15
|
+
|
|
16
|
+
const ResponseTypes = {
|
|
17
|
+
[AdbSyncResponseId.Entry]: AdbSyncEntryResponse,
|
|
18
|
+
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncEntryResponse.size),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function* adbSyncOpenDir(
|
|
22
|
+
stream: AdbBufferedStream,
|
|
23
|
+
path: string
|
|
24
|
+
): AsyncGenerator<AdbSyncEntryResponse, void, void> {
|
|
25
|
+
await adbSyncWriteRequest(stream, AdbSyncRequestId.List, path);
|
|
26
|
+
|
|
27
|
+
while (true) {
|
|
28
|
+
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
|
29
|
+
switch (response.id) {
|
|
30
|
+
case AdbSyncResponseId.Entry:
|
|
31
|
+
yield response;
|
|
32
|
+
break;
|
|
33
|
+
case AdbSyncResponseId.Done:
|
|
34
|
+
return;
|
|
35
|
+
default:
|
|
36
|
+
throw new Error('Unexpected response id');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
-
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
5
|
-
|
|
6
|
-
export const AdbSyncDataResponse =
|
|
7
|
-
new Struct({ littleEndian: true })
|
|
8
|
-
.uint32('dataLength')
|
|
9
|
-
.arrayBuffer('data', { lengthField: 'dataLength' })
|
|
10
|
-
.extra({ id: AdbSyncResponseId.Data as const });
|
|
11
|
-
|
|
12
|
-
const ResponseTypes = {
|
|
13
|
-
[AdbSyncResponseId.Data]: AdbSyncDataResponse,
|
|
14
|
-
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncDataResponse.size),
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export async function* adbSyncPull(
|
|
18
|
-
stream: AdbBufferedStream,
|
|
19
|
-
path: string,
|
|
20
|
-
): AsyncGenerator<ArrayBuffer, void, void> {
|
|
21
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.Receive, path);
|
|
22
|
-
while (true) {
|
|
23
|
-
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
|
24
|
-
switch (response.id) {
|
|
25
|
-
case AdbSyncResponseId.Data:
|
|
26
|
-
yield response.data!;
|
|
27
|
-
break;
|
|
28
|
-
case AdbSyncResponseId.Done:
|
|
29
|
-
return;
|
|
30
|
-
default:
|
|
31
|
-
throw new Error('Unexpected response id');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import Struct from '@yume-chan/struct';
|
|
2
|
+
import { AdbBufferedStream } from '../../stream';
|
|
3
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
4
|
+
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
5
|
+
|
|
6
|
+
export const AdbSyncDataResponse =
|
|
7
|
+
new Struct({ littleEndian: true })
|
|
8
|
+
.uint32('dataLength')
|
|
9
|
+
.arrayBuffer('data', { lengthField: 'dataLength' })
|
|
10
|
+
.extra({ id: AdbSyncResponseId.Data as const });
|
|
11
|
+
|
|
12
|
+
const ResponseTypes = {
|
|
13
|
+
[AdbSyncResponseId.Data]: AdbSyncDataResponse,
|
|
14
|
+
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncDataResponse.size),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function* adbSyncPull(
|
|
18
|
+
stream: AdbBufferedStream,
|
|
19
|
+
path: string,
|
|
20
|
+
): AsyncGenerator<ArrayBuffer, void, void> {
|
|
21
|
+
await adbSyncWriteRequest(stream, AdbSyncRequestId.Receive, path);
|
|
22
|
+
while (true) {
|
|
23
|
+
const response = await adbSyncReadResponse(stream, ResponseTypes);
|
|
24
|
+
switch (response.id) {
|
|
25
|
+
case AdbSyncResponseId.Data:
|
|
26
|
+
yield response.data!;
|
|
27
|
+
break;
|
|
28
|
+
case AdbSyncResponseId.Done:
|
|
29
|
+
return;
|
|
30
|
+
default:
|
|
31
|
+
throw new Error('Unexpected response id');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import Struct from '@yume-chan/struct';
|
|
2
|
-
import { AdbBufferedStream } from '../../stream';
|
|
3
|
-
import { chunkArrayLike, chunkAsyncIterable } from '../../utils';
|
|
4
|
-
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
5
|
-
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
6
|
-
import { LinuxFileType } from './stat';
|
|
7
|
-
|
|
8
|
-
export const AdbSyncOkResponse =
|
|
9
|
-
new Struct({ littleEndian: true })
|
|
10
|
-
.uint32('unused');
|
|
11
|
-
|
|
12
|
-
const ResponseTypes = {
|
|
13
|
-
[AdbSyncResponseId.Ok]: AdbSyncOkResponse,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const AdbSyncMaxPacketSize = 64 * 1024;
|
|
17
|
-
|
|
18
|
-
export async function adbSyncPush(
|
|
19
|
-
stream: AdbBufferedStream,
|
|
20
|
-
filename: string,
|
|
21
|
-
content: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
|
|
22
|
-
mode: number = (LinuxFileType.File << 12) | 0o666,
|
|
23
|
-
mtime: number = (Date.now() / 1000) | 0,
|
|
24
|
-
packetSize: number = AdbSyncMaxPacketSize,
|
|
25
|
-
onProgress?: (uploaded: number) => void,
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
const pathAndMode = `${filename},${mode.toString()}`;
|
|
28
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.Send, pathAndMode);
|
|
29
|
-
|
|
30
|
-
let chunkReader: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>;
|
|
31
|
-
if ('length' in content || 'byteLength' in content) {
|
|
32
|
-
chunkReader = chunkArrayLike(content, packetSize);
|
|
33
|
-
} else {
|
|
34
|
-
chunkReader = chunkAsyncIterable(content, packetSize);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let uploaded = 0;
|
|
38
|
-
for await (const buffer of chunkReader) {
|
|
39
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.Data, buffer);
|
|
40
|
-
uploaded += buffer.byteLength;
|
|
41
|
-
onProgress?.(uploaded);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await adbSyncWriteRequest(stream, AdbSyncRequestId.Done, mtime);
|
|
45
|
-
await adbSyncReadResponse(stream, ResponseTypes);
|
|
46
|
-
}
|
|
1
|
+
import Struct from '@yume-chan/struct';
|
|
2
|
+
import { AdbBufferedStream } from '../../stream';
|
|
3
|
+
import { chunkArrayLike, chunkAsyncIterable } from '../../utils';
|
|
4
|
+
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
|
|
5
|
+
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
|
|
6
|
+
import { LinuxFileType } from './stat';
|
|
7
|
+
|
|
8
|
+
export const AdbSyncOkResponse =
|
|
9
|
+
new Struct({ littleEndian: true })
|
|
10
|
+
.uint32('unused');
|
|
11
|
+
|
|
12
|
+
const ResponseTypes = {
|
|
13
|
+
[AdbSyncResponseId.Ok]: AdbSyncOkResponse,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const AdbSyncMaxPacketSize = 64 * 1024;
|
|
17
|
+
|
|
18
|
+
export async function adbSyncPush(
|
|
19
|
+
stream: AdbBufferedStream,
|
|
20
|
+
filename: string,
|
|
21
|
+
content: ArrayLike<number> | ArrayBufferLike | AsyncIterable<ArrayBuffer>,
|
|
22
|
+
mode: number = (LinuxFileType.File << 12) | 0o666,
|
|
23
|
+
mtime: number = (Date.now() / 1000) | 0,
|
|
24
|
+
packetSize: number = AdbSyncMaxPacketSize,
|
|
25
|
+
onProgress?: (uploaded: number) => void,
|
|
26
|
+
): Promise<void> {
|
|
27
|
+
const pathAndMode = `${filename},${mode.toString()}`;
|
|
28
|
+
await adbSyncWriteRequest(stream, AdbSyncRequestId.Send, pathAndMode);
|
|
29
|
+
|
|
30
|
+
let chunkReader: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>;
|
|
31
|
+
if ('length' in content || 'byteLength' in content) {
|
|
32
|
+
chunkReader = chunkArrayLike(content, packetSize);
|
|
33
|
+
} else {
|
|
34
|
+
chunkReader = chunkAsyncIterable(content, packetSize);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let uploaded = 0;
|
|
38
|
+
for await (const buffer of chunkReader) {
|
|
39
|
+
await adbSyncWriteRequest(stream, AdbSyncRequestId.Data, buffer);
|
|
40
|
+
uploaded += buffer.byteLength;
|
|
41
|
+
onProgress?.(uploaded);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await adbSyncWriteRequest(stream, AdbSyncRequestId.Done, mtime);
|
|
45
|
+
await adbSyncReadResponse(stream, ResponseTypes);
|
|
46
|
+
}
|