@yume-chan/adb 0.0.12 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +54 -0
- package/CHANGELOG.md +28 -1
- package/README.md +24 -17
- package/esm/adb.d.ts +10 -9
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +88 -67
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts +6 -6
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js +8 -6
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +2 -2
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +5 -7
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/reverse.d.ts +9 -12
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +44 -36
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +19 -20
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +36 -31
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/legacy.d.ts +14 -7
- package/esm/commands/subprocess/legacy.d.ts.map +1 -1
- package/esm/commands/subprocess/legacy.js +14 -5
- package/esm/commands/subprocess/legacy.js.map +1 -1
- package/esm/commands/subprocess/protocol.d.ts +3 -2
- package/esm/commands/subprocess/protocol.d.ts.map +1 -1
- package/esm/commands/subprocess/protocol.js +6 -4
- package/esm/commands/subprocess/protocol.js.map +1 -1
- package/esm/commands/subprocess/protocols/index.d.ts +4 -0
- package/esm/commands/subprocess/protocols/index.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/index.js +4 -0
- package/esm/commands/subprocess/protocols/index.js.map +1 -0
- package/esm/commands/subprocess/protocols/none.d.ts +35 -0
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/none.js +53 -0
- package/esm/commands/subprocess/protocols/none.js.map +1 -0
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -0
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/shell.js +155 -0
- package/esm/commands/subprocess/protocols/shell.js.map +1 -0
- package/esm/commands/subprocess/protocols/types.d.ts +50 -0
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/types.js +2 -0
- package/esm/commands/subprocess/protocols/types.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +9 -6
- package/esm/commands/subprocess/types.d.ts.map +1 -1
- package/esm/commands/sync/list.d.ts +25 -1
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +40 -5
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +6 -3
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/request.d.ts +1 -0
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +1 -0
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +2 -1
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +2 -1
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +13 -1
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +22 -9
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +13 -35
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +40 -10
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.d.ts +23 -10
- package/esm/crypto.d.ts.map +1 -1
- package/esm/crypto.js +64 -46
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +4 -2
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +6 -2
- package/esm/features.js.map +1 -1
- package/esm/packet.d.ts +21 -2
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +2 -2
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +35 -23
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +97 -72
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/socket.d.ts +29 -8
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +43 -29
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +1 -1
- package/esm/stream/buffered.d.ts.map +1 -1
- package/esm/stream/buffered.js +2 -2
- package/esm/stream/buffered.js.map +1 -1
- package/esm/stream/detect.d.ts +1 -17
- package/esm/stream/detect.d.ts.map +1 -1
- package/esm/stream/detect.js +4 -5
- package/esm/stream/detect.js.map +1 -1
- package/esm/stream/detect.polyfill.d.ts +1 -1
- package/esm/stream/detect.polyfill.d.ts.map +1 -1
- package/esm/stream/detect.polyfill.js +4 -1
- package/esm/stream/detect.polyfill.js.map +1 -1
- package/esm/stream/transform.d.ts +39 -33
- package/esm/stream/transform.d.ts.map +1 -1
- package/esm/stream/transform.js +121 -100
- package/esm/stream/transform.js.map +1 -1
- package/esm/utils/base64.js +5 -5
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts.map +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +1 -1
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/package.json +7 -7
- package/src/adb.ts +112 -86
- package/src/auth.ts +21 -18
- package/src/backend.ts +2 -2
- package/src/commands/install.ts +7 -9
- package/src/commands/reverse.ts +48 -44
- package/src/commands/subprocess/index.ts +57 -42
- package/src/commands/subprocess/protocols/index.ts +3 -0
- package/src/commands/subprocess/{legacy.ts → protocols/none.ts} +20 -10
- package/src/commands/subprocess/{protocol.ts → protocols/shell.ts} +22 -17
- package/src/commands/subprocess/{types.ts → protocols/types.ts} +13 -9
- package/src/commands/sync/list.ts +51 -5
- package/src/commands/sync/pull.ts +6 -3
- package/src/commands/sync/request.ts +1 -0
- package/src/commands/sync/response.ts +8 -2
- package/src/commands/sync/stat.ts +36 -9
- package/src/commands/sync/sync.ts +56 -20
- package/src/crypto.ts +72 -56
- package/src/features.ts +6 -2
- package/src/packet.ts +17 -6
- package/src/socket/dispatcher.ts +139 -91
- package/src/socket/socket.ts +76 -61
- package/src/stream/buffered.ts +2 -2
- package/src/stream/detect.polyfill.ts +5 -2
- package/src/stream/detect.ts +4 -24
- package/src/stream/transform.ts +144 -124
- package/src/utils/index.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/src/utils/encoding.ts +0 -13
package/esm/features.d.ts
CHANGED
package/esm/features.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAEA,oBAAY,WAAW;IACnB,OAAO,aAAa;IACpB,GAAG,QAAQ;IACX,MAAM,YAAY;IAClB,MAAM,UAAU;IAChB,cAAc,qBAAqB;CACtC"}
|
package/esm/features.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
// The order follows
|
|
2
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/79010dc6d5ca7490c493df800d4421730f5466ca/transport.cpp#1252
|
|
1
3
|
export var AdbFeatures;
|
|
2
4
|
(function (AdbFeatures) {
|
|
3
|
-
AdbFeatures["StatV2"] = "stat_v2";
|
|
4
|
-
AdbFeatures["Cmd"] = "cmd";
|
|
5
5
|
AdbFeatures["ShellV2"] = "shell_v2";
|
|
6
|
+
AdbFeatures["Cmd"] = "cmd";
|
|
7
|
+
AdbFeatures["StatV2"] = "stat_v2";
|
|
8
|
+
AdbFeatures["ListV2"] = "ls_v2";
|
|
9
|
+
AdbFeatures["FixedPushMkdir"] = "fixed_push_mkdir";
|
|
6
10
|
})(AdbFeatures = AdbFeatures || (AdbFeatures = {}));
|
|
7
11
|
//# sourceMappingURL=features.js.map
|
package/esm/features.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.js","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,+HAA+H;AAC/H,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACnB,mCAAoB,CAAA;IACpB,0BAAW,CAAA;IACX,iCAAkB,CAAA;IAClB,+BAAgB,CAAA;IAChB,kDAAmC,CAAA;AACvC,CAAC,EANW,WAAW,GAAX,WAAW,KAAX,WAAW,QAMtB"}
|
package/esm/packet.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ export declare enum AdbCommand {
|
|
|
8
8
|
Open = 1313165391,
|
|
9
9
|
Write = 1163154007
|
|
10
10
|
}
|
|
11
|
+
export declare const AdbPacketHeader: Struct<{
|
|
12
|
+
command: number;
|
|
13
|
+
arg0: number;
|
|
14
|
+
arg1: number;
|
|
15
|
+
payloadLength: number;
|
|
16
|
+
checksum: number;
|
|
17
|
+
magic: number;
|
|
18
|
+
}, never, {}, undefined>;
|
|
19
|
+
export declare type AdbPacketHeader = typeof AdbPacketHeader['TDeserializeResult'];
|
|
11
20
|
export declare const AdbPacket: Struct<{
|
|
12
21
|
command: number;
|
|
13
22
|
arg0: number;
|
|
@@ -18,10 +27,20 @@ export declare const AdbPacket: Struct<{
|
|
|
18
27
|
payload: Uint8Array;
|
|
19
28
|
}, "payloadLength", {}, undefined>;
|
|
20
29
|
export declare type AdbPacket = typeof AdbPacket['TDeserializeResult'];
|
|
21
|
-
|
|
30
|
+
/**
|
|
31
|
+
* `AdbPacketData` contains all the useful fields of `AdbPacket`.
|
|
32
|
+
*
|
|
33
|
+
* `AdbBackend#connect` will return a `ReadableStream<AdbPacketData>`,
|
|
34
|
+
* so each backend can encode `AdbPacket` in different ways.
|
|
35
|
+
*
|
|
36
|
+
* `AdbBackend#connect` will return a `WritableStream<AdbPacketInit>`,
|
|
37
|
+
* however, `AdbPacketDispatcher` will transform `AdbPacketData` to `AdbPacketInit` for you,
|
|
38
|
+
* so `AdbSocket#writable#write` only needs `AdbPacketData`.
|
|
39
|
+
*/
|
|
40
|
+
export declare type AdbPacketData = Omit<typeof AdbPacket['TInit'], 'checksum' | 'magic'>;
|
|
22
41
|
export declare type AdbPacketInit = Omit<typeof AdbPacket['TInit'], 'magic'>;
|
|
23
42
|
export declare function calculateChecksum(payload: Uint8Array): number;
|
|
24
|
-
export declare function calculateChecksum(init:
|
|
43
|
+
export declare function calculateChecksum(init: AdbPacketData): AdbPacketInit;
|
|
25
44
|
export declare class AdbPacketSerializeStream extends TransformStream<AdbPacketInit, Uint8Array> {
|
|
26
45
|
constructor();
|
|
27
46
|
}
|
package/esm/packet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packet.d.ts","sourceRoot":"","sources":["../src/packet.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,oBAAY,UAAU;IAClB,IAAI,aAAa;IACjB,KAAK,aAAa;IAClB,OAAO,aAAa;IACpB,EAAE,aAAa;IACf,IAAI,aAAa;IACjB,KAAK,aAAa;CACrB;
|
|
1
|
+
{"version":3,"file":"packet.d.ts","sourceRoot":"","sources":["../src/packet.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,oBAAY,UAAU;IAClB,IAAI,aAAa;IACjB,KAAK,aAAa;IAClB,OAAO,aAAa;IACpB,EAAE,aAAa;IACf,IAAI,aAAa;IACjB,KAAK,aAAa;CACrB;AAED,eAAO,MAAM,eAAe;;;;;;;wBAOL,CAAC;AAExB,oBAAY,eAAe,GAAG,OAAO,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAI3E,eAAO,MAAM,SAAS;;;;;;;;kCAG0C,CAAC;AAEjE,oBAAY,SAAS,GAAG,OAAO,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAE/D;;;;;;;;;GASG;AACH,oBAAY,aAAa,GAAG,IAAI,CAAC,OAAO,SAAS,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC;AAGlF,oBAAY,aAAa,GAAG,IAAI,CAAC,OAAO,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAErE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC;AAC/D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CAAC;AAUtE,qBAAa,wBAAyB,SAAQ,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC;;CAqBvF"}
|
package/esm/packet.js
CHANGED
|
@@ -9,7 +9,7 @@ export var AdbCommand;
|
|
|
9
9
|
AdbCommand[AdbCommand["Open"] = 1313165391] = "Open";
|
|
10
10
|
AdbCommand[AdbCommand["Write"] = 1163154007] = "Write";
|
|
11
11
|
})(AdbCommand = AdbCommand || (AdbCommand = {}));
|
|
12
|
-
const AdbPacketHeader = new Struct({ littleEndian: true })
|
|
12
|
+
export const AdbPacketHeader = new Struct({ littleEndian: true })
|
|
13
13
|
.uint32('command')
|
|
14
14
|
.uint32('arg0')
|
|
15
15
|
.uint32('arg1')
|
|
@@ -32,7 +32,7 @@ export class AdbPacketSerializeStream extends TransformStream {
|
|
|
32
32
|
constructor() {
|
|
33
33
|
super({
|
|
34
34
|
transform: async (init, controller) => {
|
|
35
|
-
// This syntax is ugly, but I don't want to create
|
|
35
|
+
// This syntax is ugly, but I don't want to create a new object.
|
|
36
36
|
init.magic = init.command ^ 0xFFFFFFFF;
|
|
37
37
|
init.payloadLength = init.payload.byteLength;
|
|
38
38
|
controller.enqueue(AdbPacketHeader.serialize(init));
|
package/esm/packet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packet.js","sourceRoot":"","sources":["../src/packet.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IAClB,oDAAiB,CAAA;IACjB,sDAAkB,CAAA;IAClB,0DAAoB,CAAA;IACpB,gDAAe,CAAA;IACf,oDAAiB,CAAA;IACjB,sDAAkB,CAAA;AACtB,CAAC,EAPW,UAAU,GAAV,UAAU,KAAV,UAAU,QAOrB;AAED,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"packet.js","sourceRoot":"","sources":["../src/packet.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IAClB,oDAAiB,CAAA;IACjB,sDAAkB,CAAA;IAClB,0DAAoB,CAAA;IACpB,gDAAe,CAAA;IACf,oDAAiB,CAAA;IACjB,sDAAkB,CAAA;AACtB,CAAC,EAPW,UAAU,GAAV,UAAU,KAAV,UAAU,QAOrB;AAED,MAAM,CAAC,MAAM,eAAe,GACxB,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7B,MAAM,CAAC,SAAS,CAAC;KACjB,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,eAAe,CAAC;KACvB,MAAM,CAAC,UAAU,CAAC;KAClB,KAAK,CAAC,OAAO,CAAC,CAAC;AAMxB,MAAM,CAAC,MAAM,SAAS,GAClB,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7B,MAAM,CAAC,eAAe,CAAC;KACvB,UAAU,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;AAqBjE,MAAM,UAAU,iBAAiB,CAAC,OAAmC;IACjE,IAAI,OAAO,YAAY,UAAU,EAAE;QAC/B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;KAC7D;SAAM;QACF,OAAyB,CAAC,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACzE,OAAO,OAAwB,CAAC;KACnC;AACL,CAAC;AAED,MAAM,OAAO,wBAAyB,SAAQ,eAA0C;IACpF;QACI,KAAK,CAAC;YACF,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;gBAClC,gEAAgE;gBAC/D,IAAuC,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC;gBAC1E,IAAuC,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;gBAEjF,UAAU,CAAC,OAAO,CACd,eAAe,CAAC,SAAS,CACrB,IAAsC,CACzC,CACJ,CAAC;gBAEF,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;oBACzB,8CAA8C;oBAC9C,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBACpC;YACL,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -1,40 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { RemoveEventListener } from '@yume-chan/event';
|
|
2
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
+
import { AdbCommand, type AdbPacketData, type AdbPacketInit } from '../packet.js';
|
|
3
4
|
import { type ReadableWritablePair } from '../stream/index.js';
|
|
4
5
|
import { AdbSocket } from './socket.js';
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export interface AdbPacketDispatcherOptions {
|
|
7
|
+
calculateChecksum: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Before Android 9.0, ADB uses `char*` to parse service string,
|
|
10
|
+
* thus requires a null character to terminate.
|
|
11
|
+
*
|
|
12
|
+
* Usually it should have the same value as `calculateChecksum`.
|
|
13
|
+
*/
|
|
14
|
+
appendNullToServiceString: boolean;
|
|
15
|
+
maxPayloadSize: number;
|
|
16
|
+
}
|
|
17
|
+
export declare type AdbIncomingSocketHandler = (socket: AdbSocket) => ValueOrPromise<boolean>;
|
|
18
|
+
export interface Closeable {
|
|
19
|
+
close(): ValueOrPromise<void>;
|
|
10
20
|
}
|
|
11
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The dispatcher is the "dumb" part of the connection handling logic.
|
|
23
|
+
*
|
|
24
|
+
* Except some options to change some minor behaviors,
|
|
25
|
+
* its only job is forwarding packets between authenticated underlying streams
|
|
26
|
+
* and abstracted socket objects.
|
|
27
|
+
*
|
|
28
|
+
* The `Adb` class is responsible for doing the authentication,
|
|
29
|
+
* negotiating the options, and has shortcuts to high-level services.
|
|
30
|
+
*/
|
|
31
|
+
export declare class AdbPacketDispatcher implements Closeable {
|
|
12
32
|
private readonly initializers;
|
|
13
33
|
private readonly sockets;
|
|
14
34
|
private _writer;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
appendNullToServiceString: boolean;
|
|
35
|
+
readonly options: AdbPacketDispatcherOptions;
|
|
36
|
+
private _closed;
|
|
18
37
|
private _disconnected;
|
|
19
38
|
get disconnected(): Promise<void>;
|
|
20
|
-
private
|
|
21
|
-
get onIncomingSocket(): {
|
|
22
|
-
(listener: import("@yume-chan/event").EventListener<AdbIncomingSocketEventArgs, unknown, [], unknown>): import("@yume-chan/event").RemoveEventListener;
|
|
23
|
-
<TThis, TArgs extends unknown[]>(listener: import("@yume-chan/event").EventListener<AdbIncomingSocketEventArgs, TThis, TArgs, unknown>, thisArg: TThis, ...args: TArgs): import("@yume-chan/event").RemoveEventListener;
|
|
24
|
-
};
|
|
25
|
-
private readonly errorEvent;
|
|
26
|
-
get onError(): {
|
|
27
|
-
(listener: import("@yume-chan/event").EventListener<Error, unknown, [], unknown>): import("@yume-chan/event").RemoveEventListener;
|
|
28
|
-
<TThis, TArgs extends unknown[]>(listener: import("@yume-chan/event").EventListener<Error, TThis, TArgs, unknown>, thisArg: TThis, ...args: TArgs): import("@yume-chan/event").RemoveEventListener;
|
|
29
|
-
};
|
|
39
|
+
private _incomingSocketHandlers;
|
|
30
40
|
private _abortController;
|
|
31
|
-
constructor(connection: ReadableWritablePair<
|
|
41
|
+
constructor(connection: ReadableWritablePair<AdbPacketData, AdbPacketInit>, options: AdbPacketDispatcherOptions);
|
|
32
42
|
private handleOk;
|
|
33
43
|
private handleClose;
|
|
44
|
+
addIncomingSocketHandler(handler: AdbIncomingSocketHandler): RemoveEventListener;
|
|
34
45
|
private handleOpen;
|
|
35
46
|
createSocket(serviceString: string): Promise<AdbSocket>;
|
|
36
47
|
sendPacket(packet: AdbPacketInit): Promise<void>;
|
|
37
48
|
sendPacket(command: AdbCommand, arg0: number, arg1: number, payload?: string | Uint8Array): Promise<void>;
|
|
38
|
-
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
private dispose;
|
|
39
51
|
}
|
|
40
52
|
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBA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AC;IA2B7D,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAChD,UAAU,CACb,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,GAC9B,OAAO,CAAC,IAAI,CAAC;IAsCH,KAAK;IAmBlB,OAAO,CAAC,OAAO;CAOlB"}
|
package/esm/socket/dispatcher.js
CHANGED
|
@@ -1,67 +1,79 @@
|
|
|
1
1
|
import { AsyncOperationManager, PromiseResolver } from '@yume-chan/async';
|
|
2
|
-
import { AutoDisposable, EventEmitter } from '@yume-chan/event';
|
|
3
2
|
import { AdbCommand, calculateChecksum } from '../packet.js';
|
|
4
3
|
import { AbortController, WritableStream } from '../stream/index.js';
|
|
5
4
|
import { decodeUtf8, encodeUtf8 } from '../utils/index.js';
|
|
6
|
-
import {
|
|
5
|
+
import { AdbSocketController } from './socket.js';
|
|
7
6
|
const EmptyUint8Array = new Uint8Array(0);
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The dispatcher is the "dumb" part of the connection handling logic.
|
|
9
|
+
*
|
|
10
|
+
* Except some options to change some minor behaviors,
|
|
11
|
+
* its only job is forwarding packets between authenticated underlying streams
|
|
12
|
+
* and abstracted socket objects.
|
|
13
|
+
*
|
|
14
|
+
* The `Adb` class is responsible for doing the authentication,
|
|
15
|
+
* negotiating the options, and has shortcuts to high-level services.
|
|
16
|
+
*/
|
|
17
|
+
export class AdbPacketDispatcher {
|
|
9
18
|
// ADB socket id starts from 1
|
|
10
19
|
// (0 means open failed)
|
|
11
20
|
initializers = new AsyncOperationManager(1);
|
|
12
21
|
sockets = new Map();
|
|
13
22
|
_writer;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
appendNullToServiceString = true;
|
|
23
|
+
options;
|
|
24
|
+
_closed = false;
|
|
17
25
|
_disconnected = new PromiseResolver();
|
|
18
26
|
get disconnected() { return this._disconnected.promise; }
|
|
19
|
-
|
|
20
|
-
get onIncomingSocket() { return this.incomingSocketEvent.event; }
|
|
21
|
-
errorEvent = this.addDisposable(new EventEmitter());
|
|
22
|
-
get onError() { return this.errorEvent.event; }
|
|
27
|
+
_incomingSocketHandlers = new Set();
|
|
23
28
|
_abortController = new AbortController();
|
|
24
|
-
constructor(connection) {
|
|
25
|
-
|
|
29
|
+
constructor(connection, options) {
|
|
30
|
+
this.options = options;
|
|
26
31
|
connection.readable
|
|
27
32
|
.pipeTo(new WritableStream({
|
|
28
33
|
write: async (packet) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Throw error here will stop the pipe
|
|
53
|
-
// But won't close `readable` because of `preventCancel: true`
|
|
54
|
-
throw e;
|
|
34
|
+
switch (packet.command) {
|
|
35
|
+
case AdbCommand.OK:
|
|
36
|
+
this.handleOk(packet);
|
|
37
|
+
break;
|
|
38
|
+
case AdbCommand.Close:
|
|
39
|
+
await this.handleClose(packet);
|
|
40
|
+
break;
|
|
41
|
+
case AdbCommand.Write:
|
|
42
|
+
if (this.sockets.has(packet.arg1)) {
|
|
43
|
+
await this.sockets.get(packet.arg1).enqueue(packet.payload);
|
|
44
|
+
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Unknown local socket id: ${packet.arg1}`);
|
|
48
|
+
case AdbCommand.Open:
|
|
49
|
+
await this.handleOpen(packet);
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
// Junk data may only appear in the authentication phase,
|
|
53
|
+
// since the dispatcher only works after authentication,
|
|
54
|
+
// all packets should have a valid command.
|
|
55
|
+
// (although it's possible that Adb added new commands in the future)
|
|
56
|
+
throw new Error(`Unknown command: ${packet.command.toString(16)}`);
|
|
55
57
|
}
|
|
56
58
|
},
|
|
57
59
|
}), {
|
|
58
|
-
|
|
60
|
+
// There are multiple reasons for the pipe to stop,
|
|
61
|
+
// (device disconnection, protocol error, or user abortion)
|
|
62
|
+
// if the underlying streams are still open,
|
|
63
|
+
// it's still possible to create another ADB connection.
|
|
64
|
+
// So don't close `readable` here.
|
|
65
|
+
preventCancel: true,
|
|
59
66
|
signal: this._abortController.signal,
|
|
60
67
|
})
|
|
61
68
|
.then(() => {
|
|
62
69
|
this.dispose();
|
|
63
|
-
}, () => {
|
|
64
|
-
//
|
|
70
|
+
}, (e) => {
|
|
71
|
+
// https://github.com/MattiasBuelens/web-streams-polyfill/issues/115
|
|
72
|
+
// `e` is always `AbortError` (instead of what I give in `abortController.abort()`)
|
|
73
|
+
// so we can't check if `e` is a real error.
|
|
74
|
+
if (!this._closed) {
|
|
75
|
+
this._disconnected.reject(e);
|
|
76
|
+
}
|
|
65
77
|
this.dispose();
|
|
66
78
|
});
|
|
67
79
|
this._writer = connection.writable.getWriter();
|
|
@@ -88,12 +100,17 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
|
|
88
100
|
* versions, CLOSE(0, remote-id, "") was also used for normal
|
|
89
101
|
* CLOSE() operations.
|
|
90
102
|
*/
|
|
91
|
-
//
|
|
103
|
+
// If the socket is still pending
|
|
92
104
|
if (packet.arg0 === 0 &&
|
|
93
105
|
this.initializers.reject(packet.arg1, new Error('Socket open failed'))) {
|
|
94
106
|
// Device failed to create the socket
|
|
107
|
+
// (unknown service string, failed to execute command, etc.)
|
|
108
|
+
// it doesn't break the connection,
|
|
109
|
+
// so only reject the socket creation promise,
|
|
110
|
+
// don't throw an error here.
|
|
95
111
|
return;
|
|
96
112
|
}
|
|
113
|
+
// Ignore `arg0` and search for the socket
|
|
97
114
|
const socket = this.sockets.get(packet.arg1);
|
|
98
115
|
if (socket) {
|
|
99
116
|
// The device want to close the socket
|
|
@@ -104,8 +121,17 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
|
|
104
121
|
this.sockets.delete(packet.arg1);
|
|
105
122
|
return;
|
|
106
123
|
}
|
|
107
|
-
//
|
|
108
|
-
//
|
|
124
|
+
// TODO: adb: is double closing an socket a catastrophic error?
|
|
125
|
+
// If the client sends two `CLSE` packets for one socket,
|
|
126
|
+
// the device may also respond with two `CLSE` packets.
|
|
127
|
+
}
|
|
128
|
+
addIncomingSocketHandler(handler) {
|
|
129
|
+
this._incomingSocketHandlers.add(handler);
|
|
130
|
+
const remove = () => {
|
|
131
|
+
this._incomingSocketHandlers.delete(handler);
|
|
132
|
+
};
|
|
133
|
+
remove.dispose = remove;
|
|
134
|
+
return remove;
|
|
109
135
|
}
|
|
110
136
|
async handleOpen(packet) {
|
|
111
137
|
// AsyncOperationManager doesn't support get and skip an ID
|
|
@@ -114,44 +140,39 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
|
|
114
140
|
this.initializers.resolve(localId, undefined);
|
|
115
141
|
const remoteId = packet.arg0;
|
|
116
142
|
const serviceString = decodeUtf8(packet.payload);
|
|
117
|
-
const
|
|
143
|
+
const controller = new AdbSocketController({
|
|
118
144
|
dispatcher: this,
|
|
119
145
|
localId,
|
|
120
146
|
remoteId,
|
|
121
147
|
localCreated: false,
|
|
122
148
|
serviceString,
|
|
123
149
|
});
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.incomingSocketEvent.fire(args);
|
|
131
|
-
if (args.handled) {
|
|
132
|
-
this.sockets.set(localId, socket);
|
|
133
|
-
await this.sendPacket(AdbCommand.OK, localId, remoteId);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
await this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
150
|
+
for (const handler of this._incomingSocketHandlers) {
|
|
151
|
+
if (await handler(controller.socket)) {
|
|
152
|
+
this.sockets.set(localId, controller);
|
|
153
|
+
await this.sendPacket(AdbCommand.OK, localId, remoteId);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
137
156
|
}
|
|
157
|
+
await this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
138
158
|
}
|
|
139
159
|
async createSocket(serviceString) {
|
|
140
|
-
if (this.appendNullToServiceString) {
|
|
160
|
+
if (this.options.appendNullToServiceString) {
|
|
141
161
|
serviceString += '\0';
|
|
142
162
|
}
|
|
143
163
|
const [localId, initializer] = this.initializers.add();
|
|
144
164
|
await this.sendPacket(AdbCommand.Open, localId, 0, serviceString);
|
|
165
|
+
// Fulfilled by `handleOk`
|
|
145
166
|
const remoteId = await initializer;
|
|
146
|
-
const
|
|
167
|
+
const controller = new AdbSocketController({
|
|
147
168
|
dispatcher: this,
|
|
148
169
|
localId,
|
|
149
170
|
remoteId,
|
|
150
171
|
localCreated: true,
|
|
151
172
|
serviceString,
|
|
152
173
|
});
|
|
153
|
-
this.sockets.set(localId,
|
|
154
|
-
return socket;
|
|
174
|
+
this.sockets.set(localId, controller);
|
|
175
|
+
return controller.socket;
|
|
155
176
|
}
|
|
156
177
|
async sendPacket(packetOrCommand, arg0, arg1, payload = EmptyUint8Array) {
|
|
157
178
|
let init;
|
|
@@ -170,30 +191,34 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
|
|
170
191
|
};
|
|
171
192
|
}
|
|
172
193
|
if (init.payload &&
|
|
173
|
-
init.payload.byteLength > this.maxPayloadSize) {
|
|
194
|
+
init.payload.byteLength > this.options.maxPayloadSize) {
|
|
174
195
|
throw new Error('payload too large');
|
|
175
196
|
}
|
|
176
|
-
if (this.calculateChecksum) {
|
|
197
|
+
if (this.options.calculateChecksum) {
|
|
177
198
|
calculateChecksum(init);
|
|
178
199
|
}
|
|
179
200
|
else {
|
|
180
201
|
init.checksum = 0;
|
|
181
202
|
}
|
|
203
|
+
await this._writer.ready;
|
|
182
204
|
await this._writer.write(init);
|
|
183
205
|
}
|
|
206
|
+
async close() {
|
|
207
|
+
// Send `CLSE` packets for all sockets
|
|
208
|
+
await Promise.all(Array.from(this.sockets.values(), socket => socket.close()));
|
|
209
|
+
// Stop receiving
|
|
210
|
+
// It's possible that we haven't received all `CLSE` confirm packets,
|
|
211
|
+
// but it doesn't matter, the next connection can cope with them.
|
|
212
|
+
this._closed = true;
|
|
213
|
+
this._abortController.abort();
|
|
214
|
+
this._writer.releaseLock();
|
|
215
|
+
// `pipe().then()` will call `dispose`
|
|
216
|
+
}
|
|
184
217
|
dispose() {
|
|
185
218
|
for (const socket of this.sockets.values()) {
|
|
186
219
|
socket.dispose();
|
|
187
220
|
}
|
|
188
|
-
this.sockets.clear();
|
|
189
|
-
try {
|
|
190
|
-
// Stop pipes
|
|
191
|
-
this._abortController.abort();
|
|
192
|
-
}
|
|
193
|
-
catch { }
|
|
194
|
-
this._writer.releaseLock();
|
|
195
221
|
this._disconnected.resolve();
|
|
196
|
-
super.dispose();
|
|
197
222
|
}
|
|
198
223
|
}
|
|
199
224
|
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAI1E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAA0C,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,cAAc,EAA0D,MAAM,oBAAoB,CAAC;AAC7H,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MA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CAAC,CAAC;SACxC;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAqB,CAAC,CAAC;IACpD,CAAC;IAEM,KAAK,CAAC,KAAK;QACd,sCAAsC;QACtC,MAAM,OAAO,CAAC,GAAG,CACb,KAAK,CAAC,IAAI,CACN,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EACrB,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAC3B,CACJ,CAAC;QAEF,iBAAiB;QACjB,qEAAqE;QACrE,iEAAiE;QACjE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAE3B,sCAAsC;IAC1C,CAAC;IAEO,OAAO;QACX,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;YACxC,MAAM,CAAC,OAAO,EAAE,CAAC;SACpB;QAED,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACJ"}
|
package/esm/socket/socket.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import type { Disposable } from "@yume-chan/event";
|
|
2
|
+
import { WritableStream, type ReadableStream, type ReadableWritablePair } from '../stream/index.js';
|
|
3
|
+
import type { AdbPacketDispatcher, Closeable } from './dispatcher.js';
|
|
3
4
|
export interface AdbSocketInfo {
|
|
4
5
|
localId: number;
|
|
5
6
|
remoteId: number;
|
|
6
7
|
localCreated: boolean;
|
|
7
8
|
serviceString: string;
|
|
8
9
|
}
|
|
9
|
-
export interface AdbSocketConstructionOptions {
|
|
10
|
+
export interface AdbSocketConstructionOptions extends AdbSocketInfo {
|
|
10
11
|
dispatcher: AdbPacketDispatcher;
|
|
11
|
-
localId: number;
|
|
12
|
-
remoteId: number;
|
|
13
|
-
localCreated: boolean;
|
|
14
|
-
serviceString: string;
|
|
15
12
|
highWaterMark?: number | undefined;
|
|
16
13
|
}
|
|
17
|
-
export declare class
|
|
14
|
+
export declare class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array>, Closeable, Disposable {
|
|
18
15
|
private readonly dispatcher;
|
|
19
16
|
readonly localId: number;
|
|
20
17
|
readonly remoteId: number;
|
|
@@ -28,7 +25,31 @@ export declare class AdbSocket implements AdbSocketInfo {
|
|
|
28
25
|
readonly writable: WritableStream<Uint8Array>;
|
|
29
26
|
private _closed;
|
|
30
27
|
get closed(): boolean;
|
|
28
|
+
private _socket;
|
|
29
|
+
get socket(): AdbSocket;
|
|
31
30
|
constructor(options: AdbSocketConstructionOptions);
|
|
31
|
+
enqueue(packet: Uint8Array): Promise<void>;
|
|
32
|
+
ack(): void;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
dispose(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* AdbSocket is a duplex stream.
|
|
38
|
+
*
|
|
39
|
+
* To close it, call either `socket.close()`,
|
|
40
|
+
* `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
|
|
41
|
+
* `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
|
|
42
|
+
* `socket.writable.close()` or `socket.writable.getWriter().close()`.
|
|
43
|
+
*/
|
|
44
|
+
export declare class AdbSocket implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array> {
|
|
45
|
+
private _controller;
|
|
46
|
+
get localId(): number;
|
|
47
|
+
get remoteId(): number;
|
|
48
|
+
get localCreated(): boolean;
|
|
49
|
+
get serviceString(): string;
|
|
50
|
+
get readable(): ReadableStream<Uint8Array>;
|
|
51
|
+
get writable(): WritableStream<Uint8Array>;
|
|
52
|
+
constructor(controller: AdbSocketController);
|
|
32
53
|
close(): Promise<void>;
|
|
33
54
|
}
|
|
34
55
|
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAkE,cAAc,EAAqC,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACvM,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IAEjB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,4BAA6B,SAAQ,aAAa;IAC/D,UAAU,EAAE,mBAAmB,CAAC;IAEhC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,qBAAa,mBAAoB,YAAW,aAAa,EAAE,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,SAAS,EAAE,UAAU;IAC1H,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAElD,SAAgB,OAAO,EAAG,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAG,MAAM,CAAC;IAClC,SAAgB,YAAY,EAAG,OAAO,CAAC;IACvC,SAAgB,aAAa,EAAG,MAAM,CAAC;IAEvC,OAAO,CAAC,QAAQ,CAA8C;IAE9D,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,mBAAmB,CAA4C;IACvE,IAAW,QAAQ,+BAA6B;IAEhD,OAAO,CAAC,aAAa,CAAoC;IACzD,SAAgB,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;I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