@yume-chan/adb 0.0.24 → 1.0.0
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.md +36 -1
- package/README.md +4 -1
- package/esm/adb.d.ts +13 -7
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +3 -0
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +7 -6
- package/esm/banner.d.ts.map +1 -1
- package/esm/banner.js +6 -7
- package/esm/banner.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +63 -34
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +35 -33
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/reverse.d.ts +12 -12
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +39 -30
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +3 -5
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +20 -12
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +16 -21
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +6 -6
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/list.d.ts +49 -27
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +9 -9
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +7 -6
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +3 -5
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +22 -16
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +12 -16
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +19 -17
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +14 -18
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +18 -18
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +20 -19
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +1 -1
- package/esm/commands/sync/socket.js +2 -2
- package/esm/commands/sync/socket.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +75 -51
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +73 -67
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +14 -14
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +4 -7
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +0 -1
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +8 -8
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/daemon/auth.d.ts +8 -7
- package/esm/daemon/auth.d.ts.map +1 -1
- package/esm/daemon/auth.js +7 -8
- package/esm/daemon/auth.js.map +1 -1
- package/esm/daemon/crypto.d.ts +1 -1
- package/esm/daemon/crypto.d.ts.map +1 -1
- package/esm/daemon/crypto.js +1 -0
- package/esm/daemon/crypto.js.map +1 -1
- package/esm/daemon/device.d.ts +2 -2
- package/esm/daemon/device.d.ts.map +1 -1
- package/esm/daemon/dispatcher.js +6 -6
- package/esm/daemon/dispatcher.js.map +1 -1
- package/esm/daemon/packet.d.ts +46 -30
- package/esm/daemon/packet.d.ts.map +1 -1
- package/esm/daemon/packet.js +24 -21
- package/esm/daemon/packet.js.map +1 -1
- package/esm/daemon/socket.d.ts +1 -6
- package/esm/daemon/socket.d.ts.map +1 -1
- package/esm/daemon/socket.js +4 -27
- package/esm/daemon/socket.js.map +1 -1
- package/esm/daemon/transport.d.ts +14 -14
- package/esm/daemon/transport.d.ts.map +1 -1
- package/esm/daemon/transport.js +6 -8
- package/esm/daemon/transport.js.map +1 -1
- package/esm/device-observer.d.ts +10 -0
- package/esm/device-observer.d.ts.map +1 -0
- package/esm/device-observer.js +2 -0
- package/esm/device-observer.js.map +1 -0
- package/esm/features.d.ts +12 -11
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +11 -12
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +34 -22
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +151 -136
- package/esm/server/client.js.map +1 -1
- package/esm/server/transport.d.ts +2 -2
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +1 -3
- package/esm/server/transport.js.map +1 -1
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +19 -16
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/no-op.d.ts.map +1 -1
- package/esm/utils/no-op.js +1 -0
- package/esm/utils/no-op.js.map +1 -1
- package/package.json +14 -17
- package/src/adb.ts +13 -7
- package/src/banner.ts +8 -6
- package/src/commands/framebuffer.ts +44 -35
- package/src/commands/reverse.ts +49 -31
- package/src/commands/subprocess/protocols/none.ts +3 -5
- package/src/commands/subprocess/protocols/shell.ts +26 -24
- package/src/commands/subprocess/protocols/types.ts +6 -6
- package/src/commands/sync/list.ts +20 -13
- package/src/commands/sync/pull.ts +8 -7
- package/src/commands/sync/push.ts +20 -16
- package/src/commands/sync/request.ts +18 -19
- package/src/commands/sync/response.ts +28 -29
- package/src/commands/sync/socket.ts +2 -2
- package/src/commands/sync/stat.ts +93 -71
- package/src/commands/sync/sync.ts +4 -8
- package/src/commands/tcpip.ts +8 -8
- package/src/daemon/auth.ts +11 -9
- package/src/daemon/crypto.ts +2 -0
- package/src/daemon/device.ts +2 -2
- package/src/daemon/dispatcher.ts +6 -6
- package/src/daemon/packet.ts +37 -25
- package/src/daemon/socket.ts +4 -27
- package/src/daemon/transport.ts +36 -35
- package/src/device-observer.ts +10 -0
- package/src/features.ts +13 -11
- package/src/index.ts +1 -0
- package/src/server/client.ts +185 -160
- package/src/server/transport.ts +3 -5
- package/src/utils/base64.ts +26 -18
- package/src/utils/no-op.ts +1 -0
- package/tsconfig.build.json +1 -12
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -298
package/esm/utils/base64.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const [charToIndex, indexToChar, paddingChar] = /* #__PURE__ */ (() => {
|
|
2
|
+
// Array is faster than object literal or `Map`
|
|
3
|
+
const charToIndex = [];
|
|
4
|
+
const indexToChar = [];
|
|
5
|
+
const paddingChar = "=".charCodeAt(0);
|
|
6
|
+
function addRange(start, end) {
|
|
7
|
+
const charCodeStart = start.charCodeAt(0);
|
|
8
|
+
const charCodeEnd = end.charCodeAt(0);
|
|
9
|
+
for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) {
|
|
10
|
+
charToIndex[charCode] = indexToChar.length;
|
|
11
|
+
indexToChar.push(charCode);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
addRange("
|
|
14
|
-
addRange("
|
|
15
|
-
addRange("
|
|
16
|
-
addRange("
|
|
17
|
-
|
|
14
|
+
addRange("A", "Z");
|
|
15
|
+
addRange("a", "z");
|
|
16
|
+
addRange("0", "9");
|
|
17
|
+
addRange("+", "+");
|
|
18
|
+
addRange("/", "/");
|
|
19
|
+
return [charToIndex, indexToChar, paddingChar];
|
|
20
|
+
})();
|
|
18
21
|
/**
|
|
19
22
|
* Calculate the required length of the output buffer for the given input length.
|
|
20
23
|
*
|
package/esm/utils/base64.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA,+CAA+C;
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/utils/base64.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC,GAAG,EAAE;IAClE,+CAA+C;IAC/C,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtC,SAAS,QAAQ,CAAC,KAAa,EAAE,GAAW;QACxC,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEtC,KACI,IAAI,QAAQ,GAAG,aAAa,EAC5B,QAAQ,IAAI,WAAW,EACvB,QAAQ,IAAI,CAAC,EACf,CAAC;YACC,WAAW,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;YAC3C,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEnB,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACnD,CAAC,CAAC,EAAE,CAAC;AAEL;;;;;GAKG;AACH,MAAM,UAAU,4B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"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-op.d.ts","sourceRoot":"","sources":["../../src/utils/no-op.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,IAAI,YAEhB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAGrD"}
|
package/esm/utils/no-op.js
CHANGED
package/esm/utils/no-op.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-op.js","sourceRoot":"","sources":["../../src/utils/no-op.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE;IACrB,QAAQ;AACZ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,IAAe;IAC1C,+CAA+C;IAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
|
1
|
+
{"version":3,"file":"no-op.js","sourceRoot":"","sources":["../../src/utils/no-op.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE;IACrB,QAAQ;AACZ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,IAAe;IAC1C,+CAA+C;IAC/C,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/adb",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "TypeScript implementation of Android Debug Bridge (ADB) protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -24,28 +24,25 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "esm/index.js",
|
|
26
26
|
"types": "esm/index.d.ts",
|
|
27
|
+
"sideEffects": false,
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@yume-chan/async": "^
|
|
29
|
-
"@yume-chan/event": "^0.0
|
|
30
|
-
"@yume-chan/
|
|
31
|
-
"@yume-chan/
|
|
32
|
-
"@yume-chan/
|
|
29
|
+
"@yume-chan/async": "^4.0.2",
|
|
30
|
+
"@yume-chan/event": "^1.0.0",
|
|
31
|
+
"@yume-chan/stream-extra": "^1.0.0",
|
|
32
|
+
"@yume-chan/struct": "^1.0.0",
|
|
33
|
+
"@yume-chan/no-data-view": "^1.0.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
36
|
+
"@types/node": "^22.10.0",
|
|
37
|
+
"prettier": "^3.4.1",
|
|
38
|
+
"typescript": "^5.7.2",
|
|
37
39
|
"@yume-chan/eslint-config": "^1.0.0",
|
|
38
|
-
"@yume-chan/
|
|
39
|
-
"
|
|
40
|
-
"jest": "^30.0.0-alpha.4",
|
|
41
|
-
"prettier": "^3.3.2",
|
|
42
|
-
"ts-jest": "^29.1.4",
|
|
43
|
-
"typescript": "^5.4.5"
|
|
40
|
+
"@yume-chan/test-runner": "^1.0.0",
|
|
41
|
+
"@yume-chan/tsconfig": "^1.0.0"
|
|
44
42
|
},
|
|
45
43
|
"scripts": {
|
|
46
44
|
"build": "tsc -b tsconfig.build.json",
|
|
47
|
-
"
|
|
48
|
-
"test": "
|
|
49
|
-
"lint": "run-eslint && prettier src/**/*.ts --write --tab-width 4"
|
|
45
|
+
"lint": "run-eslint && prettier src/**/*.ts --write --tab-width 4",
|
|
46
|
+
"test": "run-test"
|
|
50
47
|
}
|
|
51
48
|
}
|
package/src/adb.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
1
2
|
import type {
|
|
2
3
|
MaybeConsumable,
|
|
3
4
|
ReadableWritablePair,
|
|
4
5
|
} from "@yume-chan/stream-extra";
|
|
5
6
|
import { ConcatStringStream, TextDecoderStream } from "@yume-chan/stream-extra";
|
|
6
|
-
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
7
7
|
|
|
8
8
|
import type { AdbBanner } from "./banner.js";
|
|
9
9
|
import type { AdbFrameBuffer } from "./commands/index.js";
|
|
@@ -19,9 +19,12 @@ import {
|
|
|
19
19
|
import type { AdbFeature } from "./features.js";
|
|
20
20
|
|
|
21
21
|
export interface Closeable {
|
|
22
|
-
close():
|
|
22
|
+
close(): MaybePromiseLike<void>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Represents an ADB socket.
|
|
27
|
+
*/
|
|
25
28
|
export interface AdbSocket
|
|
26
29
|
extends ReadableWritablePair<Uint8Array, MaybeConsumable<Uint8Array>>,
|
|
27
30
|
Closeable {
|
|
@@ -32,7 +35,7 @@ export interface AdbSocket
|
|
|
32
35
|
|
|
33
36
|
export type AdbIncomingSocketHandler = (
|
|
34
37
|
socket: AdbSocket,
|
|
35
|
-
) =>
|
|
38
|
+
) => MaybePromiseLike<void>;
|
|
36
39
|
|
|
37
40
|
export interface AdbTransport extends Closeable {
|
|
38
41
|
readonly serial: string;
|
|
@@ -45,16 +48,16 @@ export interface AdbTransport extends Closeable {
|
|
|
45
48
|
|
|
46
49
|
readonly clientFeatures: readonly AdbFeature[];
|
|
47
50
|
|
|
48
|
-
connect(service: string):
|
|
51
|
+
connect(service: string): MaybePromiseLike<AdbSocket>;
|
|
49
52
|
|
|
50
53
|
addReverseTunnel(
|
|
51
54
|
handler: AdbIncomingSocketHandler,
|
|
52
55
|
address?: string,
|
|
53
|
-
):
|
|
56
|
+
): MaybePromiseLike<string>;
|
|
54
57
|
|
|
55
|
-
removeReverseTunnel(address: string):
|
|
58
|
+
removeReverseTunnel(address: string): MaybePromiseLike<void>;
|
|
56
59
|
|
|
57
|
-
clearReverseTunnels():
|
|
60
|
+
clearReverseTunnels(): MaybePromiseLike<void>;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export class Adb implements Closeable {
|
|
@@ -105,6 +108,9 @@ export class Adb implements Closeable {
|
|
|
105
108
|
);
|
|
106
109
|
}
|
|
107
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new ADB Socket to the specified service or socket address.
|
|
113
|
+
*/
|
|
108
114
|
async createSocket(service: string): Promise<AdbSocket> {
|
|
109
115
|
return this.transport.connect(service);
|
|
110
116
|
}
|
package/src/banner.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { AdbFeature } from "./features.js";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
Product
|
|
5
|
-
Model
|
|
6
|
-
Device
|
|
7
|
-
Features
|
|
8
|
-
}
|
|
3
|
+
export const AdbBannerKey = {
|
|
4
|
+
Product: "ro.product.name",
|
|
5
|
+
Model: "ro.product.model",
|
|
6
|
+
Device: "ro.product.device",
|
|
7
|
+
Features: "features",
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export type AdbBannerKey = (typeof AdbBannerKey)[keyof typeof AdbBannerKey];
|
|
9
11
|
|
|
10
12
|
export class AdbBanner {
|
|
11
13
|
static parse(banner: string) {
|
|
@@ -1,44 +1,53 @@
|
|
|
1
1
|
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import
|
|
2
|
+
import type { StructValue } from "@yume-chan/struct";
|
|
3
|
+
import { buffer, struct, StructEmptyError, u32 } from "@yume-chan/struct";
|
|
3
4
|
|
|
4
5
|
import type { Adb } from "../adb.js";
|
|
5
6
|
|
|
6
|
-
const Version =
|
|
7
|
+
const Version = struct({ version: u32 }, { littleEndian: true });
|
|
7
8
|
|
|
8
|
-
export const AdbFrameBufferV1 =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
export const AdbFrameBufferV1 = struct(
|
|
10
|
+
{
|
|
11
|
+
bpp: u32,
|
|
12
|
+
size: u32,
|
|
13
|
+
width: u32,
|
|
14
|
+
height: u32,
|
|
15
|
+
red_offset: u32,
|
|
16
|
+
red_length: u32,
|
|
17
|
+
blue_offset: u32,
|
|
18
|
+
blue_length: u32,
|
|
19
|
+
green_offset: u32,
|
|
20
|
+
green_length: u32,
|
|
21
|
+
alpha_offset: u32,
|
|
22
|
+
alpha_length: u32,
|
|
23
|
+
data: buffer("size"),
|
|
24
|
+
},
|
|
25
|
+
{ littleEndian: true },
|
|
26
|
+
);
|
|
22
27
|
|
|
23
|
-
export type AdbFrameBufferV1 =
|
|
28
|
+
export type AdbFrameBufferV1 = StructValue<typeof AdbFrameBufferV1>;
|
|
24
29
|
|
|
25
|
-
export const AdbFrameBufferV2 =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
export const AdbFrameBufferV2 = struct(
|
|
31
|
+
{
|
|
32
|
+
bpp: u32,
|
|
33
|
+
colorSpace: u32,
|
|
34
|
+
size: u32,
|
|
35
|
+
width: u32,
|
|
36
|
+
height: u32,
|
|
37
|
+
red_offset: u32,
|
|
38
|
+
red_length: u32,
|
|
39
|
+
blue_offset: u32,
|
|
40
|
+
blue_length: u32,
|
|
41
|
+
green_offset: u32,
|
|
42
|
+
green_length: u32,
|
|
43
|
+
alpha_offset: u32,
|
|
44
|
+
alpha_length: u32,
|
|
45
|
+
data: buffer("size"),
|
|
46
|
+
},
|
|
47
|
+
{ littleEndian: true },
|
|
48
|
+
);
|
|
40
49
|
|
|
41
|
-
export type AdbFrameBufferV2 =
|
|
50
|
+
export type AdbFrameBufferV2 = StructValue<typeof AdbFrameBufferV2>;
|
|
42
51
|
|
|
43
52
|
/**
|
|
44
53
|
* ADB uses 8 int32 fields to describe bit depths
|
|
@@ -93,9 +102,9 @@ export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
|
|
|
93
102
|
switch (version) {
|
|
94
103
|
case 1:
|
|
95
104
|
// TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
|
|
96
|
-
return AdbFrameBufferV1.deserialize(stream);
|
|
105
|
+
return await AdbFrameBufferV1.deserialize(stream);
|
|
97
106
|
case 2:
|
|
98
|
-
return AdbFrameBufferV2.deserialize(stream);
|
|
107
|
+
return await AdbFrameBufferV2.deserialize(stream);
|
|
99
108
|
default:
|
|
100
109
|
throw new AdbFrameBufferUnsupportedVersionError(version);
|
|
101
110
|
}
|
package/src/commands/reverse.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// cspell: ignore killforward
|
|
2
2
|
|
|
3
|
-
import { AutoDisposable } from "@yume-chan/event";
|
|
4
3
|
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
5
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
encodeUtf8,
|
|
6
|
+
ExactReadableEndedError,
|
|
7
|
+
string,
|
|
8
|
+
struct,
|
|
9
|
+
} from "@yume-chan/struct";
|
|
6
10
|
|
|
7
11
|
import type { Adb, AdbIncomingSocketHandler } from "../adb.js";
|
|
8
12
|
import { hexToNumber, sequenceEqual } from "../utils/index.js";
|
|
@@ -15,14 +19,25 @@ export interface AdbForwardListener {
|
|
|
15
19
|
remoteName: string;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
const AdbReverseStringResponse =
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const AdbReverseStringResponse = struct(
|
|
23
|
+
{
|
|
24
|
+
length: string(4),
|
|
25
|
+
content: string({
|
|
26
|
+
field: "length",
|
|
27
|
+
convert(value: string) {
|
|
28
|
+
return Number.parseInt(value, 16);
|
|
29
|
+
},
|
|
30
|
+
back(value) {
|
|
31
|
+
return value.toString(16).padStart(4, "0");
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
{ littleEndian: true },
|
|
36
|
+
);
|
|
21
37
|
|
|
22
38
|
export class AdbReverseError extends Error {
|
|
23
39
|
constructor(message: string) {
|
|
24
40
|
super(message);
|
|
25
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
26
41
|
}
|
|
27
42
|
}
|
|
28
43
|
|
|
@@ -34,18 +49,22 @@ export class AdbReverseNotSupportedError extends AdbReverseError {
|
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
51
|
|
|
37
|
-
const AdbReverseErrorResponse =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
const AdbReverseErrorResponse = struct(
|
|
53
|
+
/* #__PURE__ */ (() => AdbReverseStringResponse.fields)(),
|
|
54
|
+
{
|
|
55
|
+
littleEndian: true,
|
|
56
|
+
postDeserialize: (value) => {
|
|
57
|
+
// https://issuetracker.google.com/issues/37066218
|
|
58
|
+
// ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi),
|
|
59
|
+
// and returns this confusing "more than one device/emulator" error.
|
|
60
|
+
if (value.content === "more than one device/emulator") {
|
|
61
|
+
throw new AdbReverseNotSupportedError();
|
|
62
|
+
} else {
|
|
63
|
+
throw new AdbReverseError(value.content);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
);
|
|
49
68
|
|
|
50
69
|
// Like `hexToNumber`, it's much faster than first converting `buffer` to a string
|
|
51
70
|
function decimalToNumber(buffer: Uint8Array) {
|
|
@@ -62,14 +81,12 @@ function decimalToNumber(buffer: Uint8Array) {
|
|
|
62
81
|
|
|
63
82
|
const OKAY = encodeUtf8("OKAY");
|
|
64
83
|
|
|
65
|
-
export class AdbReverseCommand
|
|
84
|
+
export class AdbReverseCommand {
|
|
66
85
|
protected adb: Adb;
|
|
67
86
|
|
|
68
87
|
readonly #deviceAddressToLocalAddress = new Map<string, string>();
|
|
69
88
|
|
|
70
89
|
constructor(adb: Adb) {
|
|
71
|
-
super();
|
|
72
|
-
|
|
73
90
|
this.adb = adb;
|
|
74
91
|
}
|
|
75
92
|
|
|
@@ -89,6 +106,9 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
89
106
|
return stream;
|
|
90
107
|
}
|
|
91
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Get a list of all reverse port forwarding on the device.
|
|
111
|
+
*/
|
|
92
112
|
async list(): Promise<AdbForwardListener[]> {
|
|
93
113
|
const stream = await this.createBufferedStream("reverse:list-forward");
|
|
94
114
|
|
|
@@ -107,10 +127,7 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
/**
|
|
110
|
-
* Add
|
|
111
|
-
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
112
|
-
* @param localAddress The address that listens on the local machine.
|
|
113
|
-
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
130
|
+
* Add a reverse port forwarding for a program that already listens on a port.
|
|
114
131
|
*/
|
|
115
132
|
async addExternal(deviceAddress: string, localAddress: string) {
|
|
116
133
|
const stream = await this.sendRequest(
|
|
@@ -143,12 +160,7 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
143
160
|
}
|
|
144
161
|
|
|
145
162
|
/**
|
|
146
|
-
*
|
|
147
|
-
* @param handler A callback to handle incoming connections.
|
|
148
|
-
* @param localAddressThe The address that listens on the local machine. May be `undefined` to let the transport choose an appropriate one.
|
|
149
|
-
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
150
|
-
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
151
|
-
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
163
|
+
* Add a reverse port forwarding.
|
|
152
164
|
*/
|
|
153
165
|
async add(
|
|
154
166
|
deviceAddress: string,
|
|
@@ -170,6 +182,9 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Remove a reverse port forwarding.
|
|
187
|
+
*/
|
|
173
188
|
async remove(deviceAddress: string): Promise<void> {
|
|
174
189
|
const localAddress =
|
|
175
190
|
this.#deviceAddressToLocalAddress.get(deviceAddress);
|
|
@@ -182,6 +197,9 @@ export class AdbReverseCommand extends AutoDisposable {
|
|
|
182
197
|
// No need to close the stream, device will close it
|
|
183
198
|
}
|
|
184
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Remove all reverse port forwarding, including the ones added by other programs.
|
|
202
|
+
*/
|
|
185
203
|
async removeAll(): Promise<void> {
|
|
186
204
|
await this.adb.transport.clearReverseTunnels();
|
|
187
205
|
this.#deviceAddressToLocalAddress.clear();
|
|
@@ -2,7 +2,6 @@ import type { MaybeConsumable, WritableStream } from "@yume-chan/stream-extra";
|
|
|
2
2
|
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
3
3
|
|
|
4
4
|
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
5
|
-
import { unreachable } from "../../../utils/index.js";
|
|
6
5
|
|
|
7
6
|
import type { AdbSubprocessProtocol } from "./types.js";
|
|
8
7
|
|
|
@@ -64,10 +63,9 @@ export class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
|
|
|
64
63
|
this.#socket = socket;
|
|
65
64
|
|
|
66
65
|
this.#stderr = new ReadableStream({
|
|
67
|
-
start: (controller) => {
|
|
68
|
-
this.#socket.closed
|
|
69
|
-
|
|
70
|
-
.catch(unreachable);
|
|
66
|
+
start: async (controller) => {
|
|
67
|
+
await this.#socket.closed;
|
|
68
|
+
controller.close();
|
|
71
69
|
},
|
|
72
70
|
});
|
|
73
71
|
this.#exit = socket.closed.then(() => 0);
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
StructDeserializeStream,
|
|
11
11
|
WritableStream,
|
|
12
12
|
} from "@yume-chan/stream-extra";
|
|
13
|
-
import type {
|
|
14
|
-
import
|
|
13
|
+
import type { StructValue } from "@yume-chan/struct";
|
|
14
|
+
import { buffer, struct, u32, u8 } from "@yume-chan/struct";
|
|
15
15
|
|
|
16
16
|
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
17
17
|
import { AdbFeature } from "../../../features.js";
|
|
@@ -19,22 +19,28 @@ import { encodeUtf8 } from "../../../utils/index.js";
|
|
|
19
19
|
|
|
20
20
|
import type { AdbSubprocessProtocol } from "./types.js";
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
Stdin,
|
|
24
|
-
Stdout,
|
|
25
|
-
Stderr,
|
|
26
|
-
Exit,
|
|
27
|
-
CloseStdin,
|
|
28
|
-
WindowSizeChange,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
export const AdbShellProtocolId = {
|
|
23
|
+
Stdin: 0,
|
|
24
|
+
Stdout: 1,
|
|
25
|
+
Stderr: 2,
|
|
26
|
+
Exit: 3,
|
|
27
|
+
CloseStdin: 4,
|
|
28
|
+
WindowSizeChange: 5,
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export type AdbShellProtocolId =
|
|
32
|
+
(typeof AdbShellProtocolId)[keyof typeof AdbShellProtocolId];
|
|
33
|
+
|
|
34
|
+
// This packet format is used in both directions.
|
|
35
|
+
export const AdbShellProtocolPacket = struct(
|
|
36
|
+
{
|
|
37
|
+
id: u8<AdbShellProtocolId>(),
|
|
38
|
+
data: buffer(u32),
|
|
39
|
+
},
|
|
40
|
+
{ littleEndian: true },
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
type AdbShellProtocolPacket = StructValue<typeof AdbShellProtocolPacket>;
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* Shell v2 a.k.a Shell Protocol
|
|
@@ -107,14 +113,10 @@ export class AdbSubprocessShellProtocol implements AdbSubprocessProtocol {
|
|
|
107
113
|
this.#exit.resolve(chunk.data[0]!);
|
|
108
114
|
break;
|
|
109
115
|
case AdbShellProtocolId.Stdout:
|
|
110
|
-
|
|
111
|
-
await stdoutController.enqueue(chunk.data);
|
|
112
|
-
}
|
|
116
|
+
await stdoutController.enqueue(chunk.data);
|
|
113
117
|
break;
|
|
114
118
|
case AdbShellProtocolId.Stderr:
|
|
115
|
-
|
|
116
|
-
await stderrController.enqueue(chunk.data);
|
|
117
|
-
}
|
|
119
|
+
await stderrController.enqueue(chunk.data);
|
|
118
120
|
break;
|
|
119
121
|
}
|
|
120
122
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
1
2
|
import type {
|
|
2
3
|
MaybeConsumable,
|
|
3
4
|
ReadableStream,
|
|
4
5
|
WritableStream,
|
|
5
6
|
} from "@yume-chan/stream-extra";
|
|
6
|
-
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
7
7
|
|
|
8
8
|
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
9
9
|
|
|
@@ -40,23 +40,23 @@ export interface AdbSubprocessProtocol {
|
|
|
40
40
|
* Some `AdbSubprocessProtocol`s may not support resizing
|
|
41
41
|
* and will ignore calls to this method.
|
|
42
42
|
*/
|
|
43
|
-
resize(rows: number, cols: number):
|
|
43
|
+
resize(rows: number, cols: number): MaybePromiseLike<void>;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Kills the current process.
|
|
47
47
|
*/
|
|
48
|
-
kill():
|
|
48
|
+
kill(): MaybePromiseLike<void>;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export interface AdbSubprocessProtocolConstructor {
|
|
52
52
|
/** Returns `true` if the `adb` instance supports this shell */
|
|
53
|
-
isSupported(adb: Adb):
|
|
53
|
+
isSupported(adb: Adb): MaybePromiseLike<boolean>;
|
|
54
54
|
|
|
55
55
|
/** Spawns an executable in PTY (interactive) mode. */
|
|
56
|
-
pty(adb: Adb, command: string):
|
|
56
|
+
pty(adb: Adb, command: string): MaybePromiseLike<AdbSubprocessProtocol>;
|
|
57
57
|
|
|
58
58
|
/** Spawns an executable and pipe the output. */
|
|
59
|
-
raw(adb: Adb, command: string):
|
|
59
|
+
raw(adb: Adb, command: string): MaybePromiseLike<AdbSubprocessProtocol>;
|
|
60
60
|
|
|
61
61
|
/** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
|
|
62
62
|
new (socket: AdbSocket): AdbSubprocessProtocol;
|