@yume-chan/adb 0.0.18 → 0.0.20
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 +25 -1
- package/README.md +220 -103
- package/esm/adb.d.ts +43 -60
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +68 -249
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +17 -0
- package/esm/banner.d.ts.map +1 -0
- package/esm/banner.js +67 -0
- package/esm/banner.js.map +1 -0
- package/esm/commands/base.d.ts +6 -6
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +8 -8
- package/esm/commands/framebuffer.d.ts +53 -53
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +46 -46
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +7 -8
- package/esm/commands/index.d.ts.map +1 -1
- package/esm/commands/index.js +7 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/power.d.ts +22 -22
- package/esm/commands/power.js +48 -48
- package/esm/commands/reverse.d.ts +40 -28
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +130 -100
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +57 -51
- package/esm/commands/subprocess/command.d.ts.map +1 -1
- package/esm/commands/subprocess/command.js +86 -80
- package/esm/commands/subprocess/command.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -3
- package/esm/commands/subprocess/index.js +3 -3
- package/esm/commands/subprocess/protocols/index.d.ts +3 -3
- package/esm/commands/subprocess/protocols/index.js +3 -3
- package/esm/commands/subprocess/protocols/none.d.ts +30 -35
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +65 -55
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +33 -38
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +172 -162
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +48 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/types.js +1 -1
- package/esm/commands/subprocess/utils.d.ts +1 -1
- package/esm/commands/subprocess/utils.js +18 -18
- package/esm/commands/sync/index.d.ts +8 -7
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +8 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +42 -40
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +67 -47
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +13 -11
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +35 -37
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +57 -7
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +89 -22
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +26 -23
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +40 -42
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +19 -19
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +54 -54
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +22 -0
- package/esm/commands/sync/socket.d.ts.map +1 -0
- package/esm/commands/sync/socket.js +69 -0
- package/esm/commands/sync/socket.js.map +1 -0
- package/esm/commands/sync/stat.d.ts +72 -72
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +116 -104
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +65 -60
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +123 -149
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +5 -5
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +20 -18
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/{auth.d.ts → daemon/auth.d.ts} +50 -51
- package/esm/daemon/auth.d.ts.map +1 -0
- package/esm/{auth.js → daemon/auth.js} +95 -96
- package/esm/daemon/auth.js.map +1 -0
- package/esm/daemon/connection.d.ts +11 -0
- package/esm/daemon/connection.d.ts.map +1 -0
- package/esm/daemon/connection.js +2 -0
- package/esm/daemon/connection.js.map +1 -0
- package/esm/{crypto.d.ts → daemon/crypto.d.ts} +36 -36
- package/esm/daemon/crypto.d.ts.map +1 -0
- package/esm/{crypto.js → daemon/crypto.js} +244 -248
- package/esm/daemon/crypto.js.map +1 -0
- package/esm/daemon/device.d.ts +9 -0
- package/esm/daemon/device.d.ts.map +1 -0
- package/esm/daemon/device.js +2 -0
- package/esm/daemon/device.js.map +1 -0
- package/esm/daemon/dispatcher.d.ts +42 -0
- package/esm/daemon/dispatcher.d.ts.map +1 -0
- package/esm/{socket → daemon}/dispatcher.js +225 -234
- package/esm/daemon/dispatcher.js.map +1 -0
- package/esm/daemon/index.d.ts +8 -0
- package/esm/daemon/index.d.ts.map +1 -0
- package/esm/daemon/index.js +8 -0
- package/esm/daemon/index.js.map +1 -0
- package/esm/{packet.d.ts → daemon/packet.d.ts} +45 -46
- package/esm/daemon/packet.d.ts.map +1 -0
- package/esm/{packet.js → daemon/packet.js} +43 -48
- package/esm/daemon/packet.js.map +1 -0
- package/esm/daemon/socket.d.ts +58 -0
- package/esm/daemon/socket.d.ts.map +1 -0
- package/esm/{socket → daemon}/socket.js +121 -118
- package/esm/daemon/socket.js.map +1 -0
- package/esm/daemon/transport.d.ts +45 -0
- package/esm/daemon/transport.d.ts.map +1 -0
- package/esm/daemon/transport.js +184 -0
- package/esm/daemon/transport.js.map +1 -0
- package/esm/features.d.ts +10 -7
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +13 -10
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +7 -9
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -9
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +78 -0
- package/esm/server/client.d.ts.map +1 -0
- package/esm/server/client.js +329 -0
- package/esm/server/client.js.map +1 -0
- package/esm/server/index.d.ts +3 -0
- package/esm/server/index.d.ts.map +1 -0
- package/esm/server/index.js +3 -0
- package/esm/server/index.js.map +1 -0
- package/esm/server/transport.d.ts +19 -0
- package/esm/server/transport.d.ts.map +1 -0
- package/esm/server/transport.js +44 -0
- package/esm/server/transport.js.map +1 -0
- package/esm/utils/auto-reset-event.d.ts +8 -9
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +33 -33
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +27 -27
- package/esm/utils/base64.js +246 -246
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/conditional-variable.d.ts +8 -0
- package/esm/utils/conditional-variable.d.ts.map +1 -0
- package/esm/utils/conditional-variable.js +34 -0
- package/esm/utils/conditional-variable.js.map +1 -0
- package/esm/utils/hex.d.ts +3 -0
- package/esm/utils/hex.d.ts.map +1 -0
- package/esm/utils/hex.js +55 -0
- package/esm/utils/hex.js.map +1 -0
- package/esm/utils/index.d.ts +6 -3
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +6 -3
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/no-op.d.ts +7 -0
- package/esm/utils/no-op.d.ts.map +1 -0
- package/esm/utils/no-op.js +12 -0
- package/esm/utils/no-op.js.map +1 -0
- package/package.json +14 -12
- package/src/adb.ts +47 -248
- package/src/banner.ts +82 -0
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +7 -8
- package/src/commands/power.ts +2 -2
- package/src/commands/reverse.ts +90 -70
- package/src/commands/subprocess/command.ts +12 -4
- package/src/commands/subprocess/index.ts +3 -3
- package/src/commands/subprocess/protocols/index.ts +3 -3
- package/src/commands/subprocess/protocols/none.ts +36 -23
- package/src/commands/subprocess/protocols/shell.ts +94 -74
- package/src/commands/subprocess/protocols/types.ts +7 -7
- package/src/commands/subprocess/utils.ts +1 -1
- package/src/commands/sync/index.ts +8 -7
- package/src/commands/sync/list.ts +44 -25
- package/src/commands/sync/pull.ts +40 -45
- package/src/commands/sync/push.ts +158 -39
- package/src/commands/sync/request.ts +21 -16
- package/src/commands/sync/response.ts +10 -9
- package/src/commands/sync/socket.ts +99 -0
- package/src/commands/sync/stat.ts +47 -42
- package/src/commands/sync/sync.ts +73 -116
- package/src/commands/tcpip.ts +9 -7
- package/src/{auth.ts → daemon/auth.ts} +24 -23
- package/src/{crypto.ts → daemon/crypto.ts} +25 -33
- package/src/daemon/device.ts +14 -0
- package/src/{socket → daemon}/dispatcher.ts +95 -117
- package/src/daemon/index.ts +7 -0
- package/src/daemon/packet.ts +75 -0
- package/src/{socket → daemon}/socket.ts +71 -56
- package/src/daemon/transport.ts +269 -0
- package/src/features.ts +9 -6
- package/src/index.ts +3 -5
- package/src/server/client.ts +476 -0
- package/src/server/index.ts +2 -0
- package/src/server/transport.ts +77 -0
- package/src/utils/auto-reset-event.ts +14 -15
- package/src/utils/conditional-variable.ts +45 -0
- package/src/utils/hex.ts +58 -0
- package/src/utils/index.ts +6 -3
- package/src/utils/no-op.ts +12 -0
- package/tsconfig.build.json +12 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/auth.d.ts.map +0 -1
- package/esm/auth.js.map +0 -1
- package/esm/backend.d.ts +0 -9
- package/esm/backend.d.ts.map +0 -1
- package/esm/backend.js +0 -2
- package/esm/backend.js.map +0 -1
- package/esm/commands/install.d.ts +0 -4
- package/esm/commands/install.d.ts.map +0 -1
- package/esm/commands/install.js +0 -29
- package/esm/commands/install.js.map +0 -1
- package/esm/crypto.d.ts.map +0 -1
- package/esm/crypto.js.map +0 -1
- package/esm/packet.d.ts.map +0 -1
- package/esm/packet.js.map +0 -1
- package/esm/socket/dispatcher.d.ts +0 -60
- package/esm/socket/dispatcher.d.ts.map +0 -1
- package/esm/socket/dispatcher.js.map +0 -1
- package/esm/socket/index.d.ts +0 -3
- package/esm/socket/index.d.ts.map +0 -1
- package/esm/socket/index.js +0 -3
- package/esm/socket/index.js.map +0 -1
- package/esm/socket/socket.d.ts +0 -60
- package/esm/socket/socket.d.ts.map +0 -1
- package/esm/socket/socket.js.map +0 -1
- package/src/backend.ts +0 -14
- package/src/commands/install.ts +0 -40
- package/src/packet.ts +0 -90
- package/src/socket/index.ts +0 -2
|
@@ -1,249 +1,245 @@
|
|
|
1
|
-
import { getBigUint64, setBigUint64, } from "@yume-chan/dataview-bigint-polyfill/esm/fallback.js";
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
// https://
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// https://
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
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
|
-
output
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
setBigUint(outputView, outputOffset,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
export const
|
|
192
|
-
|
|
193
|
-
export const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
index
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
padded
|
|
236
|
-
|
|
237
|
-
padded
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// re-use the buffer to store the result
|
|
246
|
-
setBigUint(view, 0, signature, false);
|
|
247
|
-
return padded;
|
|
248
|
-
}
|
|
1
|
+
import { getBigUint64, setBigUint64, } from "@yume-chan/dataview-bigint-polyfill/esm/fallback.js";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the `BigInt` value at the specified byte offset and length from the start of the view. There is
|
|
4
|
+
* no alignment constraint; multi-byte values may be fetched from any offset.
|
|
5
|
+
*
|
|
6
|
+
* Only supports Big-Endian, because that's what ADB uses.
|
|
7
|
+
* @param byteOffset The place in the buffer at which the value should be retrieved.
|
|
8
|
+
*/
|
|
9
|
+
export function getBigUint(dataView, byteOffset, length) {
|
|
10
|
+
let result = 0n;
|
|
11
|
+
// Currently `length` must be a multiplication of 8
|
|
12
|
+
// Support for arbitrary length can be easily added
|
|
13
|
+
for (let i = byteOffset; i < byteOffset + length; i += 8) {
|
|
14
|
+
result <<= 64n;
|
|
15
|
+
const value = getBigUint64(dataView, i, false);
|
|
16
|
+
result += value;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Stores an arbitrary-precision positive `BigInt` value at the specified byte offset from the start of the view.
|
|
22
|
+
* @param byteOffset The place in the buffer at which the value should be set.
|
|
23
|
+
* @param value The value to set.
|
|
24
|
+
* @param littleEndian If `false` or `undefined`, a big-endian value should be written,
|
|
25
|
+
* otherwise a little-endian value should be written.
|
|
26
|
+
*/
|
|
27
|
+
export function setBigUint(dataView, byteOffset, value, littleEndian) {
|
|
28
|
+
const start = byteOffset;
|
|
29
|
+
if (littleEndian) {
|
|
30
|
+
while (value > 0n) {
|
|
31
|
+
setBigUint64(dataView, byteOffset, value, true);
|
|
32
|
+
byteOffset += 8;
|
|
33
|
+
value >>= 64n;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Because we don't know how long (in bits) the `value` is,
|
|
38
|
+
// Convert it to an array of `uint64` first.
|
|
39
|
+
const uint64Array = [];
|
|
40
|
+
while (value > 0n) {
|
|
41
|
+
uint64Array.push(BigInt.asUintN(64, value));
|
|
42
|
+
value >>= 64n;
|
|
43
|
+
}
|
|
44
|
+
for (let i = uint64Array.length - 1; i >= 0; i -= 1) {
|
|
45
|
+
setBigUint64(dataView, byteOffset, uint64Array[i], false);
|
|
46
|
+
byteOffset += 8;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return byteOffset - start;
|
|
50
|
+
}
|
|
51
|
+
// These values are correct only if
|
|
52
|
+
// modulus length is 2048 and
|
|
53
|
+
// public exponent (e) is 65537
|
|
54
|
+
// Anyway, that's how this library generates keys
|
|
55
|
+
// To support other parameters,
|
|
56
|
+
// a proper ASN.1 parser can be used
|
|
57
|
+
// References:
|
|
58
|
+
//
|
|
59
|
+
// https://tools.ietf.org/html/rfc8017#appendix-A.1.2
|
|
60
|
+
// PKCS #1: RSA Cryptography Specifications Version 2.2
|
|
61
|
+
// A.1.2. RSA Private Key Syntax
|
|
62
|
+
//
|
|
63
|
+
// https://lapo.it/asn1js/
|
|
64
|
+
// https://github.com/lapo-luchini/asn1js
|
|
65
|
+
// ASN.1 JavaScript decoder
|
|
66
|
+
//
|
|
67
|
+
// https://www.itu.int/rec/T-REC-X.690-201508-I/en
|
|
68
|
+
// X.690: Specification of Distinguished Encoding Rules (DER)
|
|
69
|
+
const RsaPrivateKeyNOffset = 38;
|
|
70
|
+
const RsaPrivateKeyNLength = 2048 / 8;
|
|
71
|
+
const RsaPrivateKeyDOffset = 303;
|
|
72
|
+
const RsaPrivateKeyDLength = 2048 / 8;
|
|
73
|
+
export function rsaParsePrivateKey(key) {
|
|
74
|
+
const view = new DataView(key.buffer, key.byteOffset, key.byteLength);
|
|
75
|
+
const n = getBigUint(view, RsaPrivateKeyNOffset, RsaPrivateKeyNLength);
|
|
76
|
+
const d = getBigUint(view, RsaPrivateKeyDOffset, RsaPrivateKeyDLength);
|
|
77
|
+
return [n, d];
|
|
78
|
+
}
|
|
79
|
+
// Taken from https://stackoverflow.com/a/51562038
|
|
80
|
+
// I can't understand, but it does work
|
|
81
|
+
// Only used with numbers smaller than 2^32 so doesn't need BigInt
|
|
82
|
+
export function modInverse(a, m) {
|
|
83
|
+
a = ((a % m) + m) % m;
|
|
84
|
+
if (!a || m < 2) {
|
|
85
|
+
return NaN; // invalid input
|
|
86
|
+
}
|
|
87
|
+
// find the gcd
|
|
88
|
+
const s = [];
|
|
89
|
+
let b = m;
|
|
90
|
+
while (b) {
|
|
91
|
+
[a, b] = [b, a % b];
|
|
92
|
+
s.push({ a, b });
|
|
93
|
+
}
|
|
94
|
+
if (a !== 1) {
|
|
95
|
+
return NaN; // inverse does not exists
|
|
96
|
+
}
|
|
97
|
+
// find the inverse
|
|
98
|
+
let x = 1;
|
|
99
|
+
let y = 0;
|
|
100
|
+
for (let i = s.length - 2; i >= 0; i -= 1) {
|
|
101
|
+
[x, y] = [y, x - y * Math.floor(s[i].a / s[i].b)];
|
|
102
|
+
}
|
|
103
|
+
return ((y % m) + m) % m;
|
|
104
|
+
}
|
|
105
|
+
export function adbGetPublicKeySize() {
|
|
106
|
+
return 4 + 4 + 2048 / 8 + 2048 / 8 + 4;
|
|
107
|
+
}
|
|
108
|
+
export function adbGeneratePublicKey(privateKey, output) {
|
|
109
|
+
// Android has its own public key generation algorithm
|
|
110
|
+
// See https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#111
|
|
111
|
+
// The public key is an array of
|
|
112
|
+
//
|
|
113
|
+
// [
|
|
114
|
+
// modulusLengthInWords, // 32-bit integer, a "word" is 32-bit so it must be 2048 / 8 / 4
|
|
115
|
+
// // Actually the comment in Android source code was wrong
|
|
116
|
+
// n0inv, // 32-bit integer, the modular inverse of (low 32 bits of n)
|
|
117
|
+
// modulus, // n
|
|
118
|
+
// rr, // Montgomery parameter R^2
|
|
119
|
+
// exponent, // 32-bit integer, must be 65537
|
|
120
|
+
// ]
|
|
121
|
+
//
|
|
122
|
+
// (All in little endian)
|
|
123
|
+
// See https://android.googlesource.com/platform/system/core.git/+/91784040db2b9273687f88d8b95f729d4a61ecc2/libcrypto_utils/android_pubkey.cpp#38
|
|
124
|
+
// extract `n` from private key
|
|
125
|
+
const [n] = rsaParsePrivateKey(privateKey);
|
|
126
|
+
let outputType;
|
|
127
|
+
const outputLength = adbGetPublicKeySize();
|
|
128
|
+
if (!output) {
|
|
129
|
+
output = new Uint8Array(outputLength);
|
|
130
|
+
outputType = "Uint8Array";
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (output.byteLength < outputLength) {
|
|
134
|
+
throw new Error("output buffer is too small");
|
|
135
|
+
}
|
|
136
|
+
outputType = "number";
|
|
137
|
+
}
|
|
138
|
+
const outputView = new DataView(output.buffer, output.byteOffset, output.byteLength);
|
|
139
|
+
let outputOffset = 0;
|
|
140
|
+
// modulusLengthInWords
|
|
141
|
+
outputView.setUint32(outputOffset, 2048 / 8 / 4, true);
|
|
142
|
+
outputOffset += 4;
|
|
143
|
+
// Calculate `n0inv`
|
|
144
|
+
// Don't know why need to multiply by -1
|
|
145
|
+
// Didn't exist in Android codebase
|
|
146
|
+
const n0inv = modInverse(-Number(BigInt.asUintN(32, n)), 2 ** 32);
|
|
147
|
+
outputView.setUint32(outputOffset, n0inv, true);
|
|
148
|
+
outputOffset += 4;
|
|
149
|
+
// Write n
|
|
150
|
+
setBigUint(outputView, outputOffset, n, true);
|
|
151
|
+
outputOffset += 256;
|
|
152
|
+
// Calculate rr = (2^(rsa_size)) ^ 2 mod n
|
|
153
|
+
const rr = 2n ** 4096n % n;
|
|
154
|
+
outputOffset += setBigUint(outputView, outputOffset, rr, true);
|
|
155
|
+
// exponent
|
|
156
|
+
outputView.setUint32(outputOffset, 65537, true);
|
|
157
|
+
outputOffset += 4;
|
|
158
|
+
if (outputType === "Uint8Array") {
|
|
159
|
+
return output;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return outputLength;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Modular exponentiation.
|
|
167
|
+
*
|
|
168
|
+
* Calculate `(base ** exponent) % modulus` without actually calculating `(base ** exponent)`.
|
|
169
|
+
*
|
|
170
|
+
* See https://en.wikipedia.org/wiki/Modular_exponentiation#Implementation_in_Lua
|
|
171
|
+
*/
|
|
172
|
+
export function powMod(base, exponent, modulus) {
|
|
173
|
+
if (modulus === 1n) {
|
|
174
|
+
return 0n;
|
|
175
|
+
}
|
|
176
|
+
let r = 1n;
|
|
177
|
+
base = base % modulus;
|
|
178
|
+
while (exponent > 0n) {
|
|
179
|
+
if (BigInt.asUintN(1, exponent) === 1n) {
|
|
180
|
+
r = (r * base) % modulus;
|
|
181
|
+
}
|
|
182
|
+
base = (base * base) % modulus;
|
|
183
|
+
exponent >>= 1n;
|
|
184
|
+
}
|
|
185
|
+
return r;
|
|
186
|
+
}
|
|
187
|
+
export const SHA1_DIGEST_LENGTH = 20;
|
|
188
|
+
export const ASN1_SEQUENCE = 0x30;
|
|
189
|
+
export const ASN1_OCTET_STRING = 0x04;
|
|
190
|
+
export const ASN1_NULL = 0x05;
|
|
191
|
+
export const ASN1_OID = 0x06;
|
|
192
|
+
// PKCS#1 SHA-1 hash digest info
|
|
193
|
+
export const SHA1_DIGEST_INFO = new Uint8Array([
|
|
194
|
+
ASN1_SEQUENCE,
|
|
195
|
+
0x0d + SHA1_DIGEST_LENGTH,
|
|
196
|
+
ASN1_SEQUENCE,
|
|
197
|
+
0x09,
|
|
198
|
+
// SHA-1 (1 3 14 3 2 26)
|
|
199
|
+
ASN1_OID,
|
|
200
|
+
0x05,
|
|
201
|
+
1 * 40 + 3,
|
|
202
|
+
14,
|
|
203
|
+
3,
|
|
204
|
+
2,
|
|
205
|
+
26,
|
|
206
|
+
ASN1_NULL,
|
|
207
|
+
0x00,
|
|
208
|
+
ASN1_OCTET_STRING,
|
|
209
|
+
SHA1_DIGEST_LENGTH,
|
|
210
|
+
]);
|
|
211
|
+
// SubtleCrypto.sign() will hash the given data and sign the hash
|
|
212
|
+
// But we don't need the hashing step
|
|
213
|
+
// (In another word, ADB just requires the client to
|
|
214
|
+
// encrypt the given data with its private key)
|
|
215
|
+
// However SubtileCrypto.encrypt() doesn't accept 'RSASSA-PKCS1-v1_5' algorithm
|
|
216
|
+
// So we need to implement the encryption by ourself
|
|
217
|
+
export function rsaSign(privateKey, data) {
|
|
218
|
+
const [n, d] = rsaParsePrivateKey(privateKey);
|
|
219
|
+
// PKCS#1 padding
|
|
220
|
+
const padded = new Uint8Array(256);
|
|
221
|
+
let index = 0;
|
|
222
|
+
padded[index] = 0;
|
|
223
|
+
index += 1;
|
|
224
|
+
padded[index] = 1;
|
|
225
|
+
index += 1;
|
|
226
|
+
const fillLength = padded.length - SHA1_DIGEST_INFO.length - data.length - 1;
|
|
227
|
+
while (index < fillLength) {
|
|
228
|
+
padded[index] = 0xff;
|
|
229
|
+
index += 1;
|
|
230
|
+
}
|
|
231
|
+
padded[index] = 0;
|
|
232
|
+
index += 1;
|
|
233
|
+
padded.set(SHA1_DIGEST_INFO, index);
|
|
234
|
+
index += SHA1_DIGEST_INFO.length;
|
|
235
|
+
padded.set(data, index);
|
|
236
|
+
// Encryption
|
|
237
|
+
// signature = padded ** d % n
|
|
238
|
+
const view = new DataView(padded.buffer);
|
|
239
|
+
const signature = powMod(getBigUint(view, 0, view.byteLength), d, n);
|
|
240
|
+
// `padded` is not used anymore,
|
|
241
|
+
// re-use the buffer to store the result
|
|
242
|
+
setBigUint(view, 0, signature, false);
|
|
243
|
+
return padded;
|
|
244
|
+
}
|
|
249
245
|
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/daemon/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,YAAY,GACf,MAAM,qDAAqD,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACtB,QAAkB,EAClB,UAAkB,EAClB,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AC,CAAC;IAErE,gCAAgC;IAChC,wCAAwC;IACxC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Consumable, ReadableWritablePair } from "@yume-chan/stream-extra";
|
|
2
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
3
|
+
import type { AdbPacketData, AdbPacketInit } from "./packet.js";
|
|
4
|
+
export interface AdbDaemonDevice {
|
|
5
|
+
readonly serial: string;
|
|
6
|
+
readonly name: string | undefined;
|
|
7
|
+
connect(): ValueOrPromise<ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/daemon/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAElC,OAAO,IAAI,cAAc,CACrB,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CACjE,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../src/daemon/device.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Consumable, ReadableWritablePair } from "@yume-chan/stream-extra";
|
|
2
|
+
import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js";
|
|
3
|
+
import type { AdbPacketData, AdbPacketInit } from "./packet.js";
|
|
4
|
+
import { AdbCommand } from "./packet.js";
|
|
5
|
+
export interface AdbPacketDispatcherOptions {
|
|
6
|
+
calculateChecksum: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Before Android 9.0, ADB uses `char*` to parse service string,
|
|
9
|
+
* thus requires a null character to terminate.
|
|
10
|
+
*
|
|
11
|
+
* Usually it should have the same value as `calculateChecksum`.
|
|
12
|
+
*/
|
|
13
|
+
appendNullToServiceString: boolean;
|
|
14
|
+
maxPayloadSize: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The dispatcher is the "dumb" part of the connection handling logic.
|
|
18
|
+
*
|
|
19
|
+
* Except some options to change some minor behaviors,
|
|
20
|
+
* its only job is forwarding packets between authenticated underlying streams
|
|
21
|
+
* and abstracted socket objects.
|
|
22
|
+
*
|
|
23
|
+
* The `Adb` class is responsible for doing the authentication,
|
|
24
|
+
* negotiating the options, and has shortcuts to high-level services.
|
|
25
|
+
*/
|
|
26
|
+
export declare class AdbPacketDispatcher implements Closeable {
|
|
27
|
+
#private;
|
|
28
|
+
readonly options: AdbPacketDispatcherOptions;
|
|
29
|
+
get disconnected(): Promise<void>;
|
|
30
|
+
constructor(connection: ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>, options: AdbPacketDispatcherOptions);
|
|
31
|
+
private handleOk;
|
|
32
|
+
private handleClose;
|
|
33
|
+
addReverseTunnel(service: string, handler: AdbIncomingSocketHandler): void;
|
|
34
|
+
removeReverseTunnel(address: string): void;
|
|
35
|
+
clearReverseTunnels(): void;
|
|
36
|
+
private handleOpen;
|
|
37
|
+
createSocket(service: string): Promise<AdbSocket>;
|
|
38
|
+
sendPacket(command: AdbCommand, arg0: number, arg1: number, payload?: string | Uint8Array): Promise<void>;
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
private dispose;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