@yume-chan/adb 0.0.13 → 0.0.16
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 +57 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +21 -21
- package/README.md +247 -247
- package/esm/adb.d.ts +12 -4
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +29 -19
- package/esm/adb.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/protocols/none.d.ts +2 -1
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +10 -9
- package/esm/commands/subprocess/protocols/none.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/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +2 -2
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.js +1 -1
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +25 -14
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +94 -63
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/socket.d.ts +18 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +36 -21
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +7 -3
- package/esm/stream/buffered.d.ts.map +1 -1
- package/esm/stream/buffered.js +69 -49
- package/esm/stream/buffered.js.map +1 -1
- package/esm/stream/detect.js +1 -0
- 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 +0 -5
- package/esm/stream/detect.polyfill.js.map +1 -1
- package/esm/stream/transform.d.ts +39 -13
- package/esm/stream/transform.d.ts.map +1 -1
- package/esm/stream/transform.js +67 -90
- package/esm/stream/transform.js.map +1 -1
- package/esm/utils/base64.js +5 -5
- package/esm/utils/base64.js.map +1 -1
- package/package.json +10 -10
- package/src/adb.ts +280 -270
- package/src/auth.ts +173 -173
- package/src/backend.ts +11 -11
- package/src/commands/base.ts +11 -11
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +30 -30
- package/src/commands/power.ts +54 -54
- package/src/commands/reverse.ts +140 -136
- package/src/commands/subprocess/index.ts +139 -139
- package/src/commands/subprocess/protocols/none.ts +70 -68
- package/src/commands/subprocess/protocols/shell.ts +190 -190
- package/src/commands/subprocess/protocols/types.ts +59 -59
- package/src/commands/subprocess/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +86 -86
- package/src/commands/sync/pull.ts +46 -43
- package/src/commands/sync/push.ts +41 -41
- package/src/commands/sync/request.ts +50 -50
- package/src/commands/sync/response.ts +64 -64
- package/src/commands/sync/stat.ts +151 -150
- package/src/commands/sync/sync.ts +181 -181
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +296 -296
- package/src/features.ts +9 -9
- package/src/index.ts +11 -11
- package/src/packet.ts +80 -80
- package/src/socket/dispatcher.ts +305 -270
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +155 -136
- package/src/stream/buffered.ts +168 -147
- package/src/stream/detect.native.ts +362 -362
- package/src/stream/detect.polyfill.ts +22 -28
- package/src/stream/detect.ts +7 -5
- package/src/stream/index.ts +3 -3
- package/src/stream/transform.ts +474 -483
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +306 -306
- package/src/utils/index.ts +3 -3
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.test.json +9 -10
- package/web-streams-polyfill-4.0.0-beta.2.tgz +0 -0
- package/esm/commands/subprocess/legacy.d.ts +0 -35
- package/esm/commands/subprocess/legacy.d.ts.map +0 -1
- package/esm/commands/subprocess/legacy.js +0 -53
- package/esm/commands/subprocess/legacy.js.map +0 -1
- package/esm/commands/subprocess/protocol.d.ts +0 -39
- package/esm/commands/subprocess/protocol.d.ts.map +0 -1
- package/esm/commands/subprocess/protocol.js +0 -157
- package/esm/commands/subprocess/protocol.js.map +0 -1
- package/esm/commands/subprocess/types.d.ts +0 -50
- package/esm/commands/subprocess/types.d.ts.map +0 -1
- package/esm/commands/subprocess/types.js +0 -2
- package/esm/commands/subprocess/types.js.map +0 -1
- package/esm/socket/controller.d.ts +0 -37
- package/esm/socket/controller.d.ts.map +0 -1
- package/esm/socket/controller.js +0 -66
- package/esm/socket/controller.js.map +0 -1
- package/esm/stream/detect.bak.d.ts +0 -240
- package/esm/stream/detect.bak.d.ts.map +0 -1
- package/esm/stream/detect.bak.js +0 -60
- package/esm/stream/detect.bak.js.map +0 -1
- package/esm/utils/encoding.d.ts +0 -3
- package/esm/utils/encoding.d.ts.map +0 -1
- package/esm/utils/encoding.js +0 -11
- package/esm/utils/encoding.js.map +0 -1
package/src/commands/power.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
// cspell: ignore bootloader
|
|
2
|
-
// cspell: ignore fastboot
|
|
3
|
-
// cspell: ignore keyevent
|
|
4
|
-
// cspell: ignore longpress
|
|
5
|
-
|
|
6
|
-
import { AdbCommandBase } from "./base.js";
|
|
7
|
-
|
|
8
|
-
export class AdbPower extends AdbCommandBase {
|
|
9
|
-
public reboot(name: string = '') {
|
|
10
|
-
return this.adb.createSocketAndWait(`reboot:${name}`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public bootloader() {
|
|
14
|
-
return this.reboot('bootloader');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public fastboot() {
|
|
18
|
-
return this.reboot('fastboot');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public recovery() {
|
|
22
|
-
return this.reboot('recovery');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public sideload() {
|
|
26
|
-
return this.reboot('sideload');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
31
|
-
*
|
|
32
|
-
* Only works on some Qualcomm devices.
|
|
33
|
-
*/
|
|
34
|
-
public qualcommEdlMode() {
|
|
35
|
-
return this.reboot('edl');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public powerOff() {
|
|
39
|
-
return this.adb.subprocess.spawnAndWaitLegacy(['reboot', '-p']);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public powerButton(longPress: boolean = false) {
|
|
43
|
-
return this.adb.subprocess.spawnAndWaitLegacy(['input', 'keyevent', longPress ? '--longpress POWER' : 'POWER']);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Reboot to Samsung Odin download mode.
|
|
48
|
-
*
|
|
49
|
-
* Only works on Samsung devices.
|
|
50
|
-
*/
|
|
51
|
-
public samsungOdin() {
|
|
52
|
-
return this.reboot('download');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
// cspell: ignore bootloader
|
|
2
|
+
// cspell: ignore fastboot
|
|
3
|
+
// cspell: ignore keyevent
|
|
4
|
+
// cspell: ignore longpress
|
|
5
|
+
|
|
6
|
+
import { AdbCommandBase } from "./base.js";
|
|
7
|
+
|
|
8
|
+
export class AdbPower extends AdbCommandBase {
|
|
9
|
+
public reboot(name: string = '') {
|
|
10
|
+
return this.adb.createSocketAndWait(`reboot:${name}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public bootloader() {
|
|
14
|
+
return this.reboot('bootloader');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public fastboot() {
|
|
18
|
+
return this.reboot('fastboot');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public recovery() {
|
|
22
|
+
return this.reboot('recovery');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public sideload() {
|
|
26
|
+
return this.reboot('sideload');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
31
|
+
*
|
|
32
|
+
* Only works on some Qualcomm devices.
|
|
33
|
+
*/
|
|
34
|
+
public qualcommEdlMode() {
|
|
35
|
+
return this.reboot('edl');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public powerOff() {
|
|
39
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['reboot', '-p']);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public powerButton(longPress: boolean = false) {
|
|
43
|
+
return this.adb.subprocess.spawnAndWaitLegacy(['input', 'keyevent', longPress ? '--longpress POWER' : 'POWER']);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reboot to Samsung Odin download mode.
|
|
48
|
+
*
|
|
49
|
+
* Only works on Samsung devices.
|
|
50
|
+
*/
|
|
51
|
+
public samsungOdin() {
|
|
52
|
+
return this.reboot('download');
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/commands/reverse.ts
CHANGED
|
@@ -1,136 +1,140 @@
|
|
|
1
|
-
// cspell: ignore killforward
|
|
2
|
-
|
|
3
|
-
import { AutoDisposable } from '@yume-chan/event';
|
|
4
|
-
import Struct from '@yume-chan/struct';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import { AdbBufferedStream } from '../stream/index.js';
|
|
8
|
-
import { decodeUtf8 } from "../utils/index.js";
|
|
9
|
-
|
|
10
|
-
export interface
|
|
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
|
-
protected
|
|
36
|
-
|
|
37
|
-
protected
|
|
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
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
1
|
+
// cspell: ignore killforward
|
|
2
|
+
|
|
3
|
+
import { AutoDisposable } from '@yume-chan/event';
|
|
4
|
+
import Struct from '@yume-chan/struct';
|
|
5
|
+
import type { Adb } from "../adb.js";
|
|
6
|
+
import type { AdbIncomingSocketHandler, AdbSocket } from '../socket/index.js';
|
|
7
|
+
import { AdbBufferedStream, BufferedStreamEndedError } from '../stream/index.js';
|
|
8
|
+
import { decodeUtf8 } from "../utils/index.js";
|
|
9
|
+
|
|
10
|
+
export interface AdbForwardListener {
|
|
11
|
+
deviceSerial: string;
|
|
12
|
+
|
|
13
|
+
localName: string;
|
|
14
|
+
|
|
15
|
+
remoteName: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const AdbReverseStringResponse =
|
|
19
|
+
new Struct()
|
|
20
|
+
.string('length', { length: 4 })
|
|
21
|
+
.string('content', { lengthField: 'length', lengthFieldRadix: 16 });
|
|
22
|
+
|
|
23
|
+
const AdbReverseErrorResponse =
|
|
24
|
+
new Struct()
|
|
25
|
+
.fields(AdbReverseStringResponse)
|
|
26
|
+
.postDeserialize((value) => {
|
|
27
|
+
throw new Error(value.content);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export class AdbReverseCommand extends AutoDisposable {
|
|
31
|
+
protected localAddressToHandler = new Map<string, AdbIncomingSocketHandler>();
|
|
32
|
+
|
|
33
|
+
protected deviceAddressToLocalAddress = new Map<string, string>();
|
|
34
|
+
|
|
35
|
+
protected adb: Adb;
|
|
36
|
+
|
|
37
|
+
protected listening = false;
|
|
38
|
+
|
|
39
|
+
public constructor(adb: Adb) {
|
|
40
|
+
super();
|
|
41
|
+
|
|
42
|
+
this.adb = adb;
|
|
43
|
+
this.addDisposable(this.adb.addIncomingSocketHandler(this.handleIncomingSocket));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected handleIncomingSocket = async (socket: AdbSocket) => {
|
|
47
|
+
let address = socket.serviceString;
|
|
48
|
+
// ADB daemon appends `\0` to the service string
|
|
49
|
+
address = address.replace(/\0/g, '');
|
|
50
|
+
return !!(await this.localAddressToHandler.get(address)?.(socket));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
private async createBufferedStream(service: string) {
|
|
54
|
+
const socket = await this.adb.createSocket(service);
|
|
55
|
+
return new AdbBufferedStream(socket);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async sendRequest(service: string) {
|
|
59
|
+
const stream = await this.createBufferedStream(service);
|
|
60
|
+
const success = decodeUtf8(await stream.read(4)) === 'OKAY';
|
|
61
|
+
if (!success) {
|
|
62
|
+
await AdbReverseErrorResponse.deserialize(stream);
|
|
63
|
+
}
|
|
64
|
+
return stream;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async list(): Promise<AdbForwardListener[]> {
|
|
68
|
+
const stream = await this.createBufferedStream('reverse:list-forward');
|
|
69
|
+
|
|
70
|
+
const response = await AdbReverseStringResponse.deserialize(stream);
|
|
71
|
+
return response.content!.split('\n').map(line => {
|
|
72
|
+
const [deviceSerial, localName, remoteName] = line.split(' ') as [string, string, string];
|
|
73
|
+
return { deviceSerial, localName, remoteName };
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// No need to close the stream, device will close it
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param deviceAddress The address adbd on device is listening on. Can be `tcp:0` to let adbd choose an available TCP port by itself.
|
|
81
|
+
* @param localAddress Native ADB client will open a connection to this address when reverse connection received. In WebADB, it's only used to uniquely identify a reverse tunnel registry, `handler` will be called to handle the connection.
|
|
82
|
+
* @param handler A callback to handle incoming connections
|
|
83
|
+
* @returns If `deviceAddress` is `tcp:0`, return `tcp:{ACTUAL_LISTENING_PORT}`; otherwise, return `deviceAddress`.
|
|
84
|
+
*/
|
|
85
|
+
public async add(
|
|
86
|
+
deviceAddress: string,
|
|
87
|
+
localAddress: string,
|
|
88
|
+
handler: AdbIncomingSocketHandler,
|
|
89
|
+
): Promise<string> {
|
|
90
|
+
const stream = await this.sendRequest(`reverse:forward:${deviceAddress};${localAddress}`);
|
|
91
|
+
|
|
92
|
+
// `tcp:0` tells the device to pick an available port.
|
|
93
|
+
// Begin with Android 8, device will respond with the selected port for all `tcp:` requests.
|
|
94
|
+
if (deviceAddress.startsWith('tcp:')) {
|
|
95
|
+
let length: number | undefined;
|
|
96
|
+
try {
|
|
97
|
+
length = Number.parseInt(decodeUtf8(await stream.read(4)), 16);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (!(e instanceof BufferedStreamEndedError)) {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Device before Android 8 doesn't have this response.
|
|
104
|
+
// (the stream is closed now)
|
|
105
|
+
// Can be safely ignored.
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (length !== undefined) {
|
|
109
|
+
const port = decodeUtf8(await stream.read(length!));
|
|
110
|
+
deviceAddress = `tcp:${Number.parseInt(port, 10)}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.localAddressToHandler.set(localAddress, handler);
|
|
115
|
+
this.deviceAddressToLocalAddress.set(deviceAddress, localAddress);
|
|
116
|
+
return deviceAddress;
|
|
117
|
+
|
|
118
|
+
// No need to close the stream, device will close it
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public async remove(deviceAddress: string): Promise<void> {
|
|
122
|
+
await this.sendRequest(`reverse:killforward:${deviceAddress}`);
|
|
123
|
+
|
|
124
|
+
if (this.deviceAddressToLocalAddress.has(deviceAddress)) {
|
|
125
|
+
this.localAddressToHandler.delete(this.deviceAddressToLocalAddress.get(deviceAddress)!);
|
|
126
|
+
this.deviceAddressToLocalAddress.delete(deviceAddress);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// No need to close the stream, device will close it
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async removeAll(): Promise<void> {
|
|
133
|
+
await this.sendRequest(`reverse:killforward-all`);
|
|
134
|
+
|
|
135
|
+
this.deviceAddressToLocalAddress.clear();
|
|
136
|
+
this.localAddressToHandler.clear();
|
|
137
|
+
|
|
138
|
+
// No need to close the stream, device will close it
|
|
139
|
+
}
|
|
140
|
+
}
|