@yume-chan/adb 0.0.15 → 0.0.17
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 +33 -0
- package/CHANGELOG.md +18 -1
- package/LICENSE +21 -21
- package/README.md +247 -247
- package/esm/adb.d.ts +15 -3
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +18 -6
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +2 -2
- package/esm/backend.d.ts.map +1 -1
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +17 -1
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +4 -15
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/install.d.ts +2 -2
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +3 -2
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +1 -1
- package/esm/commands/power.js +1 -1
- package/esm/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +9 -9
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +52 -0
- package/esm/commands/subprocess/command.d.ts.map +1 -0
- package/esm/commands/subprocess/command.js +83 -0
- package/esm/commands/subprocess/command.js.map +1 -0
- package/esm/commands/subprocess/index.d.ts +1 -53
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +1 -85
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +5 -4
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +11 -8
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +4 -4
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +6 -6
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +7 -7
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/index.d.ts +1 -1
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +1 -1
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +2 -2
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +15 -43
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +3 -2
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +15 -17
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +2 -2
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +2 -5
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +1 -1
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +1 -1
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +4 -9
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +32 -23
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +3 -3
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +13 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +2 -2
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +7 -5
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.js +1 -1
- package/esm/crypto.js.map +1 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +1 -1
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +1 -1
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +11 -3
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +19 -11
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +1 -1
- package/esm/socket/index.d.ts.map +1 -1
- package/esm/socket/index.js +1 -1
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +9 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +20 -10
- package/esm/socket/socket.js.map +1 -1
- package/esm/utils/base64.d.ts +23 -0
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +6 -0
- package/esm/utils/base64.js.map +1 -1
- package/package.json +13 -14
- package/src/adb.ts +285 -273
- package/src/auth.ts +174 -173
- package/src/backend.ts +12 -11
- package/src/commands/base.ts +12 -11
- package/src/commands/framebuffer.ts +78 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -30
- package/src/commands/power.ts +54 -54
- package/src/commands/reverse.ts +141 -140
- package/src/commands/subprocess/command.ts +131 -0
- package/src/commands/subprocess/index.ts +3 -139
- package/src/commands/subprocess/protocols/none.ts +73 -68
- package/src/commands/subprocess/protocols/shell.ts +191 -190
- package/src/commands/subprocess/protocols/types.ts +60 -59
- package/src/commands/subprocess/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +54 -86
- package/src/commands/sync/pull.ts +45 -46
- package/src/commands/sync/push.ts +38 -41
- package/src/commands/sync/request.ts +51 -50
- package/src/commands/sync/response.ts +68 -64
- package/src/commands/sync/stat.ts +129 -150
- package/src/commands/sync/sync.ts +182 -181
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +296 -296
- package/src/features.ts +9 -9
- package/src/index.ts +10 -11
- package/src/packet.ts +80 -80
- package/src/socket/dispatcher.ts +310 -304
- package/src/socket/index.ts +2 -2
- package/src/socket/socket.ts +156 -144
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +329 -306
- package/src/utils/index.ts +3 -3
- package/tsconfig.build.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- 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/buffered.d.ts +0 -35
- package/esm/stream/buffered.d.ts.map +0 -1
- package/esm/stream/buffered.js +0 -123
- package/esm/stream/buffered.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/stream/detect.d.ts +0 -2
- package/esm/stream/detect.d.ts.map +0 -1
- package/esm/stream/detect.js +0 -5
- package/esm/stream/detect.js.map +0 -1
- package/esm/stream/detect.native.d.ts +0 -240
- package/esm/stream/detect.native.d.ts.map +0 -1
- package/esm/stream/detect.native.js +0 -60
- package/esm/stream/detect.native.js.map +0 -1
- package/esm/stream/detect.polyfill.d.ts +0 -18
- package/esm/stream/detect.polyfill.d.ts.map +0 -1
- package/esm/stream/detect.polyfill.js +0 -9
- package/esm/stream/detect.polyfill.js.map +0 -1
- package/esm/stream/index.d.ts +0 -4
- package/esm/stream/index.d.ts.map +0 -1
- package/esm/stream/index.js +0 -4
- package/esm/stream/index.js.map +0 -1
- package/esm/stream/transform.d.ts +0 -104
- package/esm/stream/transform.d.ts.map +0 -1
- package/esm/stream/transform.js +0 -373
- package/esm/stream/transform.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/stream/buffered.ts +0 -147
- package/src/stream/detect.native.ts +0 -362
- package/src/stream/detect.polyfill.ts +0 -28
- package/src/stream/detect.ts +0 -5
- package/src/stream/index.ts +0 -3
- package/src/stream/transform.ts +0 -447
- package/tsconfig.test.json +0 -10
package/src/auth.ts
CHANGED
|
@@ -1,173 +1,174 @@
|
|
|
1
|
-
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
-
import type { Disposable } from '@yume-chan/event';
|
|
3
|
-
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
publicKeyBuffer
|
|
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
|
-
this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
1
|
+
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
+
import type { Disposable } from '@yume-chan/event';
|
|
3
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
+
|
|
5
|
+
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
|
|
6
|
+
import { AdbCommand, type AdbPacketData } from './packet.js';
|
|
7
|
+
import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
|
|
8
|
+
|
|
9
|
+
export type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
10
|
+
|
|
11
|
+
export interface AdbCredentialStore {
|
|
12
|
+
/**
|
|
13
|
+
* Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
|
|
14
|
+
*
|
|
15
|
+
* The returned `Uint8Array` is the private key in PKCS #8 format.
|
|
16
|
+
*/
|
|
17
|
+
generateKey(): ValueOrPromise<Uint8Array>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Synchronously or asynchronously iterate through all stored RSA private keys.
|
|
21
|
+
*
|
|
22
|
+
* Each call to `iterateKeys` must return a different iterator that iterate through all stored keys.
|
|
23
|
+
*/
|
|
24
|
+
iterateKeys(): AdbKeyIterable;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export enum AdbAuthType {
|
|
28
|
+
Token = 1,
|
|
29
|
+
Signature = 2,
|
|
30
|
+
PublicKey = 3,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AdbAuthenticator {
|
|
34
|
+
/**
|
|
35
|
+
* @param getNextRequest
|
|
36
|
+
*
|
|
37
|
+
* Call this function to get the next authentication request packet from device.
|
|
38
|
+
*
|
|
39
|
+
* After calling `getNextRequest`, authenticator can `yield` a packet as response, or `return` to indicate its incapability of handling the request.
|
|
40
|
+
*
|
|
41
|
+
* After `return`, the `AdbAuthenticatorHandler` will move on to next authenticator and never go back.
|
|
42
|
+
*
|
|
43
|
+
* Calling `getNextRequest` multiple times without `yield` or `return` will always return the same request.
|
|
44
|
+
*/
|
|
45
|
+
(
|
|
46
|
+
credentialStore: AdbCredentialStore,
|
|
47
|
+
getNextRequest: () => Promise<AdbPacketData>
|
|
48
|
+
): AsyncIterable<AdbPacketData>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const AdbSignatureAuthenticator: AdbAuthenticator = async function* (
|
|
52
|
+
credentialStore: AdbCredentialStore,
|
|
53
|
+
getNextRequest: () => Promise<AdbPacketData>,
|
|
54
|
+
): AsyncIterable<AdbPacketData> {
|
|
55
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
56
|
+
const packet = await getNextRequest();
|
|
57
|
+
|
|
58
|
+
if (packet.arg0 !== AdbAuthType.Token) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const signature = sign(key, packet.payload);
|
|
63
|
+
yield {
|
|
64
|
+
command: AdbCommand.Auth,
|
|
65
|
+
arg0: AdbAuthType.Signature,
|
|
66
|
+
arg1: 0,
|
|
67
|
+
payload: new Uint8Array(signature),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
|
|
73
|
+
credentialStore: AdbCredentialStore,
|
|
74
|
+
getNextRequest: () => Promise<AdbPacketData>,
|
|
75
|
+
): AsyncIterable<AdbPacketData> {
|
|
76
|
+
const packet = await getNextRequest();
|
|
77
|
+
|
|
78
|
+
if (packet.arg0 !== AdbAuthType.Token) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let privateKey: Uint8Array | undefined;
|
|
83
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
84
|
+
privateKey = key;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if (!privateKey) {
|
|
90
|
+
privateKey = await credentialStore.generateKey();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const publicKeyLength = calculatePublicKeyLength();
|
|
94
|
+
const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
|
|
95
|
+
|
|
96
|
+
// The public key is null terminated,
|
|
97
|
+
// So we allocate the buffer with one extra byte.
|
|
98
|
+
const publicKeyBuffer = new Uint8Array(publicKeyBase64Length + 1);
|
|
99
|
+
|
|
100
|
+
calculatePublicKey(privateKey, publicKeyBuffer);
|
|
101
|
+
encodeBase64(
|
|
102
|
+
publicKeyBuffer.subarray(0, publicKeyLength),
|
|
103
|
+
publicKeyBuffer
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
yield {
|
|
107
|
+
command: AdbCommand.Auth,
|
|
108
|
+
arg0: AdbAuthType.PublicKey,
|
|
109
|
+
arg1: 0,
|
|
110
|
+
payload: publicKeyBuffer,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const ADB_DEFAULT_AUTHENTICATORS: AdbAuthenticator[] = [
|
|
115
|
+
AdbSignatureAuthenticator,
|
|
116
|
+
AdbPublicKeyAuthenticator,
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
export class AdbAuthenticationProcessor implements Disposable {
|
|
120
|
+
public readonly authenticators: readonly AdbAuthenticator[];
|
|
121
|
+
|
|
122
|
+
private readonly credentialStore: AdbCredentialStore;
|
|
123
|
+
|
|
124
|
+
private pendingRequest = new PromiseResolver<AdbPacketData>();
|
|
125
|
+
|
|
126
|
+
private iterator: AsyncIterator<AdbPacketData, void, void> | undefined;
|
|
127
|
+
|
|
128
|
+
public constructor(
|
|
129
|
+
authenticators: readonly AdbAuthenticator[],
|
|
130
|
+
credentialStore: AdbCredentialStore
|
|
131
|
+
) {
|
|
132
|
+
this.authenticators = authenticators;
|
|
133
|
+
this.credentialStore = credentialStore;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private getNextRequest = (): Promise<AdbPacketData> => {
|
|
137
|
+
return this.pendingRequest.promise;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
private async* invokeAuthenticator(): AsyncGenerator<AdbPacketData, void, void> {
|
|
141
|
+
for (const authenticator of this.authenticators) {
|
|
142
|
+
for await (const packet of authenticator(this.credentialStore, this.getNextRequest)) {
|
|
143
|
+
// If the authenticator yielded a response
|
|
144
|
+
// Prepare `nextRequest` for next authentication request
|
|
145
|
+
this.pendingRequest = new PromiseResolver();
|
|
146
|
+
|
|
147
|
+
// Yield the response to outer layer
|
|
148
|
+
yield packet;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// If the authenticator returned,
|
|
152
|
+
// Next authenticator will be given the same `pendingRequest`
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public async process(packet: AdbPacketData): Promise<AdbPacketData> {
|
|
157
|
+
if (!this.iterator) {
|
|
158
|
+
this.iterator = this.invokeAuthenticator();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.pendingRequest.resolve(packet);
|
|
162
|
+
|
|
163
|
+
const result = await this.iterator.next();
|
|
164
|
+
if (result.done) {
|
|
165
|
+
throw new Error('No authenticator can handle the request');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return result.value;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public dispose() {
|
|
172
|
+
this.iterator?.return?.();
|
|
173
|
+
}
|
|
174
|
+
}
|
package/src/backend.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import type { ReadableWritablePair } from '@yume-chan/stream-extra';
|
|
2
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import type { AdbPacketData, AdbPacketInit } from './packet.js';
|
|
5
|
+
|
|
6
|
+
export interface AdbBackend {
|
|
7
|
+
readonly serial: string;
|
|
8
|
+
|
|
9
|
+
readonly name: string | undefined;
|
|
10
|
+
|
|
11
|
+
connect(): ValueOrPromise<ReadableWritablePair<AdbPacketData, AdbPacketInit>>;
|
|
12
|
+
}
|
package/src/commands/base.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
+
|
|
3
|
+
import type { Adb } from '../adb.js';
|
|
4
|
+
|
|
5
|
+
export class AdbCommandBase extends AutoDisposable {
|
|
6
|
+
protected adb: Adb;
|
|
7
|
+
|
|
8
|
+
public constructor(adb: Adb) {
|
|
9
|
+
super();
|
|
10
|
+
this.adb = adb;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,73 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
.uint32('
|
|
31
|
-
.uint32('
|
|
32
|
-
.uint32('
|
|
33
|
-
.uint32('
|
|
34
|
-
.uint32('
|
|
35
|
-
.uint32('
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.uint32('
|
|
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
|
-
|
|
1
|
+
import { BufferedReadableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
import Struct from '@yume-chan/struct';
|
|
3
|
+
|
|
4
|
+
import type { Adb } from '../adb.js';
|
|
5
|
+
|
|
6
|
+
const Version =
|
|
7
|
+
new Struct({ littleEndian: true })
|
|
8
|
+
.uint32('version');
|
|
9
|
+
|
|
10
|
+
export const AdbFrameBufferV1 =
|
|
11
|
+
new Struct({ littleEndian: true })
|
|
12
|
+
.uint32('bpp')
|
|
13
|
+
.uint32('size')
|
|
14
|
+
.uint32('width')
|
|
15
|
+
.uint32('height')
|
|
16
|
+
.uint32('red_offset')
|
|
17
|
+
.uint32('red_length')
|
|
18
|
+
.uint32('blue_offset')
|
|
19
|
+
.uint32('blue_length')
|
|
20
|
+
.uint32('green_offset')
|
|
21
|
+
.uint32('green_length')
|
|
22
|
+
.uint32('alpha_offset')
|
|
23
|
+
.uint32('alpha_length')
|
|
24
|
+
.uint8Array('data', { lengthField: 'size' });
|
|
25
|
+
|
|
26
|
+
export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
|
|
27
|
+
|
|
28
|
+
export const AdbFrameBufferV2 =
|
|
29
|
+
new Struct({ littleEndian: true })
|
|
30
|
+
.uint32('bpp')
|
|
31
|
+
.uint32('colorSpace')
|
|
32
|
+
.uint32('size')
|
|
33
|
+
.uint32('width')
|
|
34
|
+
.uint32('height')
|
|
35
|
+
.uint32('red_offset')
|
|
36
|
+
.uint32('red_length')
|
|
37
|
+
.uint32('blue_offset')
|
|
38
|
+
.uint32('blue_length')
|
|
39
|
+
.uint32('green_offset')
|
|
40
|
+
.uint32('green_length')
|
|
41
|
+
.uint32('alpha_offset')
|
|
42
|
+
.uint32('alpha_length')
|
|
43
|
+
.uint8Array('data', { lengthField: 'size' });
|
|
44
|
+
|
|
45
|
+
export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* ADB uses 8 int32 fields to describe bit depths
|
|
49
|
+
*
|
|
50
|
+
* The only combination I have seen is RGBA8888, which is
|
|
51
|
+
*
|
|
52
|
+
* red_offset: 0
|
|
53
|
+
* red_length: 8
|
|
54
|
+
* blue_offset: 16
|
|
55
|
+
* blue_length: 8
|
|
56
|
+
* green_offset: 8
|
|
57
|
+
* green_length: 8
|
|
58
|
+
* alpha_offset: 24
|
|
59
|
+
* alpha_length: 8
|
|
60
|
+
*
|
|
61
|
+
* But it doesn't mean that other combinations are not possible.
|
|
62
|
+
*/
|
|
63
|
+
export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;
|
|
64
|
+
|
|
65
|
+
export async function framebuffer(adb: Adb): Promise<AdbFrameBuffer> {
|
|
66
|
+
const socket = await adb.createSocket('framebuffer:');
|
|
67
|
+
const stream = new BufferedReadableStream(socket.readable);
|
|
68
|
+
const { version } = await Version.deserialize(stream);
|
|
69
|
+
switch (version) {
|
|
70
|
+
case 1:
|
|
71
|
+
// TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
|
|
72
|
+
return AdbFrameBufferV1.deserialize(stream);
|
|
73
|
+
case 2:
|
|
74
|
+
return AdbFrameBufferV2.deserialize(stream);
|
|
75
|
+
default:
|
|
76
|
+
throw new Error('Unknown FrameBuffer version');
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './base.js';
|
|
2
|
-
export * from './framebuffer.js';
|
|
3
|
-
export * from './install.js';
|
|
4
|
-
export * from './power.js';
|
|
5
|
-
export * from './reverse.js';
|
|
6
|
-
export * from './subprocess/index.js';
|
|
7
|
-
export * from './sync/index.js';
|
|
8
|
-
export * from './tcpip.js';
|
|
1
|
+
export * from './base.js';
|
|
2
|
+
export * from './framebuffer.js';
|
|
3
|
+
export * from './install.js';
|
|
4
|
+
export * from './power.js';
|
|
5
|
+
export * from './reverse.js';
|
|
6
|
+
export * from './subprocess/index.js';
|
|
7
|
+
export * from './sync/index.js';
|
|
8
|
+
export * from './tcpip.js';
|
package/src/commands/install.ts
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
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
|
-
}
|
|
1
|
+
import { WrapWritableStream, WritableStream } from '@yume-chan/stream-extra';
|
|
2
|
+
|
|
3
|
+
import type { Adb } from '../adb.js';
|
|
4
|
+
import { escapeArg } from './subprocess/index.js';
|
|
5
|
+
import type { AdbSync } from './sync/index.js';
|
|
6
|
+
|
|
7
|
+
export function install(
|
|
8
|
+
adb: Adb,
|
|
9
|
+
): WritableStream<Uint8Array> {
|
|
10
|
+
const filename = `/data/local/tmp/${Math.random().toString().substring(2)}.apk`;
|
|
11
|
+
|
|
12
|
+
let sync!: AdbSync;
|
|
13
|
+
return new WrapWritableStream<Uint8Array>({
|
|
14
|
+
async start() {
|
|
15
|
+
// TODO: install: support other install apk methods (streaming, etc.)
|
|
16
|
+
// TODO: install: support split apk formats (`adb install-multiple`)
|
|
17
|
+
|
|
18
|
+
// Upload apk file to tmp folder
|
|
19
|
+
sync = await adb.sync();
|
|
20
|
+
return sync.write(filename, undefined, undefined);
|
|
21
|
+
},
|
|
22
|
+
async close() {
|
|
23
|
+
sync.dispose();
|
|
24
|
+
|
|
25
|
+
// Invoke `pm install` to install it
|
|
26
|
+
await adb.subprocess.spawnAndWaitLegacy(['pm', 'install', escapeArg(filename)]);
|
|
27
|
+
|
|
28
|
+
// Remove the temp file
|
|
29
|
+
await adb.rm(filename);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|