adb-sqlite-viewer 1.0.5 → 1.0.7
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/README.md +52 -117
- package/bridge/package.json +13 -0
- package/bridge/server.js +50 -0
- package/cli/ensure-adb.cjs +150 -0
- package/cli/server.cjs +7 -6
- package/dist/assets/{index-COoGrD16.js → index-CIcR1CkF.js} +6 -6
- package/dist/index.html +1 -1
- package/electron/main.cjs +9 -0
- package/package.json +11 -1
- package/sqlite3-arm64 +0 -0
package/README.md
CHANGED
|
@@ -1,151 +1,86 @@
|
|
|
1
|
-
# SQLite DevTools
|
|
1
|
+
# ADB SQLite DevTools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Inspect SQLite databases on Android devices. Browse tables, view schemas, and run SQL queries — all from your browser.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start (npm)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**Requirements:**
|
|
12
|
-
- Windows (NSIS installer)
|
|
13
|
-
- `adb` on your PATH (Android SDK Platform-Tools)
|
|
14
|
-
- Android device with USB debugging enabled
|
|
15
|
-
|
|
16
|
-
### Option 2: Hosted Version + ADB Bridge (Best for React Native Developers)
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev adb-sqlite-viewer
|
|
9
|
+
npx sqlite-viewer
|
|
10
|
+
```
|
|
17
11
|
|
|
18
|
-
|
|
12
|
+
Opens a local server at `http://127.0.0.1:8085` with the full UI and ADB bridge built in. One command, no extra downloads.
|
|
19
13
|
|
|
20
|
-
|
|
14
|
+
```bash
|
|
15
|
+
# Custom port
|
|
16
|
+
npx sqlite-viewer --port 3000
|
|
17
|
+
```
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
cd bridge
|
|
25
|
-
npm install
|
|
26
|
-
npm run build # produces adb-bridge.exe
|
|
27
|
-
```
|
|
19
|
+
**Requirements:** `adb` on your PATH ([Android SDK Platform-Tools](https://developer.android.com/tools/releases/platform-tools)) and a USB-connected Android device with debugging enabled.
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
# Either run the exe directly:
|
|
32
|
-
adb-bridge.exe
|
|
21
|
+
## All Options
|
|
33
22
|
|
|
34
|
-
|
|
35
|
-
cd bridge && node server.js
|
|
36
|
-
```
|
|
23
|
+
### npm Package (Recommended for dev workflows)
|
|
37
24
|
|
|
38
|
-
|
|
25
|
+
Install into any project and run alongside your app:
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Hosted website (HTTPS) ──HTTP──> localhost:15555 (bridge) ──> adb shell ──> Device
|
|
27
|
+
```bash
|
|
28
|
+
npm install --save-dev adb-sqlite-viewer
|
|
43
29
|
```
|
|
44
|
-
The website detects the bridge on startup and routes all commands through HTTP instead of WebUSB. No need to kill ADB.
|
|
45
|
-
|
|
46
|
-
### Option 3: Hosted Version with WebUSB (No Setup Required)
|
|
47
30
|
|
|
48
|
-
|
|
31
|
+
Add to your `package.json` scripts:
|
|
49
32
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"scripts": {
|
|
36
|
+
"sqlite-viewer": "sqlite-viewer"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
56
40
|
|
|
57
|
-
|
|
41
|
+
Then `npm run sqlite-viewer` opens the viewer. Works great alongside React Native, Flutter, or any Android project.
|
|
58
42
|
|
|
59
|
-
|
|
60
|
-
1. Run `adb kill-server` in your terminal
|
|
61
|
-
2. Open the hosted URL in Chrome/Edge
|
|
62
|
-
3. Click **Connect Device** and select your phone from the USB picker
|
|
63
|
-
4. Approve the USB debugging prompt on your phone (first time only)
|
|
64
|
-
5. Select a package and database, then start querying
|
|
43
|
+
### Desktop App
|
|
65
44
|
|
|
66
|
-
|
|
45
|
+
Download the Windows installer from [Releases](https://github.com/amitwinit/SQLite-DevTools-Mobile-ReactNative/releases). Double-click to launch — the bridge server starts automatically.
|
|
67
46
|
|
|
68
|
-
|
|
47
|
+
### Hosted Version + ADB Bridge
|
|
69
48
|
|
|
70
|
-
**
|
|
49
|
+
Use the deployed version at **[amitwinit.github.io/SQLite-DevTools-Mobile-ReactNative](https://amitwinit.github.io/SQLite-DevTools-Mobile-ReactNative/)** together with the standalone ADB Bridge.
|
|
71
50
|
|
|
72
|
-
1.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```
|
|
51
|
+
1. Download `adb-bridge.exe` from [Releases](https://github.com/amitwinit/SQLite-DevTools-Mobile-ReactNative/releases)
|
|
52
|
+
2. Run `adb-bridge.exe`
|
|
53
|
+
3. Open the hosted website — it auto-detects the bridge
|
|
76
54
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```
|
|
55
|
+
```
|
|
56
|
+
Website (HTTPS) ──HTTP──> localhost:15555 (bridge) ──> adb shell ──> Device
|
|
57
|
+
```
|
|
81
58
|
|
|
82
|
-
|
|
83
|
-
- `DEVICE_SERIAL` — run `adb devices` to find it
|
|
84
|
-
- `PACKAGE_NAME` — your app's package name
|
|
85
|
-
- `DB_NAME` — the SQLite database filename
|
|
86
|
-
- `PYTHON_TOOLS_PATH` — path to the python_tools directory
|
|
59
|
+
### Hosted Version with WebUSB (No install required)
|
|
87
60
|
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
python app.py
|
|
91
|
-
```
|
|
61
|
+
Open **[amitwinit.github.io/SQLite-DevTools-Mobile-ReactNative](https://amitwinit.github.io/SQLite-DevTools-Mobile-ReactNative/)** in Chrome/Edge. Uses WebUSB to talk directly to the device — no server needed.
|
|
92
62
|
|
|
93
|
-
|
|
63
|
+
**Note:** Requires `adb kill-server` first (WebUSB and ADB can't share the USB interface). Not suitable when you need ADB running for development.
|
|
94
64
|
|
|
95
65
|
## When to Use Which
|
|
96
66
|
|
|
97
|
-
| Scenario |
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
| Need ADB for other tools simultaneously | Desktop App (Option 1) or ADB Bridge (Option 2) |
|
|
104
|
-
|
|
105
|
-
## Environment Variables (Option 4)
|
|
106
|
-
|
|
107
|
-
### Application Configuration
|
|
108
|
-
- `PACKAGE_NAME`: Android app package name
|
|
109
|
-
- `DB_NAME`: Database name on the device
|
|
110
|
-
- `DEVICE_SERIAL`: ADB device serial number
|
|
111
|
-
- `PYTHON_TOOLS_PATH`: Path to python_tools directory
|
|
112
|
-
|
|
113
|
-
### Flask Server Configuration
|
|
114
|
-
- `FLASK_HOST`: Flask server host (default: 0.0.0.0)
|
|
115
|
-
- `FLASK_PORT`: Flask server port (default: 5001)
|
|
116
|
-
- `FLASK_DEBUG`: Enable debug mode (default: True)
|
|
117
|
-
|
|
118
|
-
### Cache Configuration
|
|
119
|
-
- `USE_CACHE`: Enable database caching (default: True)
|
|
120
|
-
- `FORCE_LOCAL`: Force local database operations (default: False)
|
|
67
|
+
| Scenario | Recommended |
|
|
68
|
+
|----------|-------------|
|
|
69
|
+
| Active development (React Native, Flutter, etc.) | `npx sqlite-viewer` or Desktop App |
|
|
70
|
+
| Quick one-off DB inspection | WebUSB (hosted version) |
|
|
71
|
+
| CI or shared dev environment | `npx sqlite-viewer` |
|
|
72
|
+
| No Node.js installed | Desktop App or WebUSB |
|
|
121
73
|
|
|
122
74
|
## Development
|
|
123
75
|
|
|
124
|
-
To work on the WebUSB frontend:
|
|
125
|
-
|
|
126
76
|
```bash
|
|
127
77
|
npm install
|
|
128
|
-
npm run dev
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
npm run build
|
|
78
|
+
npm run dev # Vite dev server
|
|
79
|
+
npm run build # Build for GitHub Pages
|
|
80
|
+
npm run electron:dev # Build + launch Electron app
|
|
81
|
+
npm run electron:build # Build Electron installer
|
|
135
82
|
```
|
|
136
83
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
To run the Electron desktop app in development:
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
npm run electron:dev
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
To build the Electron installer:
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
npm run electron:build
|
|
149
|
-
```
|
|
84
|
+
## License
|
|
150
85
|
|
|
151
|
-
|
|
86
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "adb-bridge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Localhost HTTP bridge that wraps adb shell commands for the SQLite DevTools website",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node server.js",
|
|
8
|
+
"build": "pkg server.js --target node20-win-x64 --output adb-bridge.exe"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@yao-pkg/pkg": "^5.11.0"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/bridge/server.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const http = require("http");
|
|
2
2
|
const { execFile, spawn } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
3
5
|
|
|
4
6
|
const TIMEOUT = 30_000;
|
|
5
7
|
const MAX_BUFFER = 10 * 1024 * 1024;
|
|
@@ -164,6 +166,51 @@ async function handleShell(req, res) {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
async function handlePushSqlite3(req, res) {
|
|
170
|
+
let body;
|
|
171
|
+
try {
|
|
172
|
+
body = JSON.parse(await readBody(req));
|
|
173
|
+
} catch {
|
|
174
|
+
body = {};
|
|
175
|
+
}
|
|
176
|
+
const { serial } = body;
|
|
177
|
+
|
|
178
|
+
// Locate bundled sqlite3-arm64 binary (check multiple locations)
|
|
179
|
+
const candidates = [
|
|
180
|
+
path.join(__dirname, "..", "sqlite3-arm64"), // npm package / dev
|
|
181
|
+
path.join(path.dirname(process.execPath), "sqlite3-arm64"), // next to pkg exe
|
|
182
|
+
];
|
|
183
|
+
const binaryPath = candidates.find((p) => fs.existsSync(p));
|
|
184
|
+
if (!binaryPath) {
|
|
185
|
+
json(res, 404, { error: "Bundled sqlite3-arm64 binary not found. Place it next to adb-bridge.exe." });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
// Push to /data/local/tmp/
|
|
191
|
+
const pushArgs = [];
|
|
192
|
+
if (serial) pushArgs.push("-s", serial);
|
|
193
|
+
pushArgs.push("push", binaryPath, "/data/local/tmp/sqlite3");
|
|
194
|
+
await adb(pushArgs);
|
|
195
|
+
|
|
196
|
+
// Make executable
|
|
197
|
+
const chmodArgs = [];
|
|
198
|
+
if (serial) chmodArgs.push("-s", serial);
|
|
199
|
+
chmodArgs.push("shell", "chmod", "755", "/data/local/tmp/sqlite3");
|
|
200
|
+
await adb(chmodArgs);
|
|
201
|
+
|
|
202
|
+
// Verify
|
|
203
|
+
const verifyArgs = [];
|
|
204
|
+
if (serial) verifyArgs.push("-s", serial);
|
|
205
|
+
verifyArgs.push("shell", "/data/local/tmp/sqlite3", "-version");
|
|
206
|
+
const version = await adb(verifyArgs);
|
|
207
|
+
|
|
208
|
+
json(res, 200, { ok: true, version: version.trim() });
|
|
209
|
+
} catch (err) {
|
|
210
|
+
json(res, 500, { error: err.message });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
167
214
|
// ── Exports (for use by cli/server.cjs and electron) ───
|
|
168
215
|
|
|
169
216
|
/**
|
|
@@ -191,6 +238,9 @@ async function handleRequest(req, res) {
|
|
|
191
238
|
} else if (p === "/api/shell" && req.method === "POST") {
|
|
192
239
|
await handleShell(req, res);
|
|
193
240
|
return true;
|
|
241
|
+
} else if (p === "/api/push-sqlite3" && req.method === "POST") {
|
|
242
|
+
await handlePushSqlite3(req, res);
|
|
243
|
+
return true;
|
|
194
244
|
}
|
|
195
245
|
} catch (err) {
|
|
196
246
|
json(res, 500, { error: err.message });
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { execFile } = require("child_process");
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
|
|
9
|
+
const CACHE_DIR = path.join(os.homedir(), ".adb-sqlite-viewer");
|
|
10
|
+
const PLATFORM_TOOLS_DIR = path.join(CACHE_DIR, "platform-tools");
|
|
11
|
+
|
|
12
|
+
const DOWNLOAD_URLS = {
|
|
13
|
+
win32: "https://dl.google.com/android/repository/platform-tools-latest-windows.zip",
|
|
14
|
+
darwin: "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip",
|
|
15
|
+
linux: "https://dl.google.com/android/repository/platform-tools-latest-linux.zip",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ADB_BIN = process.platform === "win32" ? "adb.exe" : "adb";
|
|
19
|
+
|
|
20
|
+
/** Check if adb works at the given path. Returns version string or null. */
|
|
21
|
+
function tryAdb(adbPath) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
execFile(adbPath, ["version"], { timeout: 5000 }, (err, stdout) => {
|
|
24
|
+
if (err) return resolve(null);
|
|
25
|
+
resolve(stdout.split("\n")[0].trim());
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Download a file via HTTPS, following redirects. */
|
|
31
|
+
function download(url, dest) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const file = fs.createWriteStream(dest);
|
|
34
|
+
const request = (u) => {
|
|
35
|
+
https.get(u, (res) => {
|
|
36
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
37
|
+
file.close();
|
|
38
|
+
request(res.headers.location);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (res.statusCode !== 200) {
|
|
42
|
+
file.close();
|
|
43
|
+
fs.unlinkSync(dest);
|
|
44
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const total = parseInt(res.headers["content-length"], 10) || 0;
|
|
48
|
+
let downloaded = 0;
|
|
49
|
+
res.on("data", (chunk) => {
|
|
50
|
+
downloaded += chunk.length;
|
|
51
|
+
if (total > 0) {
|
|
52
|
+
const pct = Math.round((downloaded / total) * 100);
|
|
53
|
+
process.stdout.write(`\r Downloading... ${pct}%`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
res.pipe(file);
|
|
57
|
+
file.on("finish", () => {
|
|
58
|
+
file.close();
|
|
59
|
+
if (total > 0) process.stdout.write("\n");
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
}).on("error", (err) => {
|
|
63
|
+
file.close();
|
|
64
|
+
fs.unlinkSync(dest);
|
|
65
|
+
reject(err);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
request(url);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Extract a zip file using OS tools. */
|
|
73
|
+
function extractZip(zipPath, destDir) {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const cmd = process.platform === "win32"
|
|
76
|
+
? `tar -xf "${zipPath}" -C "${destDir}"`
|
|
77
|
+
: `unzip -q -o "${zipPath}" -d "${destDir}"`;
|
|
78
|
+
execFile(cmd.split(" ")[0], cmd.split(" ").slice(1), { shell: true, timeout: 60000 }, (err) => {
|
|
79
|
+
if (err) reject(new Error(`Extract failed: ${err.message}`));
|
|
80
|
+
else resolve();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Ensure adb is available. Checks PATH, then cached download, then downloads.
|
|
87
|
+
* Prepends the adb directory to process.env.PATH if needed.
|
|
88
|
+
* Returns the adb version string.
|
|
89
|
+
*/
|
|
90
|
+
async function ensureAdb() {
|
|
91
|
+
// 1. Check system PATH
|
|
92
|
+
const systemVersion = await tryAdb("adb");
|
|
93
|
+
if (systemVersion) {
|
|
94
|
+
return systemVersion;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 2. Check cached download
|
|
98
|
+
const cachedAdb = path.join(PLATFORM_TOOLS_DIR, ADB_BIN);
|
|
99
|
+
if (fs.existsSync(cachedAdb)) {
|
|
100
|
+
const cachedVersion = await tryAdb(cachedAdb);
|
|
101
|
+
if (cachedVersion) {
|
|
102
|
+
prependToPath(PLATFORM_TOOLS_DIR);
|
|
103
|
+
return cachedVersion;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 3. Download from Google
|
|
108
|
+
const url = DOWNLOAD_URLS[process.platform];
|
|
109
|
+
if (!url) {
|
|
110
|
+
throw new Error(`Unsupported platform: ${process.platform}. Install adb manually.`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log(" adb not found. Downloading Android Platform-Tools...");
|
|
114
|
+
|
|
115
|
+
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
116
|
+
const zipPath = path.join(CACHE_DIR, "platform-tools.zip");
|
|
117
|
+
|
|
118
|
+
await download(url, zipPath);
|
|
119
|
+
console.log(" Extracting...");
|
|
120
|
+
await extractZip(zipPath, CACHE_DIR);
|
|
121
|
+
|
|
122
|
+
// Clean up zip
|
|
123
|
+
try { fs.unlinkSync(zipPath); } catch {}
|
|
124
|
+
|
|
125
|
+
// Verify
|
|
126
|
+
if (!fs.existsSync(cachedAdb)) {
|
|
127
|
+
throw new Error("Download succeeded but adb binary not found in extracted files.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Make executable on Unix
|
|
131
|
+
if (process.platform !== "win32") {
|
|
132
|
+
fs.chmodSync(cachedAdb, 0o755);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const version = await tryAdb(cachedAdb);
|
|
136
|
+
if (!version) {
|
|
137
|
+
throw new Error("Downloaded adb binary is not working.");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
prependToPath(PLATFORM_TOOLS_DIR);
|
|
141
|
+
console.log(` Downloaded: ${version}`);
|
|
142
|
+
return version;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function prependToPath(dir) {
|
|
146
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
147
|
+
process.env.PATH = dir + sep + (process.env.PATH || "");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
module.exports = { ensureAdb };
|
package/cli/server.cjs
CHANGED
|
@@ -4,7 +4,8 @@ const http = require("http");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const { exec } = require("child_process");
|
|
7
|
-
const { handleRequest: bridgeHandler
|
|
7
|
+
const { handleRequest: bridgeHandler } = require("../bridge/server.js");
|
|
8
|
+
const { ensureAdb } = require("./ensure-adb.cjs");
|
|
8
9
|
|
|
9
10
|
const DIST_DIR = path.join(__dirname, "..", "dist");
|
|
10
11
|
|
|
@@ -86,13 +87,13 @@ async function start(port) {
|
|
|
86
87
|
process.exit(1);
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
//
|
|
90
|
+
// Ensure adb is available (downloads if needed)
|
|
90
91
|
try {
|
|
91
|
-
const version = await
|
|
92
|
-
console.log(`
|
|
92
|
+
const version = await ensureAdb();
|
|
93
|
+
console.log(` adb: ${version}`);
|
|
93
94
|
} catch (err) {
|
|
94
|
-
console.warn(`WARNING: ${err.message}`);
|
|
95
|
-
console.warn("ADB bridge features will not work.");
|
|
95
|
+
console.warn(` WARNING: ${err.message}`);
|
|
96
|
+
console.warn(" ADB bridge features will not work.");
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
const server = http.createServer(requestHandler);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var Ai=Object.defineProperty;var Os=n=>{throw TypeError(n)};var Ui=(n,e,t)=>e in n?Ai(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var g=(n,e,t)=>Ui(n,typeof e!="symbol"?e+"":e,t),Vn=(n,e,t)=>e.has(n)||Os("Cannot "+t);var a=(n,e,t)=>(Vn(n,e,"read from private field"),t?t.call(n):e.get(n)),l=(n,e,t)=>e.has(n)?Os("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),u=(n,e,t,s)=>(Vn(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),y=(n,e,t)=>(Vn(n,e,"access private method"),t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(i){if(i.ep)return;i.ep=!0;const r=t(i);fetch(i.href,r)}})();class ys{constructor(e){g(this,"TValue");g(this,"TOmitInitKey");g(this,"options");this.options=e}}class Me{constructor(e,t,s,i){g(this,"definition");g(this,"options");g(this,"struct");g(this,"value");this.definition=e,this.options=t,this.struct=s,this.value=i}get hasCustomAccessors(){return this.get!==Me.prototype.get||this.set!==Me.prototype.set}getSize(){return this.definition.getSize()}get(){return this.value}set(e){this.value=e}}const Mi={littleEndian:!1};class ms extends Error{constructor(){super("ExactReadable ended"),Object.setPrototypeOf(this,new.target.prototype)}}const bs=Symbol("struct-value");function Wi(n){return typeof n=="object"&&n!==null&&bs in n}class Rs{constructor(e){g(this,"fieldValues",{});g(this,"value");this.value=Object.create(e),Object.defineProperty(this.value,bs,{enumerable:!1,value:this})}set(e,t){this.fieldValues[e]=t,t.hasCustomAccessors?Object.defineProperty(this.value,e,{configurable:!0,enumerable:!0,get(){return t.get()},set(s){t.set(s)}}):this.value[e]=t.get()}get(e){return this.fieldValues[e]}}const re={reject(n){return new _s(n)},resolve(n){return typeof n=="object"&&n!==null&&typeof n.then=="function"?n instanceof fn||n instanceof qs||n instanceof _s?n:new fn(n):new qs(n)},try(n){try{return re.resolve(n())}catch(e){return re.reject(e)}}};var Ge;const Ds=class Ds{constructor(e){l(this,Ge);u(this,Ge,e)}then(e,t){return new Ds(a(this,Ge).then(e,t))}valueOrPromise(){return a(this,Ge)}};Ge=new WeakMap;let fn=Ds;var Ye;class qs{constructor(e){l(this,Ye);u(this,Ye,e)}then(e){return e?re.try(()=>e(a(this,Ye))):this}valueOrPromise(){return a(this,Ye)}}Ye=new WeakMap;var Je;class _s{constructor(e){l(this,Je);u(this,Je,e)}then(e,t){return t?re.try(()=>t(a(this,Je))):this}valueOrPromise(){throw a(this,Je)}}Je=new WeakMap;function Vi(n,e,t){return t?(n[e]|n[e+1]<<8)<<16>>16:(n[e]<<8|n[e+1])<<16>>16}function Fi(n,e,t){return t?n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24:n[e]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3]}function ji(n,e,t){return t?BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7]<<24)<<32n:BigInt(n[e]<<24)<<32n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function Hi(n,e,t){n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)}function Ki(n,e,t){n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn)}function Qi(n,e,t,s){s?(n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)):(n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn))}function Gi(n,e){return n[e]<<24>>24}function Yi(n,e,t){return t?n[e]|n[e+1]<<8:n[e+1]|n[e]<<8}function Un(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0}function Ji(n,e,t){return t?(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0:(n[e]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3])>>>0}function Xi(n,e,t){n[e]=t,n[e+1]=t>>8,n[e+2]=t>>16,n[e+3]=t>>24}function Zi(n,e){return BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7])<<56n}function er(n,e){return BigInt(n[e])<<56n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function tr(n,e,t){return t?BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7])<<56n:BigInt(n[e])<<56n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function nr(n,e,t,s){s?(n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)):(n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn))}const Ke=class Ke{constructor(e,t,s){g(this,"TTypeScriptType");g(this,"size");g(this,"deserialize");g(this,"serialize");this.size=e,this.deserialize=t,this.serialize=s}};g(Ke,"Int64",new Ke(8,ji,Qi)),g(Ke,"Uint64",new Ke(8,tr,nr));let yn=Ke;class sr extends ys{constructor(t,s){super();g(this,"variant");this.variant=t}getSize(){return this.variant.size}create(t,s,i){return new ir(this,t,s,i)}deserialize(t,s,i){return re.try(()=>s.readExactly(this.getSize())).then(r=>{const o=this.variant.deserialize(r,0,t.littleEndian);return this.create(t,i,o)}).valueOrPromise()}}class ir extends Me{serialize(e,t,s){this.definition.variant.serialize(t,s,this.value,this.options.littleEndian)}}const{TextEncoder:rr,TextDecoder:ar}=globalThis,or=new rr,cr=new ar;function Y(n){return or.encode(n)}function We(n){return cr.decode(n)}class ti{constructor(){g(this,"TTypeScriptType")}}const Dn=class Dn extends ti{constructor(){super()}toBuffer(e){return e}toValue(e){return e}getSize(e){return e.length}};g(Dn,"Instance",new Dn);let Kn=Dn;const Pn=class Pn extends ti{toBuffer(e){return Y(e)}toValue(e){return We(e)}getSize(){}};g(Pn,"Instance",new Pn);let Qn=Pn;const Q=new Uint8Array(0);class ni extends ys{constructor(t,s){super(s);g(this,"converter");g(this,"TTypeScriptType");this.converter=t}getDeserializeSize(t){return this.getSize()}create(t,s,i,r){return new si(this,t,s,i,r)}deserialize(t,s,i){return re.try(()=>{const r=this.getDeserializeSize(i);return r===0?Q:s.readExactly(r)}).then(r=>{const o=this.converter.toValue(r);return this.create(t,i,o,r)}).valueOrPromise()}}class si extends Me{constructor(t,s,i,r,o){super(t,s,i,r);g(this,"array");this.array=o}set(t){super.set(t),this.array=void 0}serialize(t,s,i){this.array??(this.array=this.definition.converter.toBuffer(this.value)),s.set(this.array,i)}}class lr extends ni{getSize(){return this.options.length}}class ur extends ni{getSize(){return 0}getDeserializeSize(e){let t=e.value[this.options.lengthField];return typeof t=="string"&&(t=Number.parseInt(t,this.options.lengthFieldRadix??10)),t}create(e,t,s,i){return new hr(this,e,t,s,i)}}var Cn,ii;class hr extends si{constructor(t,s,i,r,o){super(t,s,i,r,o);l(this,Cn);g(this,"length");g(this,"lengthFieldValue");o&&(this.length=o.length);const c=this.definition.options.lengthField,w=i.get(c);this.lengthFieldValue=new dr(w,this),i.set(c,this.lengthFieldValue)}getSize(){return this.length===void 0&&(this.length=y(this,Cn,ii).call(this)),this.length===void 0&&(this.array=this.definition.converter.toBuffer(this.value),this.length=this.array.length),this.length}set(t){super.set(t),this.array=void 0,this.length=void 0}}Cn=new WeakSet,ii=function(){const t=this.definition.converter.getSize(this.value);if(t!==void 0&&t<0)throw new Error("Invalid length");return t};class dr extends Me{constructor(t,s){super(t.definition,t.options,t.struct,0);g(this,"originalValue");g(this,"bufferValue");this.originalValue=t,this.bufferValue=s}getSize(){return this.originalValue.getSize()}get(){let t=this.bufferValue.getSize();return typeof this.originalValue.get()=="string"&&(t=t.toString(this.bufferValue.definition.options.lengthFieldRadix??10)),t}set(){}serialize(t,s,i){this.originalValue.set(this.get()),this.originalValue.serialize(t,s,i)}}var ae;(function(n){n.Uint8={signed:!1,size:1,deserialize(e){return e[0]},serialize(e,t,s){e.setUint8(t,s)}},n.Int8={signed:!0,size:1,deserialize(e){return Gi(e,0)},serialize(e,t,s){e.setInt8(t,s)}},n.Uint16={signed:!1,size:2,deserialize(e,t){return Yi(e,0,t)},serialize(e,t,s,i){e.setUint16(t,s,i)}},n.Int16={signed:!0,size:2,deserialize(e,t){return Vi(e,0,t)},serialize(e,t,s,i){e.setInt16(t,s,i)}},n.Uint32={signed:!1,size:4,deserialize(e,t){return Ji(e,0,t)},serialize(e,t,s,i){e.setUint32(t,s,i)}},n.Int32={signed:!0,size:4,deserialize(e,t){return Fi(e,0,t)},serialize(e,t,s,i){e.setInt32(t,s,i)}}})(ae||(ae={}));class wr extends ys{constructor(t,s){super();g(this,"variant");this.variant=t}getSize(){return this.variant.size}create(t,s,i){return new gr(this,t,s,i)}deserialize(t,s,i){return re.try(()=>s.readExactly(this.getSize())).then(r=>{const o=this.variant.deserialize(r,t.littleEndian);return this.create(t,i,o)}).valueOrPromise()}}class gr extends Me{serialize(e,t,s){this.definition.variant.serialize(e,s,this.value,this.options.littleEndian)}}class ri extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class pr extends ri{constructor(){super("The underlying readable was ended before the struct was fully deserialized")}}class vs extends ri{constructor(){super("The underlying readable doesn't contain any more struct")}}var Se,W,xe,Xe,A,me,Gn,pt;const Ps=class Ps{constructor(e){l(this,A);g(this,"TFields");g(this,"TOmitInitKey");g(this,"TExtra");g(this,"TInit");g(this,"TDeserializeResult");g(this,"options");l(this,Se,0);l(this,W,[]);l(this,xe,{});l(this,Xe);l(this,pt,(e,t,s)=>"length"in s?this.field(e,new lr(t,s)):this.field(e,new ur(t,s)));g(this,"uint8Array",(e,t,s)=>a(this,pt).call(this,e,Kn.Instance,t,s));g(this,"string",(e,t,s)=>a(this,pt).call(this,e,Qn.Instance,t,s));this.options={...Mi,...e}}get size(){return a(this,Se)}get fields(){return a(this,W)}field(e,t){for(const i of a(this,W))if(i[0]===e){const r=String(e);throw new Error(`This struct already have a field with name '${r}'`)}a(this,W).push([e,t]);const s=t.getSize();return u(this,Se,a(this,Se)+s),this}concat(e){if(!(e instanceof Ps))throw new TypeError("The other value must be a `Struct` instance");for(const t of a(e,W))a(this,W).push(t);return u(this,Se,a(this,Se)+a(e,Se)),Object.defineProperties(a(this,xe),Object.getOwnPropertyDescriptors(a(e,xe))),this}int8(e,t){return y(this,A,me).call(this,e,ae.Int8,t)}uint8(e,t){return y(this,A,me).call(this,e,ae.Uint8,t)}int16(e,t){return y(this,A,me).call(this,e,ae.Int16,t)}uint16(e,t){return y(this,A,me).call(this,e,ae.Uint16,t)}int32(e,t){return y(this,A,me).call(this,e,ae.Int32,t)}uint32(e,t){return y(this,A,me).call(this,e,ae.Uint32,t)}int64(e,t){return y(this,A,Gn).call(this,e,yn.Int64,t)}uint64(e,t){return y(this,A,Gn).call(this,e,yn.Uint64,t)}extra(e){return Object.defineProperties(a(this,xe),Object.getOwnPropertyDescriptors(e)),this}postDeserialize(e){return u(this,Xe,e),this}deserialize(e){const t=new Rs(a(this,xe));let s=re.resolve();const i=e.position;for(const[r,o]of a(this,W))s=s.then(()=>o.deserialize(this.options,e,t)).then(c=>{t.set(r,c)},c=>{throw c instanceof ms?e.position===i?new vs:new pr:c});return s.then(()=>{const r=t.value;if(a(this,Xe)){const o=a(this,Xe).call(r,r);if(o!==void 0)return o}return r}).valueOrPromise()}serialize(e,t){let s;if(Wi(e)){s=e[bs];for(const[w,d]of Object.entries(e)){const p=s.get(w);p&&p.set(d)}}else{s=new Rs({});for(const[w,d]of a(this,W)){const p=d.create(this.options,s,e[w]);s.set(w,p)}}let i=0;const r=[];for(const[w]of a(this,W)){const d=s.get(w),p=d.getSize();r.push({fieldValue:d,size:p}),i+=p}if(!t)t=new Uint8Array(i);else if(t.length<i)throw new TypeError("Output buffer is too small");const o=new DataView(t.buffer,t.byteOffset,t.byteLength);let c=0;for(const{fieldValue:w,size:d}of r)w.serialize(o,t,c),c+=d;return t.length!==i?t.subarray(0,i):t}};Se=new WeakMap,W=new WeakMap,xe=new WeakMap,Xe=new WeakMap,A=new WeakSet,me=function(e,t,s){return this.field(e,new wr(t,s))},Gn=function(e,t,s){return this.field(e,new sr(t,s))},pt=new WeakMap;let x=Ps;var P=(function(){function n(){var e=this;this._state="running",this.resolve=function(t){e._resolve(t),e._state="resolved"},this.reject=function(t){e._reject(t),e._state="rejected"},this._promise=new Promise(function(t,s){e._resolve=t,e._reject=s})}return Object.defineProperty(n.prototype,"promise",{get:function(){return this._promise},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n})(),fr=(function(){function n(e){e===void 0&&(e=0),this.pendingResolvers=new Map,this.nextId=e}return n.prototype.add=function(){var e=this.nextId++,t=new P;return this.pendingResolvers.set(e,t),[e,t.promise]},n.prototype.getResolver=function(e){if(!this.pendingResolvers.has(e))return null;var t=this.pendingResolvers.get(e);return this.pendingResolvers.delete(e),t},n.prototype.resolve=function(e,t){var s=this.getResolver(e);return s!==null?(s.resolve(t),!0):!1},n.prototype.reject=function(e,t){var s=this.getResolver(e);return s!==null?(s.reject(t),!0):!1},n})();function yr(n){return new Promise(function(e){globalThis.setTimeout(function(){return e()},n)})}const Mn=globalThis,hn=Mn.AbortController,Ve=Mn.ReadableStream,J=Mn.WritableStream,Es=Mn.TransformStream;var Ze;class dt extends Ve{constructor(t,s){let i;const r=new hn;super({start:async o=>{await Promise.resolve();const c=t({abortSignal:r.signal,enqueue:async w=>{if(r.signal.aborted)throw r.signal.reason;if(o.desiredSize===null){o.enqueue(w);return}if(a(this,Ze)){u(this,Ze,!1),o.enqueue(w);return}o.desiredSize<=0&&(i=new P,await i.promise),o.enqueue(w)},close(){o.close()},error(w){o.error(w)}});c&&"then"in c&&c.then(()=>{try{o.close()}catch{}},w=>{o.error(w)})},pull:()=>{if(i){i.resolve();return}(s==null?void 0:s.highWaterMark)===0&&u(this,Ze,!0)},cancel:o=>{r.abort(o),i==null||i.reject(o)}},s);l(this,Ze,!1)}}Ze=new WeakMap;const mr=()=>{};var X,Z,ee,R,fe,Yn,Jn;class dn{constructor(e){l(this,fe);l(this,X);l(this,Z,0);l(this,ee,0);l(this,R,0);g(this,"stream");g(this,"reader");this.stream=e,this.reader=e.getReader()}get position(){return a(this,R)}readExactly(e){if(a(this,X)){const t=a(this,X),s=a(this,Z);return a(this,ee)>e?(u(this,Z,a(this,Z)+e),u(this,ee,a(this,ee)-e),u(this,R,a(this,R)+e),t.subarray(s,s+e)):(u(this,X,void 0),u(this,ee,0),u(this,Z,0),u(this,R,a(this,R)+(t.length-s)),y(this,fe,Jn).call(this,e,t.subarray(s)))}return y(this,fe,Jn).call(this,e)}release(){return a(this,ee)>0?new dt(async e=>{const t=a(this,X).subarray(a(this,Z));for(await e.enqueue(t),e.abortSignal.addEventListener("abort",()=>{this.reader.cancel().catch(mr)});;){const{done:s,value:i}=await this.reader.read();if(s)return;await e.enqueue(i)}}):(this.reader.releaseLock(),this.stream)}async cancel(e){await this.reader.cancel(e)}}X=new WeakMap,Z=new WeakMap,ee=new WeakMap,R=new WeakMap,fe=new WeakSet,Yn=async function(){const{done:e,value:t}=await this.reader.read();if(e)throw new ms;return t},Jn=async function(e,t){let s,i;if(t)s=new Uint8Array(e),s.set(t),i=t.length,e-=t.length;else{const r=await y(this,fe,Yn).call(this);if(r.length===e)return u(this,R,a(this,R)+e),r;if(r.length>e)return u(this,X,r),u(this,Z,e),u(this,ee,r.length-e),u(this,R,a(this,R)+e),r.subarray(0,e);s=new Uint8Array(e),s.set(r),i=r.length,e-=r.length,u(this,R,a(this,R)+r.length)}for(;e>0;){const r=await y(this,fe,Yn).call(this);if(r.length===e)return s.set(r,i),u(this,R,a(this,R)+e),s;if(r.length>e)return u(this,X,r),u(this,Z,e),u(this,ee,r.length-e),s.set(r.subarray(0,e),i),u(this,R,a(this,R)+e),s;s.set(r,i),i+=r.length,e-=r.length,u(this,R,a(this,R)+r.length)}return s};var ft,yt;class br{constructor(e){l(this,ft);l(this,yt);let t;const s=new dn(new dt(i=>{t=i}));u(this,ft,new Ve({async pull(i){try{const r=await e(s);i.enqueue(r)}catch(r){if(r instanceof vs){i.close();return}throw r}},cancel:i=>s.cancel(i)})),u(this,yt,new J({async write(i){await t.enqueue(i)},abort(){t.close()},close(){t.close()}}))}get readable(){return a(this,ft)}get writable(){return a(this,yt)}}ft=new WeakMap,yt=new WeakMap;var et,V,Nn,Le,mt;class Xn{constructor(){l(this,et,"");l(this,V,new P);l(this,Nn,new J({write:e=>{u(this,et,a(this,et)+e)},close:()=>{a(this,V).resolve(a(this,et)),a(this,Le).enqueue(a(this,et)),a(this,Le).close()},abort:e=>{a(this,V).reject(e),a(this,Le).error(e)}}));l(this,Le);l(this,mt,new Ve({start:e=>{u(this,Le,e)}}));Object.defineProperties(a(this,mt),{then:{get:()=>a(this,V).promise.then.bind(a(this,V).promise)},catch:{get:()=>a(this,V).promise.catch.bind(a(this,V).promise)},finally:{get:()=>a(this,V).promise.finally.bind(a(this,V).promise)}})}get writable(){return a(this,Nn)}get readable(){return a(this,mt)}}et=new WeakMap,V=new WeakMap,Nn=new WeakMap,Le=new WeakMap,mt=new WeakMap;const{console:pn}=globalThis;var ei;const vr=((ei=pn==null?void 0:pn.createTask)==null?void 0:ei.bind(pn))??(()=>({run(n){return n()}}));function Er(n){return typeof n=="object"&&n!==null&&"then"in n}var bt,F;class M{constructor(e){l(this,bt);l(this,F);g(this,"value");g(this,"consumed");u(this,bt,vr("Consumable")),this.value=e,u(this,F,new P),this.consumed=a(this,F).promise}consume(){a(this,F).resolve()}error(e){a(this,F).reject(e)}tryConsume(e){try{let t=a(this,bt).run(()=>e(this.value));return Er(t)?t=t.then(s=>(a(this,F).resolve(),s),s=>{throw a(this,F).reject(s),s}):a(this,F).resolve(),t}catch(t){throw a(this,F).reject(t),t}}}bt=new WeakMap,F=new WeakMap;(function(n){class e extends J{static async write(i,r){const o=new n(r);await i.write(o),await o.consumed}constructor(i,r){let o;r&&(o={},"highWaterMark"in r&&(o.highWaterMark=r.highWaterMark),"size"in r&&(o.size=c=>r.size(c instanceof n?c.value:c))),super({start(c){var w;return(w=i.start)==null?void 0:w.call(i,c)},async write(c,w){await c.tryConsume(d=>{var p;return(p=i.write)==null?void 0:p.call(i,d,w)})},abort(c){var w;return(w=i.abort)==null?void 0:w.call(i,c)},close(){var c;return(c=i.close)==null?void 0:c.call(i)}},o)}}n.WritableStream=e;class t extends Ve{static async enqueue(i,r){const o=new n(r);i.enqueue(o),await o.consumed}constructor(i,r){let o,c;r&&(c={},"highWaterMark"in r&&(c.highWaterMark=r.highWaterMark),"size"in r&&(c.size=w=>r.size(w.value))),super({async start(w){var d;o={async enqueue(p){await t.enqueue(w,p)},close(){w.close()},error(p){w.error(p)}},await((d=i.start)==null?void 0:d.call(i,o))},async pull(){var w;await((w=i.pull)==null?void 0:w.call(i,o))},async cancel(w){var d;await((d=i.cancel)==null?void 0:d.call(i,w))}},c)}}n.ReadableStream=t})(M||(M={}));var pe;(function(n){function e(r){return r instanceof M?r.value:r}n.getValue=e;function t(r,o){return r instanceof M?r.tryConsume(o):o(r)}n.tryConsume=t;class s extends Es{constructor(){super({transform(o,c){n.tryConsume(o,w=>{c.enqueue(w)})}})}}n.UnwrapStream=s;class i extends J{constructor(o,c){let w;c&&(w={},"highWaterMark"in c&&(w.highWaterMark=c.highWaterMark),"size"in c&&(w.size=d=>c.size(d instanceof M?d.value:d))),super({start(d){var p;return(p=o.start)==null?void 0:p.call(o,d)},async write(d,p){await n.tryConsume(d,b=>{var E;return(E=o.write)==null?void 0:E.call(o,b,p)})},abort(d){var p;return(p=o.abort)==null?void 0:p.call(o,d)},close(){var d;return(d=o.close)==null?void 0:d.call(o)}},w)}}n.WritableStream=i})(pe||(pe={}));var te,ne,C,q;class ai{constructor(e){l(this,te);l(this,ne);l(this,C);l(this,q);u(this,te,e),u(this,ne,new Uint8Array(e)),u(this,C,0),u(this,q,e)}*push(e){let t=0,s=e.length;if(a(this,C)!==0)if(s>=a(this,q)){if(a(this,ne).set(e.subarray(0,a(this,q)),a(this,C)),t+=a(this,q),s-=a(this,q),yield a(this,ne),u(this,C,0),u(this,q,a(this,te)),s===0)return}else{a(this,ne).set(e,a(this,C)),u(this,C,a(this,C)+s),u(this,q,a(this,q)-s);return}for(;s>=a(this,te);){const i=t+a(this,te);yield e.subarray(t,i),t=i,s-=a(this,te)}s>0&&(a(this,ne).set(e.subarray(t),a(this,C)),u(this,C,a(this,C)+s),u(this,q,a(this,q)-s))}flush(){if(a(this,C)===0)return;const e=a(this,ne).subarray(0,a(this,C));return u(this,C,0),u(this,q,a(this,te)),e}}te=new WeakMap,ne=new WeakMap,C=new WeakMap,q=new WeakMap;class Sr extends Es{constructor(e,t=!1){const s=t?new ai(e):void 0;super({async transform(i,r){await pe.tryConsume(i,async o=>{if(s)for(const c of s.push(o))await M.ReadableStream.enqueue(r,c);else{let c=0,w=o.length;for(;w>0;){const d=c+e;await M.ReadableStream.enqueue(r,o.subarray(c,d)),c=d,w-=e}}})},flush(i){if(s){const r=s.flush();r&&i.enqueue(r)}}})}}function xr(n,e){return"start"in n?n.start(e):typeof n=="function"?n(e):n}var tt;class Lr extends Ve{constructor(t,s){super({start:async i=>{await Promise.resolve(),this.readable=await xr(t,i),u(this,tt,this.readable.getReader())},pull:async i=>{var o;const r=await a(this,tt).read();r.done?(i.close(),"close"in t&&await((o=t.close)==null?void 0:o.call(t))):i.enqueue(r.value)},cancel:async i=>{var r;await a(this,tt).cancel(i),"cancel"in t&&await((r=t.cancel)==null?void 0:r.call(t,i))}},s);g(this,"readable");l(this,tt)}}tt=new WeakMap;const As=()=>{};var vt,Et,ke,St,nt;class kr{constructor(e){l(this,vt,[]);l(this,Et,[]);l(this,ke,!1);l(this,St,new P);l(this,nt);u(this,nt,e??{})}get writableClosed(){return a(this,ke)}get closed(){return a(this,St).promise}wrapReadable(e,t){return new Lr({start:s=>(a(this,vt).push(s),e),cancel:async()=>{await this.close()},close:async()=>{await this.dispose()}},t)}createWritable(e){const t=e.getWriter();return a(this,Et).push(t),new J({write:async s=>{await t.write(s)},abort:async s=>{await t.abort(s),await this.close()},close:async()=>{await t.close().catch(As),await this.close()}})}async close(){var e,t;if(!a(this,ke)){u(this,ke,!0),await((t=(e=a(this,nt)).close)==null?void 0:t.call(e))!==!1&&await this.dispose();for(const s of a(this,Et))s.close().catch(As)}}async dispose(){var e,t;u(this,ke,!0),a(this,St).resolve();for(const s of a(this,vt))try{s.close()}catch{}await((t=(e=a(this,nt)).dispose)==null?void 0:t.call(e))}}vt=new WeakMap,Et=new WeakMap,ke=new WeakMap,St=new WeakMap,nt=new WeakMap;const Tr=globalThis,Zn=Tr.TextDecoderStream;function Ir(n,e){const t=e.writable.getWriter(),s=e.readable.pipeTo(n);return new J({async write(i){await t.write(i)},async close(){await t.close(),await s}})}class Dr extends br{constructor(e){super(t=>e.deserialize(t))}}async function Pr(n){return"start"in n?await n.start():typeof n=="function"?await n():n}var Te;const Cs=class Cs extends J{constructor(t){super({start:async()=>{await Promise.resolve(),this.writable=await Pr(t),u(this,Te,this.writable.getWriter())},write:async s=>{await a(this,Te).write(s)},abort:async s=>{var i;await a(this,Te).abort(s),t!==this.writable&&"close"in t&&await((i=t.close)==null?void 0:i.call(t))},close:async()=>{var s;await a(this,Te).close(),t!==this.writable&&"close"in t&&await((s=t.close)==null?void 0:s.call(t))}});g(this,"writable");l(this,Te)}bePipedThroughFrom(t){let s;return new Cs({start:()=>(s=t.readable.pipeTo(this),t.writable),async close(){await s}})}};Te=new WeakMap;let es=Cs;var st;class Ss{constructor(){l(this,st,[]);this.dispose=this.dispose.bind(this)}addDisposable(e){return a(this,st).push(e),e}dispose(){for(const e of a(this,st))e.dispose();u(this,st,[])}}st=new WeakMap;class xs extends Ss{constructor(t){super();g(this,"adb");this.adb=t}}const Cr=new x({littleEndian:!0}).uint32("version"),Nr=new x({littleEndian:!0}).uint32("bpp").uint32("size").uint32("width").uint32("height").uint32("red_offset").uint32("red_length").uint32("blue_offset").uint32("blue_length").uint32("green_offset").uint32("green_length").uint32("alpha_offset").uint32("alpha_length").uint8Array("data",{lengthField:"size"}),Br=new x({littleEndian:!0}).uint32("bpp").uint32("colorSpace").uint32("size").uint32("width").uint32("height").uint32("red_offset").uint32("red_length").uint32("blue_offset").uint32("blue_length").uint32("green_offset").uint32("green_length").uint32("alpha_offset").uint32("alpha_length").uint8Array("data",{lengthField:"size"});class oi extends Error{constructor(e,t){super(e,t)}}class $r extends oi{constructor(e){super(`Unsupported FrameBuffer version ${e}`)}}class zr extends oi{constructor(){super("FrameBuffer is disabled by current app")}}async function Or(n){const e=await n.createSocket("framebuffer:"),t=new dn(e.readable);let s;try{({version:s}=await Cr.deserialize(t))}catch(i){throw i instanceof vs?new zr:i}switch(s){case 1:return Nr.deserialize(t);case 2:return Br.deserialize(t);default:throw new $r(s)}}class Rr extends xs{reboot(e=""){return this.adb.createSocketAndWait(`reboot:${e}`)}bootloader(){return this.reboot("bootloader")}fastboot(){return this.reboot("fastboot")}recovery(){return this.reboot("recovery")}sideload(){return this.reboot("sideload")}qualcommEdlMode(){return this.reboot("edl")}powerOff(){return this.adb.subprocess.spawnAndWaitLegacy(["reboot","-p"])}powerButton(e=!1){const t=["input","keyevent"];return e&&t.push("--longpress"),t.push("POWER"),this.adb.subprocess.spawnAndWaitLegacy(t)}samsungOdin(){return this.reboot("download")}}var Ie,se;class ci{constructor(e=!1){l(this,Ie);l(this,se,[]);u(this,Ie,e)}wait(){if(!a(this,Ie)&&(u(this,Ie,!0),a(this,se).length===0))return Promise.resolve();const e=new P;return a(this,se).push(e),e.promise}notifyOne(){a(this,se).length!==0?a(this,se).pop().resolve():u(this,Ie,!1)}dispose(){for(const e of a(this,se))e.reject(new Error("The AutoResetEvent has been disposed"));a(this,se).length=0}}Ie=new WeakMap,se=new WeakMap;const S=[],Qe=61;function wn(n,e){const t=n.charCodeAt(0),s=e.charCodeAt(0);for(let i=t;i<=s;i+=1)S.push(i)}wn("A","Z");wn("a","z");wn("0","9");wn("+","+");wn("/","/");function li(n){const e=n%3,t=e!==0?3-e:0;return[(n+t)/3*4,t]}function qr(n,e){const[t,s]=li(n.length);if(e){if(e.length<t)throw new TypeError("output buffer is too small");if(e=e.subarray(0,t),n.buffer!==e.buffer)Fn(n,e,s);else if(e.byteOffset+e.length-(s+1)<=n.byteOffset+n.length)Fn(n,e,s);else if(e.byteOffset>=n.byteOffset-1)_r(n,e,s);else throw new TypeError("input and output cannot overlap");return t}else return e=new Uint8Array(t),Fn(n,e,s),e}function Fn(n,e,t){let s=0,i=0;for(;s<n.length-2;){const r=n[s];s+=1;const o=n[s];s+=1;const c=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4|o>>4],i+=1,e[i]=S[(o&15)<<2|c>>6],i+=1,e[i]=S[c&63],i+=1}if(t===2){const r=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4],i+=1,e[i]=Qe,i+=1,e[i]=Qe}else if(t===1){const r=n[s];s+=1;const o=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4|o>>4],i+=1,e[i]=S[(o&15)<<2],i+=1,e[i]=Qe}}function _r(n,e,t){let s=n.length-1,i=e.length-1;if(t===2){const r=n[s];s-=1,e[i]=Qe,i-=1,e[i]=Qe,i-=1,e[i]=S[(r&3)<<4],i-=1,e[i]=S[r>>2],i-=1}else if(t===1){const r=n[s];s-=1;const o=n[s];s-=1,e[i]=Qe,i-=1,e[i]=S[(r&15)<<2],i-=1,e[i]=S[(o&3)<<4|r>>4],i-=1,e[i]=S[o>>2],i-=1}for(;s>=0;){const r=n[s];s-=1;const o=n[s];s-=1;const c=n[s];s-=1,e[i]=S[r&63],i-=1,e[i]=S[(o&15)<<2|r>>6],i-=1,e[i]=S[(c&3)<<4|o>>4],i-=1,e[i]=S[c>>2],i-=1}}function Ar(n){if(n<48)throw new TypeError(`Invalid hex char ${n}`);if(n<58)return n-48;if(n<65)throw new TypeError(`Invalid hex char ${n}`);if(n<71)return n-55;if(n<97)throw new TypeError(`Invalid hex char ${n}`);if(n<103)return n-87;throw new TypeError(`Invalid hex char ${n}`)}function gt(n){let e=0;for(let t=0;t<n.length;t+=1)e=e<<4|Ar(n[t]);return e}function Ur(n,e,t){const s=e;for(e+=3;e>=s&&t>0;){const i=t&15;t>>=4,i<10?n[e]=i+48:n[e]=i+87,e-=1}for(;e>=s;)n[e]=48,e-=1}const ts=()=>{};function ui(...n){throw new Error(`Unreachable. Arguments:
|
|
1
|
+
var _i=Object.defineProperty;var Os=n=>{throw TypeError(n)};var Ui=(n,e,t)=>e in n?_i(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var g=(n,e,t)=>Ui(n,typeof e!="symbol"?e+"":e,t),Vn=(n,e,t)=>e.has(n)||Os("Cannot "+t);var a=(n,e,t)=>(Vn(n,e,"read from private field"),t?t.call(n):e.get(n)),l=(n,e,t)=>e.has(n)?Os("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),u=(n,e,t,s)=>(Vn(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t),y=(n,e,t)=>(Vn(n,e,"access private method"),t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(i){if(i.ep)return;i.ep=!0;const r=t(i);fetch(i.href,r)}})();class ys{constructor(e){g(this,"TValue");g(this,"TOmitInitKey");g(this,"options");this.options=e}}class Me{constructor(e,t,s,i){g(this,"definition");g(this,"options");g(this,"struct");g(this,"value");this.definition=e,this.options=t,this.struct=s,this.value=i}get hasCustomAccessors(){return this.get!==Me.prototype.get||this.set!==Me.prototype.set}getSize(){return this.definition.getSize()}get(){return this.value}set(e){this.value=e}}const Mi={littleEndian:!1};class ms extends Error{constructor(){super("ExactReadable ended"),Object.setPrototypeOf(this,new.target.prototype)}}const bs=Symbol("struct-value");function Wi(n){return typeof n=="object"&&n!==null&&bs in n}class Rs{constructor(e){g(this,"fieldValues",{});g(this,"value");this.value=Object.create(e),Object.defineProperty(this.value,bs,{enumerable:!1,value:this})}set(e,t){this.fieldValues[e]=t,t.hasCustomAccessors?Object.defineProperty(this.value,e,{configurable:!0,enumerable:!0,get(){return t.get()},set(s){t.set(s)}}):this.value[e]=t.get()}get(e){return this.fieldValues[e]}}const re={reject(n){return new As(n)},resolve(n){return typeof n=="object"&&n!==null&&typeof n.then=="function"?n instanceof fn||n instanceof qs||n instanceof As?n:new fn(n):new qs(n)},try(n){try{return re.resolve(n())}catch(e){return re.reject(e)}}};var Ge;const Ds=class Ds{constructor(e){l(this,Ge);u(this,Ge,e)}then(e,t){return new Ds(a(this,Ge).then(e,t))}valueOrPromise(){return a(this,Ge)}};Ge=new WeakMap;let fn=Ds;var Ye;class qs{constructor(e){l(this,Ye);u(this,Ye,e)}then(e){return e?re.try(()=>e(a(this,Ye))):this}valueOrPromise(){return a(this,Ye)}}Ye=new WeakMap;var Je;class As{constructor(e){l(this,Je);u(this,Je,e)}then(e,t){return t?re.try(()=>t(a(this,Je))):this}valueOrPromise(){throw a(this,Je)}}Je=new WeakMap;function Vi(n,e,t){return t?(n[e]|n[e+1]<<8)<<16>>16:(n[e]<<8|n[e+1])<<16>>16}function Fi(n,e,t){return t?n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24:n[e]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3]}function ji(n,e,t){return t?BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7]<<24)<<32n:BigInt(n[e]<<24)<<32n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function Hi(n,e,t){n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)}function Ki(n,e,t){n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn)}function Qi(n,e,t,s){s?(n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)):(n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn))}function Gi(n,e){return n[e]<<24>>24}function Yi(n,e,t){return t?n[e]|n[e+1]<<8:n[e+1]|n[e]<<8}function Un(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0}function Ji(n,e,t){return t?(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0:(n[e]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3])>>>0}function Xi(n,e,t){n[e]=t,n[e+1]=t>>8,n[e+2]=t>>16,n[e+3]=t>>24}function Zi(n,e){return BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7])<<56n}function er(n,e){return BigInt(n[e])<<56n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function tr(n,e,t){return t?BigInt(n[e])|BigInt(n[e+1])<<8n|BigInt(n[e+2])<<16n|BigInt(n[e+3])<<24n|BigInt(n[e+4])<<32n|BigInt(n[e+5])<<40n|BigInt(n[e+6])<<48n|BigInt(n[e+7])<<56n:BigInt(n[e])<<56n|BigInt(n[e+1])<<48n|BigInt(n[e+2])<<40n|BigInt(n[e+3])<<32n|BigInt(n[e+4])<<24n|BigInt(n[e+5])<<16n|BigInt(n[e+6])<<8n|BigInt(n[e+7])}function nr(n,e,t,s){s?(n[e]=Number(t&0xffn),n[e+1]=Number(t>>8n&0xffn),n[e+2]=Number(t>>16n&0xffn),n[e+3]=Number(t>>24n&0xffn),n[e+4]=Number(t>>32n&0xffn),n[e+5]=Number(t>>40n&0xffn),n[e+6]=Number(t>>48n&0xffn),n[e+7]=Number(t>>56n&0xffn)):(n[e]=Number(t>>56n&0xffn),n[e+1]=Number(t>>48n&0xffn),n[e+2]=Number(t>>40n&0xffn),n[e+3]=Number(t>>32n&0xffn),n[e+4]=Number(t>>24n&0xffn),n[e+5]=Number(t>>16n&0xffn),n[e+6]=Number(t>>8n&0xffn),n[e+7]=Number(t&0xffn))}const Ke=class Ke{constructor(e,t,s){g(this,"TTypeScriptType");g(this,"size");g(this,"deserialize");g(this,"serialize");this.size=e,this.deserialize=t,this.serialize=s}};g(Ke,"Int64",new Ke(8,ji,Qi)),g(Ke,"Uint64",new Ke(8,tr,nr));let yn=Ke;class sr extends ys{constructor(t,s){super();g(this,"variant");this.variant=t}getSize(){return this.variant.size}create(t,s,i){return new ir(this,t,s,i)}deserialize(t,s,i){return re.try(()=>s.readExactly(this.getSize())).then(r=>{const o=this.variant.deserialize(r,0,t.littleEndian);return this.create(t,i,o)}).valueOrPromise()}}class ir extends Me{serialize(e,t,s){this.definition.variant.serialize(t,s,this.value,this.options.littleEndian)}}const{TextEncoder:rr,TextDecoder:ar}=globalThis,or=new rr,cr=new ar;function Y(n){return or.encode(n)}function We(n){return cr.decode(n)}class ti{constructor(){g(this,"TTypeScriptType")}}const Dn=class Dn extends ti{constructor(){super()}toBuffer(e){return e}toValue(e){return e}getSize(e){return e.length}};g(Dn,"Instance",new Dn);let Kn=Dn;const Pn=class Pn extends ti{toBuffer(e){return Y(e)}toValue(e){return We(e)}getSize(){}};g(Pn,"Instance",new Pn);let Qn=Pn;const Q=new Uint8Array(0);class ni extends ys{constructor(t,s){super(s);g(this,"converter");g(this,"TTypeScriptType");this.converter=t}getDeserializeSize(t){return this.getSize()}create(t,s,i,r){return new si(this,t,s,i,r)}deserialize(t,s,i){return re.try(()=>{const r=this.getDeserializeSize(i);return r===0?Q:s.readExactly(r)}).then(r=>{const o=this.converter.toValue(r);return this.create(t,i,o,r)}).valueOrPromise()}}class si extends Me{constructor(t,s,i,r,o){super(t,s,i,r);g(this,"array");this.array=o}set(t){super.set(t),this.array=void 0}serialize(t,s,i){this.array??(this.array=this.definition.converter.toBuffer(this.value)),s.set(this.array,i)}}class lr extends ni{getSize(){return this.options.length}}class ur extends ni{getSize(){return 0}getDeserializeSize(e){let t=e.value[this.options.lengthField];return typeof t=="string"&&(t=Number.parseInt(t,this.options.lengthFieldRadix??10)),t}create(e,t,s,i){return new hr(this,e,t,s,i)}}var Nn,ii;class hr extends si{constructor(t,s,i,r,o){super(t,s,i,r,o);l(this,Nn);g(this,"length");g(this,"lengthFieldValue");o&&(this.length=o.length);const c=this.definition.options.lengthField,w=i.get(c);this.lengthFieldValue=new dr(w,this),i.set(c,this.lengthFieldValue)}getSize(){return this.length===void 0&&(this.length=y(this,Nn,ii).call(this)),this.length===void 0&&(this.array=this.definition.converter.toBuffer(this.value),this.length=this.array.length),this.length}set(t){super.set(t),this.array=void 0,this.length=void 0}}Nn=new WeakSet,ii=function(){const t=this.definition.converter.getSize(this.value);if(t!==void 0&&t<0)throw new Error("Invalid length");return t};class dr extends Me{constructor(t,s){super(t.definition,t.options,t.struct,0);g(this,"originalValue");g(this,"bufferValue");this.originalValue=t,this.bufferValue=s}getSize(){return this.originalValue.getSize()}get(){let t=this.bufferValue.getSize();return typeof this.originalValue.get()=="string"&&(t=t.toString(this.bufferValue.definition.options.lengthFieldRadix??10)),t}set(){}serialize(t,s,i){this.originalValue.set(this.get()),this.originalValue.serialize(t,s,i)}}var ae;(function(n){n.Uint8={signed:!1,size:1,deserialize(e){return e[0]},serialize(e,t,s){e.setUint8(t,s)}},n.Int8={signed:!0,size:1,deserialize(e){return Gi(e,0)},serialize(e,t,s){e.setInt8(t,s)}},n.Uint16={signed:!1,size:2,deserialize(e,t){return Yi(e,0,t)},serialize(e,t,s,i){e.setUint16(t,s,i)}},n.Int16={signed:!0,size:2,deserialize(e,t){return Vi(e,0,t)},serialize(e,t,s,i){e.setInt16(t,s,i)}},n.Uint32={signed:!1,size:4,deserialize(e,t){return Ji(e,0,t)},serialize(e,t,s,i){e.setUint32(t,s,i)}},n.Int32={signed:!0,size:4,deserialize(e,t){return Fi(e,0,t)},serialize(e,t,s,i){e.setInt32(t,s,i)}}})(ae||(ae={}));class wr extends ys{constructor(t,s){super();g(this,"variant");this.variant=t}getSize(){return this.variant.size}create(t,s,i){return new gr(this,t,s,i)}deserialize(t,s,i){return re.try(()=>s.readExactly(this.getSize())).then(r=>{const o=this.variant.deserialize(r,t.littleEndian);return this.create(t,i,o)}).valueOrPromise()}}class gr extends Me{serialize(e,t,s){this.definition.variant.serialize(e,s,this.value,this.options.littleEndian)}}class ri extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class pr extends ri{constructor(){super("The underlying readable was ended before the struct was fully deserialized")}}class vs extends ri{constructor(){super("The underlying readable doesn't contain any more struct")}}var Se,W,xe,Xe,_,me,Gn,pt;const Ps=class Ps{constructor(e){l(this,_);g(this,"TFields");g(this,"TOmitInitKey");g(this,"TExtra");g(this,"TInit");g(this,"TDeserializeResult");g(this,"options");l(this,Se,0);l(this,W,[]);l(this,xe,{});l(this,Xe);l(this,pt,(e,t,s)=>"length"in s?this.field(e,new lr(t,s)):this.field(e,new ur(t,s)));g(this,"uint8Array",(e,t,s)=>a(this,pt).call(this,e,Kn.Instance,t,s));g(this,"string",(e,t,s)=>a(this,pt).call(this,e,Qn.Instance,t,s));this.options={...Mi,...e}}get size(){return a(this,Se)}get fields(){return a(this,W)}field(e,t){for(const i of a(this,W))if(i[0]===e){const r=String(e);throw new Error(`This struct already have a field with name '${r}'`)}a(this,W).push([e,t]);const s=t.getSize();return u(this,Se,a(this,Se)+s),this}concat(e){if(!(e instanceof Ps))throw new TypeError("The other value must be a `Struct` instance");for(const t of a(e,W))a(this,W).push(t);return u(this,Se,a(this,Se)+a(e,Se)),Object.defineProperties(a(this,xe),Object.getOwnPropertyDescriptors(a(e,xe))),this}int8(e,t){return y(this,_,me).call(this,e,ae.Int8,t)}uint8(e,t){return y(this,_,me).call(this,e,ae.Uint8,t)}int16(e,t){return y(this,_,me).call(this,e,ae.Int16,t)}uint16(e,t){return y(this,_,me).call(this,e,ae.Uint16,t)}int32(e,t){return y(this,_,me).call(this,e,ae.Int32,t)}uint32(e,t){return y(this,_,me).call(this,e,ae.Uint32,t)}int64(e,t){return y(this,_,Gn).call(this,e,yn.Int64,t)}uint64(e,t){return y(this,_,Gn).call(this,e,yn.Uint64,t)}extra(e){return Object.defineProperties(a(this,xe),Object.getOwnPropertyDescriptors(e)),this}postDeserialize(e){return u(this,Xe,e),this}deserialize(e){const t=new Rs(a(this,xe));let s=re.resolve();const i=e.position;for(const[r,o]of a(this,W))s=s.then(()=>o.deserialize(this.options,e,t)).then(c=>{t.set(r,c)},c=>{throw c instanceof ms?e.position===i?new vs:new pr:c});return s.then(()=>{const r=t.value;if(a(this,Xe)){const o=a(this,Xe).call(r,r);if(o!==void 0)return o}return r}).valueOrPromise()}serialize(e,t){let s;if(Wi(e)){s=e[bs];for(const[w,d]of Object.entries(e)){const p=s.get(w);p&&p.set(d)}}else{s=new Rs({});for(const[w,d]of a(this,W)){const p=d.create(this.options,s,e[w]);s.set(w,p)}}let i=0;const r=[];for(const[w]of a(this,W)){const d=s.get(w),p=d.getSize();r.push({fieldValue:d,size:p}),i+=p}if(!t)t=new Uint8Array(i);else if(t.length<i)throw new TypeError("Output buffer is too small");const o=new DataView(t.buffer,t.byteOffset,t.byteLength);let c=0;for(const{fieldValue:w,size:d}of r)w.serialize(o,t,c),c+=d;return t.length!==i?t.subarray(0,i):t}};Se=new WeakMap,W=new WeakMap,xe=new WeakMap,Xe=new WeakMap,_=new WeakSet,me=function(e,t,s){return this.field(e,new wr(t,s))},Gn=function(e,t,s){return this.field(e,new sr(t,s))},pt=new WeakMap;let x=Ps;var P=(function(){function n(){var e=this;this._state="running",this.resolve=function(t){e._resolve(t),e._state="resolved"},this.reject=function(t){e._reject(t),e._state="rejected"},this._promise=new Promise(function(t,s){e._resolve=t,e._reject=s})}return Object.defineProperty(n.prototype,"promise",{get:function(){return this._promise},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n})(),fr=(function(){function n(e){e===void 0&&(e=0),this.pendingResolvers=new Map,this.nextId=e}return n.prototype.add=function(){var e=this.nextId++,t=new P;return this.pendingResolvers.set(e,t),[e,t.promise]},n.prototype.getResolver=function(e){if(!this.pendingResolvers.has(e))return null;var t=this.pendingResolvers.get(e);return this.pendingResolvers.delete(e),t},n.prototype.resolve=function(e,t){var s=this.getResolver(e);return s!==null?(s.resolve(t),!0):!1},n.prototype.reject=function(e,t){var s=this.getResolver(e);return s!==null?(s.reject(t),!0):!1},n})();function yr(n){return new Promise(function(e){globalThis.setTimeout(function(){return e()},n)})}const Mn=globalThis,hn=Mn.AbortController,Ve=Mn.ReadableStream,J=Mn.WritableStream,Es=Mn.TransformStream;var Ze;class dt extends Ve{constructor(t,s){let i;const r=new hn;super({start:async o=>{await Promise.resolve();const c=t({abortSignal:r.signal,enqueue:async w=>{if(r.signal.aborted)throw r.signal.reason;if(o.desiredSize===null){o.enqueue(w);return}if(a(this,Ze)){u(this,Ze,!1),o.enqueue(w);return}o.desiredSize<=0&&(i=new P,await i.promise),o.enqueue(w)},close(){o.close()},error(w){o.error(w)}});c&&"then"in c&&c.then(()=>{try{o.close()}catch{}},w=>{o.error(w)})},pull:()=>{if(i){i.resolve();return}(s==null?void 0:s.highWaterMark)===0&&u(this,Ze,!0)},cancel:o=>{r.abort(o),i==null||i.reject(o)}},s);l(this,Ze,!1)}}Ze=new WeakMap;const mr=()=>{};var X,Z,ee,R,fe,Yn,Jn;class dn{constructor(e){l(this,fe);l(this,X);l(this,Z,0);l(this,ee,0);l(this,R,0);g(this,"stream");g(this,"reader");this.stream=e,this.reader=e.getReader()}get position(){return a(this,R)}readExactly(e){if(a(this,X)){const t=a(this,X),s=a(this,Z);return a(this,ee)>e?(u(this,Z,a(this,Z)+e),u(this,ee,a(this,ee)-e),u(this,R,a(this,R)+e),t.subarray(s,s+e)):(u(this,X,void 0),u(this,ee,0),u(this,Z,0),u(this,R,a(this,R)+(t.length-s)),y(this,fe,Jn).call(this,e,t.subarray(s)))}return y(this,fe,Jn).call(this,e)}release(){return a(this,ee)>0?new dt(async e=>{const t=a(this,X).subarray(a(this,Z));for(await e.enqueue(t),e.abortSignal.addEventListener("abort",()=>{this.reader.cancel().catch(mr)});;){const{done:s,value:i}=await this.reader.read();if(s)return;await e.enqueue(i)}}):(this.reader.releaseLock(),this.stream)}async cancel(e){await this.reader.cancel(e)}}X=new WeakMap,Z=new WeakMap,ee=new WeakMap,R=new WeakMap,fe=new WeakSet,Yn=async function(){const{done:e,value:t}=await this.reader.read();if(e)throw new ms;return t},Jn=async function(e,t){let s,i;if(t)s=new Uint8Array(e),s.set(t),i=t.length,e-=t.length;else{const r=await y(this,fe,Yn).call(this);if(r.length===e)return u(this,R,a(this,R)+e),r;if(r.length>e)return u(this,X,r),u(this,Z,e),u(this,ee,r.length-e),u(this,R,a(this,R)+e),r.subarray(0,e);s=new Uint8Array(e),s.set(r),i=r.length,e-=r.length,u(this,R,a(this,R)+r.length)}for(;e>0;){const r=await y(this,fe,Yn).call(this);if(r.length===e)return s.set(r,i),u(this,R,a(this,R)+e),s;if(r.length>e)return u(this,X,r),u(this,Z,e),u(this,ee,r.length-e),s.set(r.subarray(0,e),i),u(this,R,a(this,R)+e),s;s.set(r,i),i+=r.length,e-=r.length,u(this,R,a(this,R)+r.length)}return s};var ft,yt;class br{constructor(e){l(this,ft);l(this,yt);let t;const s=new dn(new dt(i=>{t=i}));u(this,ft,new Ve({async pull(i){try{const r=await e(s);i.enqueue(r)}catch(r){if(r instanceof vs){i.close();return}throw r}},cancel:i=>s.cancel(i)})),u(this,yt,new J({async write(i){await t.enqueue(i)},abort(){t.close()},close(){t.close()}}))}get readable(){return a(this,ft)}get writable(){return a(this,yt)}}ft=new WeakMap,yt=new WeakMap;var et,V,Cn,Le,mt;class Xn{constructor(){l(this,et,"");l(this,V,new P);l(this,Cn,new J({write:e=>{u(this,et,a(this,et)+e)},close:()=>{a(this,V).resolve(a(this,et)),a(this,Le).enqueue(a(this,et)),a(this,Le).close()},abort:e=>{a(this,V).reject(e),a(this,Le).error(e)}}));l(this,Le);l(this,mt,new Ve({start:e=>{u(this,Le,e)}}));Object.defineProperties(a(this,mt),{then:{get:()=>a(this,V).promise.then.bind(a(this,V).promise)},catch:{get:()=>a(this,V).promise.catch.bind(a(this,V).promise)},finally:{get:()=>a(this,V).promise.finally.bind(a(this,V).promise)}})}get writable(){return a(this,Cn)}get readable(){return a(this,mt)}}et=new WeakMap,V=new WeakMap,Cn=new WeakMap,Le=new WeakMap,mt=new WeakMap;const{console:pn}=globalThis;var ei;const vr=((ei=pn==null?void 0:pn.createTask)==null?void 0:ei.bind(pn))??(()=>({run(n){return n()}}));function Er(n){return typeof n=="object"&&n!==null&&"then"in n}var bt,F;class M{constructor(e){l(this,bt);l(this,F);g(this,"value");g(this,"consumed");u(this,bt,vr("Consumable")),this.value=e,u(this,F,new P),this.consumed=a(this,F).promise}consume(){a(this,F).resolve()}error(e){a(this,F).reject(e)}tryConsume(e){try{let t=a(this,bt).run(()=>e(this.value));return Er(t)?t=t.then(s=>(a(this,F).resolve(),s),s=>{throw a(this,F).reject(s),s}):a(this,F).resolve(),t}catch(t){throw a(this,F).reject(t),t}}}bt=new WeakMap,F=new WeakMap;(function(n){class e extends J{static async write(i,r){const o=new n(r);await i.write(o),await o.consumed}constructor(i,r){let o;r&&(o={},"highWaterMark"in r&&(o.highWaterMark=r.highWaterMark),"size"in r&&(o.size=c=>r.size(c instanceof n?c.value:c))),super({start(c){var w;return(w=i.start)==null?void 0:w.call(i,c)},async write(c,w){await c.tryConsume(d=>{var p;return(p=i.write)==null?void 0:p.call(i,d,w)})},abort(c){var w;return(w=i.abort)==null?void 0:w.call(i,c)},close(){var c;return(c=i.close)==null?void 0:c.call(i)}},o)}}n.WritableStream=e;class t extends Ve{static async enqueue(i,r){const o=new n(r);i.enqueue(o),await o.consumed}constructor(i,r){let o,c;r&&(c={},"highWaterMark"in r&&(c.highWaterMark=r.highWaterMark),"size"in r&&(c.size=w=>r.size(w.value))),super({async start(w){var d;o={async enqueue(p){await t.enqueue(w,p)},close(){w.close()},error(p){w.error(p)}},await((d=i.start)==null?void 0:d.call(i,o))},async pull(){var w;await((w=i.pull)==null?void 0:w.call(i,o))},async cancel(w){var d;await((d=i.cancel)==null?void 0:d.call(i,w))}},c)}}n.ReadableStream=t})(M||(M={}));var pe;(function(n){function e(r){return r instanceof M?r.value:r}n.getValue=e;function t(r,o){return r instanceof M?r.tryConsume(o):o(r)}n.tryConsume=t;class s extends Es{constructor(){super({transform(o,c){n.tryConsume(o,w=>{c.enqueue(w)})}})}}n.UnwrapStream=s;class i extends J{constructor(o,c){let w;c&&(w={},"highWaterMark"in c&&(w.highWaterMark=c.highWaterMark),"size"in c&&(w.size=d=>c.size(d instanceof M?d.value:d))),super({start(d){var p;return(p=o.start)==null?void 0:p.call(o,d)},async write(d,p){await n.tryConsume(d,b=>{var E;return(E=o.write)==null?void 0:E.call(o,b,p)})},abort(d){var p;return(p=o.abort)==null?void 0:p.call(o,d)},close(){var d;return(d=o.close)==null?void 0:d.call(o)}},w)}}n.WritableStream=i})(pe||(pe={}));var te,ne,N,q;class ai{constructor(e){l(this,te);l(this,ne);l(this,N);l(this,q);u(this,te,e),u(this,ne,new Uint8Array(e)),u(this,N,0),u(this,q,e)}*push(e){let t=0,s=e.length;if(a(this,N)!==0)if(s>=a(this,q)){if(a(this,ne).set(e.subarray(0,a(this,q)),a(this,N)),t+=a(this,q),s-=a(this,q),yield a(this,ne),u(this,N,0),u(this,q,a(this,te)),s===0)return}else{a(this,ne).set(e,a(this,N)),u(this,N,a(this,N)+s),u(this,q,a(this,q)-s);return}for(;s>=a(this,te);){const i=t+a(this,te);yield e.subarray(t,i),t=i,s-=a(this,te)}s>0&&(a(this,ne).set(e.subarray(t),a(this,N)),u(this,N,a(this,N)+s),u(this,q,a(this,q)-s))}flush(){if(a(this,N)===0)return;const e=a(this,ne).subarray(0,a(this,N));return u(this,N,0),u(this,q,a(this,te)),e}}te=new WeakMap,ne=new WeakMap,N=new WeakMap,q=new WeakMap;class Sr extends Es{constructor(e,t=!1){const s=t?new ai(e):void 0;super({async transform(i,r){await pe.tryConsume(i,async o=>{if(s)for(const c of s.push(o))await M.ReadableStream.enqueue(r,c);else{let c=0,w=o.length;for(;w>0;){const d=c+e;await M.ReadableStream.enqueue(r,o.subarray(c,d)),c=d,w-=e}}})},flush(i){if(s){const r=s.flush();r&&i.enqueue(r)}}})}}function xr(n,e){return"start"in n?n.start(e):typeof n=="function"?n(e):n}var tt;class Lr extends Ve{constructor(t,s){super({start:async i=>{await Promise.resolve(),this.readable=await xr(t,i),u(this,tt,this.readable.getReader())},pull:async i=>{var o;const r=await a(this,tt).read();r.done?(i.close(),"close"in t&&await((o=t.close)==null?void 0:o.call(t))):i.enqueue(r.value)},cancel:async i=>{var r;await a(this,tt).cancel(i),"cancel"in t&&await((r=t.cancel)==null?void 0:r.call(t,i))}},s);g(this,"readable");l(this,tt)}}tt=new WeakMap;const _s=()=>{};var vt,Et,ke,St,nt;class kr{constructor(e){l(this,vt,[]);l(this,Et,[]);l(this,ke,!1);l(this,St,new P);l(this,nt);u(this,nt,e??{})}get writableClosed(){return a(this,ke)}get closed(){return a(this,St).promise}wrapReadable(e,t){return new Lr({start:s=>(a(this,vt).push(s),e),cancel:async()=>{await this.close()},close:async()=>{await this.dispose()}},t)}createWritable(e){const t=e.getWriter();return a(this,Et).push(t),new J({write:async s=>{await t.write(s)},abort:async s=>{await t.abort(s),await this.close()},close:async()=>{await t.close().catch(_s),await this.close()}})}async close(){var e,t;if(!a(this,ke)){u(this,ke,!0),await((t=(e=a(this,nt)).close)==null?void 0:t.call(e))!==!1&&await this.dispose();for(const s of a(this,Et))s.close().catch(_s)}}async dispose(){var e,t;u(this,ke,!0),a(this,St).resolve();for(const s of a(this,vt))try{s.close()}catch{}await((t=(e=a(this,nt)).dispose)==null?void 0:t.call(e))}}vt=new WeakMap,Et=new WeakMap,ke=new WeakMap,St=new WeakMap,nt=new WeakMap;const Tr=globalThis,Zn=Tr.TextDecoderStream;function Ir(n,e){const t=e.writable.getWriter(),s=e.readable.pipeTo(n);return new J({async write(i){await t.write(i)},async close(){await t.close(),await s}})}class Dr extends br{constructor(e){super(t=>e.deserialize(t))}}async function Pr(n){return"start"in n?await n.start():typeof n=="function"?await n():n}var Te;const Ns=class Ns extends J{constructor(t){super({start:async()=>{await Promise.resolve(),this.writable=await Pr(t),u(this,Te,this.writable.getWriter())},write:async s=>{await a(this,Te).write(s)},abort:async s=>{var i;await a(this,Te).abort(s),t!==this.writable&&"close"in t&&await((i=t.close)==null?void 0:i.call(t))},close:async()=>{var s;await a(this,Te).close(),t!==this.writable&&"close"in t&&await((s=t.close)==null?void 0:s.call(t))}});g(this,"writable");l(this,Te)}bePipedThroughFrom(t){let s;return new Ns({start:()=>(s=t.readable.pipeTo(this),t.writable),async close(){await s}})}};Te=new WeakMap;let es=Ns;var st;class Ss{constructor(){l(this,st,[]);this.dispose=this.dispose.bind(this)}addDisposable(e){return a(this,st).push(e),e}dispose(){for(const e of a(this,st))e.dispose();u(this,st,[])}}st=new WeakMap;class xs extends Ss{constructor(t){super();g(this,"adb");this.adb=t}}const Nr=new x({littleEndian:!0}).uint32("version"),Cr=new x({littleEndian:!0}).uint32("bpp").uint32("size").uint32("width").uint32("height").uint32("red_offset").uint32("red_length").uint32("blue_offset").uint32("blue_length").uint32("green_offset").uint32("green_length").uint32("alpha_offset").uint32("alpha_length").uint8Array("data",{lengthField:"size"}),Br=new x({littleEndian:!0}).uint32("bpp").uint32("colorSpace").uint32("size").uint32("width").uint32("height").uint32("red_offset").uint32("red_length").uint32("blue_offset").uint32("blue_length").uint32("green_offset").uint32("green_length").uint32("alpha_offset").uint32("alpha_length").uint8Array("data",{lengthField:"size"});class oi extends Error{constructor(e,t){super(e,t)}}class $r extends oi{constructor(e){super(`Unsupported FrameBuffer version ${e}`)}}class zr extends oi{constructor(){super("FrameBuffer is disabled by current app")}}async function Or(n){const e=await n.createSocket("framebuffer:"),t=new dn(e.readable);let s;try{({version:s}=await Nr.deserialize(t))}catch(i){throw i instanceof vs?new zr:i}switch(s){case 1:return Cr.deserialize(t);case 2:return Br.deserialize(t);default:throw new $r(s)}}class Rr extends xs{reboot(e=""){return this.adb.createSocketAndWait(`reboot:${e}`)}bootloader(){return this.reboot("bootloader")}fastboot(){return this.reboot("fastboot")}recovery(){return this.reboot("recovery")}sideload(){return this.reboot("sideload")}qualcommEdlMode(){return this.reboot("edl")}powerOff(){return this.adb.subprocess.spawnAndWaitLegacy(["reboot","-p"])}powerButton(e=!1){const t=["input","keyevent"];return e&&t.push("--longpress"),t.push("POWER"),this.adb.subprocess.spawnAndWaitLegacy(t)}samsungOdin(){return this.reboot("download")}}var Ie,se;class ci{constructor(e=!1){l(this,Ie);l(this,se,[]);u(this,Ie,e)}wait(){if(!a(this,Ie)&&(u(this,Ie,!0),a(this,se).length===0))return Promise.resolve();const e=new P;return a(this,se).push(e),e.promise}notifyOne(){a(this,se).length!==0?a(this,se).pop().resolve():u(this,Ie,!1)}dispose(){for(const e of a(this,se))e.reject(new Error("The AutoResetEvent has been disposed"));a(this,se).length=0}}Ie=new WeakMap,se=new WeakMap;const S=[],Qe=61;function wn(n,e){const t=n.charCodeAt(0),s=e.charCodeAt(0);for(let i=t;i<=s;i+=1)S.push(i)}wn("A","Z");wn("a","z");wn("0","9");wn("+","+");wn("/","/");function li(n){const e=n%3,t=e!==0?3-e:0;return[(n+t)/3*4,t]}function qr(n,e){const[t,s]=li(n.length);if(e){if(e.length<t)throw new TypeError("output buffer is too small");if(e=e.subarray(0,t),n.buffer!==e.buffer)Fn(n,e,s);else if(e.byteOffset+e.length-(s+1)<=n.byteOffset+n.length)Fn(n,e,s);else if(e.byteOffset>=n.byteOffset-1)Ar(n,e,s);else throw new TypeError("input and output cannot overlap");return t}else return e=new Uint8Array(t),Fn(n,e,s),e}function Fn(n,e,t){let s=0,i=0;for(;s<n.length-2;){const r=n[s];s+=1;const o=n[s];s+=1;const c=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4|o>>4],i+=1,e[i]=S[(o&15)<<2|c>>6],i+=1,e[i]=S[c&63],i+=1}if(t===2){const r=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4],i+=1,e[i]=Qe,i+=1,e[i]=Qe}else if(t===1){const r=n[s];s+=1;const o=n[s];s+=1,e[i]=S[r>>2],i+=1,e[i]=S[(r&3)<<4|o>>4],i+=1,e[i]=S[(o&15)<<2],i+=1,e[i]=Qe}}function Ar(n,e,t){let s=n.length-1,i=e.length-1;if(t===2){const r=n[s];s-=1,e[i]=Qe,i-=1,e[i]=Qe,i-=1,e[i]=S[(r&3)<<4],i-=1,e[i]=S[r>>2],i-=1}else if(t===1){const r=n[s];s-=1;const o=n[s];s-=1,e[i]=Qe,i-=1,e[i]=S[(r&15)<<2],i-=1,e[i]=S[(o&3)<<4|r>>4],i-=1,e[i]=S[o>>2],i-=1}for(;s>=0;){const r=n[s];s-=1;const o=n[s];s-=1;const c=n[s];s-=1,e[i]=S[r&63],i-=1,e[i]=S[(o&15)<<2|r>>6],i-=1,e[i]=S[(c&3)<<4|o>>4],i-=1,e[i]=S[c>>2],i-=1}}function _r(n){if(n<48)throw new TypeError(`Invalid hex char ${n}`);if(n<58)return n-48;if(n<65)throw new TypeError(`Invalid hex char ${n}`);if(n<71)return n-55;if(n<97)throw new TypeError(`Invalid hex char ${n}`);if(n<103)return n-87;throw new TypeError(`Invalid hex char ${n}`)}function gt(n){let e=0;for(let t=0;t<n.length;t+=1)e=e<<4|_r(n[t]);return e}function Ur(n,e,t){const s=e;for(e+=3;e>=s&&t>0;){const i=t&15;t>>=4,i<10?n[e]=i+48:n[e]=i+87,e-=1}for(;e>=s;)n[e]=48,e-=1}const ts=()=>{};function ui(...n){throw new Error(`Unreachable. Arguments:
|
|
2
2
|
`+n.join(`
|
|
3
3
|
`))}function mn(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t+=1)if(n[t]!==e[t])return!1;return!0}const hi=new x().string("length",{length:4}).string("content",{lengthField:"length",lengthFieldRadix:16});class di extends Error{constructor(e){super(e),Object.setPrototypeOf(this,new.target.prototype)}}class Mr extends di{constructor(){super("ADB reverse tunnel is not supported on this device when connected wirelessly.")}}const Wr=new x().concat(hi).postDeserialize(n=>{throw n.content==="more than one device/emulator"?new Mr:new di(n.content)});function Vr(n){let e=0;for(const t of n){if(t<48||t>57)return e;e=e*10+t-48}return e}const Fr=Y("OKAY");var it;class jr extends Ss{constructor(t){super();g(this,"adb");l(this,it,new Map);this.adb=t}async createBufferedStream(t){const s=await this.adb.createSocket(t);return new dn(s.readable)}async sendRequest(t){const s=await this.createBufferedStream(t),i=await s.readExactly(4);return mn(i,Fr)||await Wr.deserialize(s),s}async list(){const t=await this.createBufferedStream("reverse:list-forward");return(await hi.deserialize(t)).content.split(`
|
|
4
|
-
`).filter(i=>!!i).map(i=>{const[r,o,c]=i.split(" ");return{deviceSerial:r,localName:o,remoteName:c}})}async addExternal(t,s){const i=await this.sendRequest(`reverse:forward:${t};${s}`);if(t.startsWith("tcp:")){const r=i.position;try{const o=gt(await i.readExactly(4));t=`tcp:${Vr(await i.readExactly(o))}`}catch(o){if(!(o instanceof ms&&i.position===r))throw o}}return t}async add(t,s,i){i=await this.adb.transport.addReverseTunnel(s,i);try{return t=await this.addExternal(t,i),a(this,it).set(t,i),t}catch(r){throw await this.adb.transport.removeReverseTunnel(i),r}}async remove(t){const s=a(this,it).get(t);s&&await this.adb.transport.removeReverseTunnel(s),await this.sendRequest(`reverse:killforward:${t}`)}async removeAll(){await this.adb.transport.clearReverseTunnels(),a(this,it).clear(),await this.sendRequest("reverse:killforward-all")}}it=new WeakMap;var oe,xt,Lt;const Bn=class Bn{constructor(e){l(this,oe);l(this,xt);l(this,Lt);u(this,oe,e),u(this,xt,new Ve({start:t=>{a(this,oe).closed.then(()=>t.close()).catch(ui)}})),u(this,Lt,e.closed.then(()=>0))}static isSupported(){return!0}static async pty(e,t){return new Bn(await e.createSocket(`shell:${t}`))}static async raw(e,t){return new Bn(await e.createSocket(`exec:${t}`))}get stdin(){return a(this,oe).writable}get stdout(){return a(this,oe).readable}get stderr(){return a(this,xt)}get exit(){return a(this,Lt)}resize(){}async kill(){await a(this,oe).close()}};oe=new WeakMap,xt=new WeakMap,Lt=new WeakMap;let bn=Bn;var m;(function(n){n.ShellV2="shell_v2",n.Cmd="cmd",n.StatV2="stat_v2",n.ListV2="ls_v2",n.FixedPushMkdir="fixed_push_mkdir",n.Abb="abb",n.AbbExec="abb_exec",n.SendReceiveV2="sendrecv_v2",n.DelayedAck="delayed_ack"})(m||(m={}));var be;(function(n){n[n.Stdin=0]="Stdin",n[n.Stdout=1]="Stdout",n[n.Stderr=2]="Stderr",n[n.Exit=3]="Exit",n[n.CloseStdin=4]="CloseStdin",n[n.WindowSizeChange=5]="WindowSizeChange"})(be||(be={}));const jn=new x({littleEndian:!0}).uint8("id",void 0).uint32("length").uint8Array("data",{lengthField:"length"});var rt,at,kt,Tt,It,De;const $n=class $n{constructor(e){l(this,rt);l(this,at);l(this,kt);l(this,Tt);l(this,It);l(this,De,new P);u(this,rt,e);let t,s;u(this,Tt,new dt(i=>{t=i})),u(this,It,new dt(i=>{s=i})),e.readable.pipeThrough(new Dr(jn)).pipeTo(new J({write:async i=>{switch(i.id){case be.Exit:a(this,De).resolve(i.data[0]);break;case be.Stdout:t.abortSignal.aborted||await t.enqueue(i.data);break;case be.Stderr:s.abortSignal.aborted||await s.enqueue(i.data);break}}})).then(()=>{t.close(),s.close(),a(this,De).reject(new Error("Socket ended without exit message"))},i=>{t.error(i),s.error(i),a(this,De).reject(i)}),u(this,at,a(this,rt).writable.getWriter()),u(this,kt,new pe.WritableStream({write:async i=>{await a(this,at).write(jn.serialize({id:be.Stdin,data:i}))}}))}static isSupported(e){return e.canUseFeature(m.ShellV2)}static async pty(e,t){return new $n(await e.createSocket(`shell,v2,pty:${t}`))}static async raw(e,t){return new $n(await e.createSocket(`shell,v2,raw:${t}`))}get stdin(){return a(this,kt)}get stdout(){return a(this,Tt)}get stderr(){return a(this,It)}get exit(){return a(this,De).promise}async resize(e,t){await a(this,at).write(jn.serialize({id:be.WindowSizeChange,data:Y(`${e}x${t},0x0\0`)}))}kill(){return a(this,rt).close()}};rt=new WeakMap,at=new WeakMap,kt=new WeakMap,Tt=new WeakMap,It=new WeakMap,De=new WeakMap;let ns=$n;const Hr={protocols:[ns,bn]};var Dt,ss;class Kr extends xs{constructor(){super(...arguments);l(this,Dt)}shell(t,s){return y(this,Dt,ss).call(this,"pty",t,s)}spawn(t,s){return y(this,Dt,ss).call(this,"raw",t,s)}async spawnAndWait(t,s){const i=await this.spawn(t,s),[r,o,c]=await Promise.all([i.stdout.pipeThrough(new Zn).pipeThrough(new Xn),i.stderr.pipeThrough(new Zn).pipeThrough(new Xn),i.exit]);return{stdout:r,stderr:o,exitCode:c}}async spawnAndWaitLegacy(t){const{stdout:s}=await this.spawnAndWait(t,{protocols:[bn]});return s}}Dt=new WeakSet,ss=async function(t,s,i){const{protocols:r}={...Hr,...i};let o;for(const c of r)if(await c.isSupported(this.adb)){o=c;break}if(!o)throw new Error("No specified protocol is supported by the device");return Array.isArray(s)?s=s.join(" "):s===void 0&&(s=""),await o[t](this.adb,s)};function is(n){let e="";e+="'";let t=0;for(;;){const s=n.indexOf("'",t);if(s===-1){e+=n.substring(t);break}e+=n.substring(t,s),e+=String.raw`'\''`,t=s+1}return e+="'",e}function Qr(n){const e=new Uint8Array(n.length);for(let t=0;t<n.length;t+=1)e[t]=n.charCodeAt(t);return e}function v(n){const e=Qr(n);return Un(e,0)}var N;(function(n){n.Entry=v("DENT"),n.Entry2=v("DNT2"),n.Lstat=v("STAT"),n.Stat=v("STA2"),n.Lstat2=v("LST2"),n.Done=v("DONE"),n.Data=v("DATA"),n.Ok=v("OKAY"),n.Fail=v("FAIL")})(N||(N={}));class Gr extends Error{}const wi=new x({littleEndian:!0}).uint32("messageLength").string("message",{lengthField:"messageLength"}).postDeserialize(n=>{throw new Gr(n.message)});async function vn(n,e,t){typeof e=="string"&&(e=v(e));const s=await n.readExactly(4);switch(Un(s,0)){case N.Fail:throw await wi.deserialize(n),new Error("Unreachable");case e:return await t.deserialize(n);default:throw new Error(`Expected '${e}', but got '${We(s)}'`)}}async function*En(n,e,t){for(typeof e=="string"&&(e=v(e));;){const s=await n.readExactly(4);switch(Un(s,0)){case N.Fail:throw await wi.deserialize(n),new Error("Unreachable");case N.Done:await n.readExactly(t.size);return;case e:yield await t.deserialize(n);break;default:throw new Error(`Expected '${e}' or '${N.Done}', but got '${We(s)}'`)}}}var O;(function(n){n.List=v("LIST"),n.ListV2=v("LIS2"),n.Send=v("SEND"),n.SendV2=v("SND2"),n.Lstat=v("STAT"),n.Stat=v("STA2"),n.LstatV2=v("LST2"),n.Data=v("DATA"),n.Done=v("DONE"),n.Receive=v("RECV")})(O||(O={}));const Us=new x({littleEndian:!0}).uint32("id").uint32("arg");async function G(n,e,t){if(typeof e=="string"&&(e=v(e)),typeof t=="number"){await n.write(Us.serialize({id:e,arg:t}));return}typeof t=="string"&&(t=Y(t)),await n.write(Us.serialize({id:e,arg:t.length})),await n.write(t)}var Sn;(function(n){n[n.Directory=4]="Directory",n[n.File=8]="File",n[n.Link=10]="Link"})(Sn||(Sn={}));const gi=new x({littleEndian:!0}).int32("mode").int32("size").int32("mtime").extra({get type(){return this.mode>>12},get permission(){return this.mode&4095}}).postDeserialize(n=>{if(n.mode===0&&n.size===0&&n.mtime===0)throw new Error("lstat error")});var xn;(function(n){n[n.SUCCESS=0]="SUCCESS",n[n.EACCES=13]="EACCES",n[n.EEXIST=17]="EEXIST",n[n.EFAULT=14]="EFAULT",n[n.EFBIG=27]="EFBIG",n[n.EINTR=4]="EINTR",n[n.EINVAL=22]="EINVAL",n[n.EIO=5]="EIO",n[n.EISDIR=21]="EISDIR",n[n.ELOOP=40]="ELOOP",n[n.EMFILE=24]="EMFILE",n[n.ENAMETOOLONG=36]="ENAMETOOLONG",n[n.ENFILE=23]="ENFILE",n[n.ENOENT=2]="ENOENT",n[n.ENOMEM=12]="ENOMEM",n[n.ENOSPC=28]="ENOSPC",n[n.ENOTDIR=20]="ENOTDIR",n[n.EOVERFLOW=75]="EOVERFLOW",n[n.EPERM=1]="EPERM",n[n.EROFS=30]="EROFS",n[n.ETXTBSY=26]="ETXTBSY"})(xn||(xn={}));const Ls=new x({littleEndian:!0}).uint32("error",void 0).uint64("dev").uint64("ino").uint32("mode").uint32("nlink").uint32("uid").uint32("gid").uint64("size").uint64("atime").uint64("mtime").uint64("ctime").extra({get type(){return this.mode>>12},get permission(){return this.mode&4095}}).postDeserialize(n=>{if(n.error)throw new Error(xn[n.error])});async function Yr(n,e,t){const s=await n.lock();try{if(t)return await G(s,O.LstatV2,e),await vn(s,N.Lstat2,Ls);{await G(s,O.Lstat,e);const i=await vn(s,N.Lstat,gi);return{mode:i.mode,size:BigInt(i.size),mtime:BigInt(i.mtime),get type(){return i.type},get permission(){return i.permission}}}}finally{s.release()}}async function Jr(n,e){const t=await n.lock();try{return await G(t,O.Stat,e),await vn(t,N.Stat,Ls)}finally{t.release()}}const Xr=new x({littleEndian:!0}).concat(gi).uint32("nameLength").string("name",{lengthField:"nameLength"}),Zr=new x({littleEndian:!0}).concat(Ls).uint32("nameLength").string("name",{lengthField:"nameLength"});async function*ea(n,e){const t=await n.lock();try{await G(t,O.ListV2,e);for await(const s of En(t,N.Entry2,Zr))s.error===xn.SUCCESS&&(yield s)}finally{t.release()}}async function*ta(n,e){const t=await n.lock();try{await G(t,O.List,e);for await(const s of En(t,N.Entry,Xr))yield s}finally{t.release()}}async function*na(n,e,t){if(t)yield*ea(n,e);else for await(const s of ta(n,e))yield{mode:s.mode,size:BigInt(s.size),mtime:BigInt(s.mtime),get type(){return s.type},get permission(){return s.permission},name:s.name}}const Ms=new x({littleEndian:!0}).uint32("dataLength").uint8Array("data",{lengthField:"dataLength"});async function*sa(n,e){const t=await n.lock();let s=!1;try{await G(t,O.Receive,e);for await(const i of En(t,N.Data,Ms))yield i.data;s=!0}catch(i){throw s=!0,i}finally{if(!s)for await(const i of En(t,N.Data,Ms));t.release()}}function ia(n,e){return new dt(async t=>{for await(const s of sa(n,e))await t.enqueue(s)})}const pi=64*1024,ra=new x({littleEndian:!0}).uint32("unused");async function fi(n,e,t,s){const i=new hn;e.pipeThrough(new Sr(t,!0)).pipeTo(new pe.WritableStream({write:async r=>{await G(n,O.Data,r)}}),{signal:i.signal}).then(async()=>{await G(n,O.Done,s),await n.flush()},ts),await vn(n,N.Ok,ra).catch(r=>{throw i.abort(),r})}async function aa({socket:n,filename:e,file:t,type:s=Sn.File,permission:i=438,mtime:r=Date.now()/1e3|0,packetSize:o=pi}){const c=await n.lock();try{const w=s<<12|i,d=`${e},${w.toString()}`;await G(c,O.Send,d),await fi(c,t,o,r)}finally{c.release()}}var Ln;(function(n){n[n.None=0]="None",n[n.Brotli=1]="Brotli",n[n.Lz4=2]="Lz4",n[n.Zstd=4]="Zstd",n[n.DryRun=2147483648]="DryRun"})(Ln||(Ln={}));const oa=new x({littleEndian:!0}).uint32("id").uint32("mode").uint32("flags",void 0);async function ca({socket:n,filename:e,file:t,type:s=Sn.File,permission:i=438,mtime:r=Date.now()/1e3|0,packetSize:o=pi,dryRun:c=!1}){const w=await n.lock();try{await G(w,O.SendV2,e);const d=s<<12|i;let p=Ln.None;c&&(p|=Ln.DryRun),await w.write(oa.serialize({id:O.SendV2,mode:d,flags:p})),await fi(w,t,o,r)}finally{w.release()}}function la(n){if(n.v2)return ca(n);if(n.dryRun)throw new Error("dryRun is not supported in v1");return aa(n)}var Pt,Pe,Ct,Ce,Ne,Nt,rs;class ua{constructor(e,t,s,i){l(this,Nt);l(this,Pt);l(this,Pe);l(this,Ct);l(this,Ce,new ci);l(this,Ne);u(this,Pt,e),u(this,Pe,t),u(this,Ct,i),u(this,Ne,new ai(s))}get position(){return a(this,Pe).position}async flush(){try{await a(this,Ce).wait();const e=a(this,Ne).flush();e&&await y(this,Nt,rs).call(this,e)}finally{a(this,Ce).notifyOne()}}async write(e){try{await a(this,Ce).wait();for(const t of a(this,Ne).push(e))await y(this,Nt,rs).call(this,t)}finally{a(this,Ce).notifyOne()}}async readExactly(e){return await this.flush(),await a(this,Pe).readExactly(e)}release(){a(this,Ne).flush(),a(this,Ct).notifyOne()}async close(){await a(this,Pe).cancel()}}Pt=new WeakMap,Pe=new WeakMap,Ct=new WeakMap,Ce=new WeakMap,Ne=new WeakMap,Nt=new WeakSet,rs=async function(e){await M.WritableStream.write(a(this,Pt),e)};var Bt,$t,ot;class ha{constructor(e,t){l(this,Bt,new ci);l(this,$t);l(this,ot);u(this,$t,e),u(this,ot,new ua(e.writable.getWriter(),new dn(e.readable),t,a(this,Bt)))}async lock(){return await a(this,Bt).wait(),a(this,ot)}async close(){await a(this,ot).close(),await a(this,$t).close()}}Bt=new WeakMap,$t=new WeakMap,ot=new WeakMap;function da(n){const e=n.lastIndexOf("/");if(e===-1)throw new Error("Invalid path");return e===0?"/":n.substring(0,e)}var Be,zt,Ot,Rt,qt;class wa extends Ss{constructor(t,s){super();g(this,"_adb");g(this,"_socket");l(this,Be);l(this,zt);l(this,Ot);l(this,Rt);l(this,qt);this._adb=t,this._socket=new ha(s,t.maxPayloadSize),u(this,Be,t.canUseFeature(m.StatV2)),u(this,zt,t.canUseFeature(m.ListV2)),u(this,Ot,t.canUseFeature(m.FixedPushMkdir)),u(this,Rt,t.canUseFeature(m.SendReceiveV2)),u(this,qt,this._adb.canUseFeature(m.ShellV2)&&!this.fixedPushMkdir)}get supportsStat(){return a(this,Be)}get supportsListV2(){return a(this,zt)}get fixedPushMkdir(){return a(this,Ot)}get supportsSendReceiveV2(){return a(this,Rt)}get needPushMkdirWorkaround(){return a(this,qt)}async lstat(t){return await Yr(this._socket,t,a(this,Be))}async stat(t){if(!a(this,Be))throw new Error("Not supported");return await Jr(this._socket,t)}async isDirectory(t){try{return await this.lstat(t+"/"),!0}catch{return!1}}opendir(t){return na(this._socket,t,this.supportsListV2)}async readdir(t){const s=[];for await(const i of this.opendir(t))s.push(i);return s}read(t){return ia(this._socket,t)}async write(t){this.needPushMkdirWorkaround&&await this._adb.subprocess.spawnAndWait(["mkdir","-p",is(da(t.filename))]),await la({v2:this.supportsSendReceiveV2,socket:this._socket,...t})}lockSocket(){return this._socket.lock()}async dispose(){super.dispose(),await this._socket.close()}}Be=new WeakMap,zt=new WeakMap,Ot=new WeakMap,Rt=new WeakMap,qt=new WeakMap;var _t,as;class ga extends xs{constructor(){super(...arguments);l(this,_t)}async getListenAddresses(){const t=await this.adb.getProp("service.adb.listen_addrs"),s=await this.adb.getProp("service.adb.tcp.port"),i=await this.adb.getProp("persist.adb.tcp.port");return{serviceListenAddresses:t!=""?t.split(","):[],servicePort:y(this,_t,as).call(this,s),persistPort:y(this,_t,as).call(this,i)}}async setPort(t){if(t<=0)throw new TypeError(`Invalid port ${t}`);const s=await this.adb.createSocketAndWait(`tcpip:${t}`);if(s!==`restarting in TCP mode port: ${t}
|
|
4
|
+
`).filter(i=>!!i).map(i=>{const[r,o,c]=i.split(" ");return{deviceSerial:r,localName:o,remoteName:c}})}async addExternal(t,s){const i=await this.sendRequest(`reverse:forward:${t};${s}`);if(t.startsWith("tcp:")){const r=i.position;try{const o=gt(await i.readExactly(4));t=`tcp:${Vr(await i.readExactly(o))}`}catch(o){if(!(o instanceof ms&&i.position===r))throw o}}return t}async add(t,s,i){i=await this.adb.transport.addReverseTunnel(s,i);try{return t=await this.addExternal(t,i),a(this,it).set(t,i),t}catch(r){throw await this.adb.transport.removeReverseTunnel(i),r}}async remove(t){const s=a(this,it).get(t);s&&await this.adb.transport.removeReverseTunnel(s),await this.sendRequest(`reverse:killforward:${t}`)}async removeAll(){await this.adb.transport.clearReverseTunnels(),a(this,it).clear(),await this.sendRequest("reverse:killforward-all")}}it=new WeakMap;var oe,xt,Lt;const Bn=class Bn{constructor(e){l(this,oe);l(this,xt);l(this,Lt);u(this,oe,e),u(this,xt,new Ve({start:t=>{a(this,oe).closed.then(()=>t.close()).catch(ui)}})),u(this,Lt,e.closed.then(()=>0))}static isSupported(){return!0}static async pty(e,t){return new Bn(await e.createSocket(`shell:${t}`))}static async raw(e,t){return new Bn(await e.createSocket(`exec:${t}`))}get stdin(){return a(this,oe).writable}get stdout(){return a(this,oe).readable}get stderr(){return a(this,xt)}get exit(){return a(this,Lt)}resize(){}async kill(){await a(this,oe).close()}};oe=new WeakMap,xt=new WeakMap,Lt=new WeakMap;let bn=Bn;var m;(function(n){n.ShellV2="shell_v2",n.Cmd="cmd",n.StatV2="stat_v2",n.ListV2="ls_v2",n.FixedPushMkdir="fixed_push_mkdir",n.Abb="abb",n.AbbExec="abb_exec",n.SendReceiveV2="sendrecv_v2",n.DelayedAck="delayed_ack"})(m||(m={}));var be;(function(n){n[n.Stdin=0]="Stdin",n[n.Stdout=1]="Stdout",n[n.Stderr=2]="Stderr",n[n.Exit=3]="Exit",n[n.CloseStdin=4]="CloseStdin",n[n.WindowSizeChange=5]="WindowSizeChange"})(be||(be={}));const jn=new x({littleEndian:!0}).uint8("id",void 0).uint32("length").uint8Array("data",{lengthField:"length"});var rt,at,kt,Tt,It,De;const $n=class $n{constructor(e){l(this,rt);l(this,at);l(this,kt);l(this,Tt);l(this,It);l(this,De,new P);u(this,rt,e);let t,s;u(this,Tt,new dt(i=>{t=i})),u(this,It,new dt(i=>{s=i})),e.readable.pipeThrough(new Dr(jn)).pipeTo(new J({write:async i=>{switch(i.id){case be.Exit:a(this,De).resolve(i.data[0]);break;case be.Stdout:t.abortSignal.aborted||await t.enqueue(i.data);break;case be.Stderr:s.abortSignal.aborted||await s.enqueue(i.data);break}}})).then(()=>{t.close(),s.close(),a(this,De).reject(new Error("Socket ended without exit message"))},i=>{t.error(i),s.error(i),a(this,De).reject(i)}),u(this,at,a(this,rt).writable.getWriter()),u(this,kt,new pe.WritableStream({write:async i=>{await a(this,at).write(jn.serialize({id:be.Stdin,data:i}))}}))}static isSupported(e){return e.canUseFeature(m.ShellV2)}static async pty(e,t){return new $n(await e.createSocket(`shell,v2,pty:${t}`))}static async raw(e,t){return new $n(await e.createSocket(`shell,v2,raw:${t}`))}get stdin(){return a(this,kt)}get stdout(){return a(this,Tt)}get stderr(){return a(this,It)}get exit(){return a(this,De).promise}async resize(e,t){await a(this,at).write(jn.serialize({id:be.WindowSizeChange,data:Y(`${e}x${t},0x0\0`)}))}kill(){return a(this,rt).close()}};rt=new WeakMap,at=new WeakMap,kt=new WeakMap,Tt=new WeakMap,It=new WeakMap,De=new WeakMap;let ns=$n;const Hr={protocols:[ns,bn]};var Dt,ss;class Kr extends xs{constructor(){super(...arguments);l(this,Dt)}shell(t,s){return y(this,Dt,ss).call(this,"pty",t,s)}spawn(t,s){return y(this,Dt,ss).call(this,"raw",t,s)}async spawnAndWait(t,s){const i=await this.spawn(t,s),[r,o,c]=await Promise.all([i.stdout.pipeThrough(new Zn).pipeThrough(new Xn),i.stderr.pipeThrough(new Zn).pipeThrough(new Xn),i.exit]);return{stdout:r,stderr:o,exitCode:c}}async spawnAndWaitLegacy(t){const{stdout:s}=await this.spawnAndWait(t,{protocols:[bn]});return s}}Dt=new WeakSet,ss=async function(t,s,i){const{protocols:r}={...Hr,...i};let o;for(const c of r)if(await c.isSupported(this.adb)){o=c;break}if(!o)throw new Error("No specified protocol is supported by the device");return Array.isArray(s)?s=s.join(" "):s===void 0&&(s=""),await o[t](this.adb,s)};function is(n){let e="";e+="'";let t=0;for(;;){const s=n.indexOf("'",t);if(s===-1){e+=n.substring(t);break}e+=n.substring(t,s),e+=String.raw`'\''`,t=s+1}return e+="'",e}function Qr(n){const e=new Uint8Array(n.length);for(let t=0;t<n.length;t+=1)e[t]=n.charCodeAt(t);return e}function v(n){const e=Qr(n);return Un(e,0)}var C;(function(n){n.Entry=v("DENT"),n.Entry2=v("DNT2"),n.Lstat=v("STAT"),n.Stat=v("STA2"),n.Lstat2=v("LST2"),n.Done=v("DONE"),n.Data=v("DATA"),n.Ok=v("OKAY"),n.Fail=v("FAIL")})(C||(C={}));class Gr extends Error{}const wi=new x({littleEndian:!0}).uint32("messageLength").string("message",{lengthField:"messageLength"}).postDeserialize(n=>{throw new Gr(n.message)});async function vn(n,e,t){typeof e=="string"&&(e=v(e));const s=await n.readExactly(4);switch(Un(s,0)){case C.Fail:throw await wi.deserialize(n),new Error("Unreachable");case e:return await t.deserialize(n);default:throw new Error(`Expected '${e}', but got '${We(s)}'`)}}async function*En(n,e,t){for(typeof e=="string"&&(e=v(e));;){const s=await n.readExactly(4);switch(Un(s,0)){case C.Fail:throw await wi.deserialize(n),new Error("Unreachable");case C.Done:await n.readExactly(t.size);return;case e:yield await t.deserialize(n);break;default:throw new Error(`Expected '${e}' or '${C.Done}', but got '${We(s)}'`)}}}var O;(function(n){n.List=v("LIST"),n.ListV2=v("LIS2"),n.Send=v("SEND"),n.SendV2=v("SND2"),n.Lstat=v("STAT"),n.Stat=v("STA2"),n.LstatV2=v("LST2"),n.Data=v("DATA"),n.Done=v("DONE"),n.Receive=v("RECV")})(O||(O={}));const Us=new x({littleEndian:!0}).uint32("id").uint32("arg");async function G(n,e,t){if(typeof e=="string"&&(e=v(e)),typeof t=="number"){await n.write(Us.serialize({id:e,arg:t}));return}typeof t=="string"&&(t=Y(t)),await n.write(Us.serialize({id:e,arg:t.length})),await n.write(t)}var Sn;(function(n){n[n.Directory=4]="Directory",n[n.File=8]="File",n[n.Link=10]="Link"})(Sn||(Sn={}));const gi=new x({littleEndian:!0}).int32("mode").int32("size").int32("mtime").extra({get type(){return this.mode>>12},get permission(){return this.mode&4095}}).postDeserialize(n=>{if(n.mode===0&&n.size===0&&n.mtime===0)throw new Error("lstat error")});var xn;(function(n){n[n.SUCCESS=0]="SUCCESS",n[n.EACCES=13]="EACCES",n[n.EEXIST=17]="EEXIST",n[n.EFAULT=14]="EFAULT",n[n.EFBIG=27]="EFBIG",n[n.EINTR=4]="EINTR",n[n.EINVAL=22]="EINVAL",n[n.EIO=5]="EIO",n[n.EISDIR=21]="EISDIR",n[n.ELOOP=40]="ELOOP",n[n.EMFILE=24]="EMFILE",n[n.ENAMETOOLONG=36]="ENAMETOOLONG",n[n.ENFILE=23]="ENFILE",n[n.ENOENT=2]="ENOENT",n[n.ENOMEM=12]="ENOMEM",n[n.ENOSPC=28]="ENOSPC",n[n.ENOTDIR=20]="ENOTDIR",n[n.EOVERFLOW=75]="EOVERFLOW",n[n.EPERM=1]="EPERM",n[n.EROFS=30]="EROFS",n[n.ETXTBSY=26]="ETXTBSY"})(xn||(xn={}));const Ls=new x({littleEndian:!0}).uint32("error",void 0).uint64("dev").uint64("ino").uint32("mode").uint32("nlink").uint32("uid").uint32("gid").uint64("size").uint64("atime").uint64("mtime").uint64("ctime").extra({get type(){return this.mode>>12},get permission(){return this.mode&4095}}).postDeserialize(n=>{if(n.error)throw new Error(xn[n.error])});async function Yr(n,e,t){const s=await n.lock();try{if(t)return await G(s,O.LstatV2,e),await vn(s,C.Lstat2,Ls);{await G(s,O.Lstat,e);const i=await vn(s,C.Lstat,gi);return{mode:i.mode,size:BigInt(i.size),mtime:BigInt(i.mtime),get type(){return i.type},get permission(){return i.permission}}}}finally{s.release()}}async function Jr(n,e){const t=await n.lock();try{return await G(t,O.Stat,e),await vn(t,C.Stat,Ls)}finally{t.release()}}const Xr=new x({littleEndian:!0}).concat(gi).uint32("nameLength").string("name",{lengthField:"nameLength"}),Zr=new x({littleEndian:!0}).concat(Ls).uint32("nameLength").string("name",{lengthField:"nameLength"});async function*ea(n,e){const t=await n.lock();try{await G(t,O.ListV2,e);for await(const s of En(t,C.Entry2,Zr))s.error===xn.SUCCESS&&(yield s)}finally{t.release()}}async function*ta(n,e){const t=await n.lock();try{await G(t,O.List,e);for await(const s of En(t,C.Entry,Xr))yield s}finally{t.release()}}async function*na(n,e,t){if(t)yield*ea(n,e);else for await(const s of ta(n,e))yield{mode:s.mode,size:BigInt(s.size),mtime:BigInt(s.mtime),get type(){return s.type},get permission(){return s.permission},name:s.name}}const Ms=new x({littleEndian:!0}).uint32("dataLength").uint8Array("data",{lengthField:"dataLength"});async function*sa(n,e){const t=await n.lock();let s=!1;try{await G(t,O.Receive,e);for await(const i of En(t,C.Data,Ms))yield i.data;s=!0}catch(i){throw s=!0,i}finally{if(!s)for await(const i of En(t,C.Data,Ms));t.release()}}function ia(n,e){return new dt(async t=>{for await(const s of sa(n,e))await t.enqueue(s)})}const pi=64*1024,ra=new x({littleEndian:!0}).uint32("unused");async function fi(n,e,t,s){const i=new hn;e.pipeThrough(new Sr(t,!0)).pipeTo(new pe.WritableStream({write:async r=>{await G(n,O.Data,r)}}),{signal:i.signal}).then(async()=>{await G(n,O.Done,s),await n.flush()},ts),await vn(n,C.Ok,ra).catch(r=>{throw i.abort(),r})}async function aa({socket:n,filename:e,file:t,type:s=Sn.File,permission:i=438,mtime:r=Date.now()/1e3|0,packetSize:o=pi}){const c=await n.lock();try{const w=s<<12|i,d=`${e},${w.toString()}`;await G(c,O.Send,d),await fi(c,t,o,r)}finally{c.release()}}var Ln;(function(n){n[n.None=0]="None",n[n.Brotli=1]="Brotli",n[n.Lz4=2]="Lz4",n[n.Zstd=4]="Zstd",n[n.DryRun=2147483648]="DryRun"})(Ln||(Ln={}));const oa=new x({littleEndian:!0}).uint32("id").uint32("mode").uint32("flags",void 0);async function ca({socket:n,filename:e,file:t,type:s=Sn.File,permission:i=438,mtime:r=Date.now()/1e3|0,packetSize:o=pi,dryRun:c=!1}){const w=await n.lock();try{await G(w,O.SendV2,e);const d=s<<12|i;let p=Ln.None;c&&(p|=Ln.DryRun),await w.write(oa.serialize({id:O.SendV2,mode:d,flags:p})),await fi(w,t,o,r)}finally{w.release()}}function la(n){if(n.v2)return ca(n);if(n.dryRun)throw new Error("dryRun is not supported in v1");return aa(n)}var Pt,Pe,Nt,Ne,Ce,Ct,rs;class ua{constructor(e,t,s,i){l(this,Ct);l(this,Pt);l(this,Pe);l(this,Nt);l(this,Ne,new ci);l(this,Ce);u(this,Pt,e),u(this,Pe,t),u(this,Nt,i),u(this,Ce,new ai(s))}get position(){return a(this,Pe).position}async flush(){try{await a(this,Ne).wait();const e=a(this,Ce).flush();e&&await y(this,Ct,rs).call(this,e)}finally{a(this,Ne).notifyOne()}}async write(e){try{await a(this,Ne).wait();for(const t of a(this,Ce).push(e))await y(this,Ct,rs).call(this,t)}finally{a(this,Ne).notifyOne()}}async readExactly(e){return await this.flush(),await a(this,Pe).readExactly(e)}release(){a(this,Ce).flush(),a(this,Nt).notifyOne()}async close(){await a(this,Pe).cancel()}}Pt=new WeakMap,Pe=new WeakMap,Nt=new WeakMap,Ne=new WeakMap,Ce=new WeakMap,Ct=new WeakSet,rs=async function(e){await M.WritableStream.write(a(this,Pt),e)};var Bt,$t,ot;class ha{constructor(e,t){l(this,Bt,new ci);l(this,$t);l(this,ot);u(this,$t,e),u(this,ot,new ua(e.writable.getWriter(),new dn(e.readable),t,a(this,Bt)))}async lock(){return await a(this,Bt).wait(),a(this,ot)}async close(){await a(this,ot).close(),await a(this,$t).close()}}Bt=new WeakMap,$t=new WeakMap,ot=new WeakMap;function da(n){const e=n.lastIndexOf("/");if(e===-1)throw new Error("Invalid path");return e===0?"/":n.substring(0,e)}var Be,zt,Ot,Rt,qt;class wa extends Ss{constructor(t,s){super();g(this,"_adb");g(this,"_socket");l(this,Be);l(this,zt);l(this,Ot);l(this,Rt);l(this,qt);this._adb=t,this._socket=new ha(s,t.maxPayloadSize),u(this,Be,t.canUseFeature(m.StatV2)),u(this,zt,t.canUseFeature(m.ListV2)),u(this,Ot,t.canUseFeature(m.FixedPushMkdir)),u(this,Rt,t.canUseFeature(m.SendReceiveV2)),u(this,qt,this._adb.canUseFeature(m.ShellV2)&&!this.fixedPushMkdir)}get supportsStat(){return a(this,Be)}get supportsListV2(){return a(this,zt)}get fixedPushMkdir(){return a(this,Ot)}get supportsSendReceiveV2(){return a(this,Rt)}get needPushMkdirWorkaround(){return a(this,qt)}async lstat(t){return await Yr(this._socket,t,a(this,Be))}async stat(t){if(!a(this,Be))throw new Error("Not supported");return await Jr(this._socket,t)}async isDirectory(t){try{return await this.lstat(t+"/"),!0}catch{return!1}}opendir(t){return na(this._socket,t,this.supportsListV2)}async readdir(t){const s=[];for await(const i of this.opendir(t))s.push(i);return s}read(t){return ia(this._socket,t)}async write(t){this.needPushMkdirWorkaround&&await this._adb.subprocess.spawnAndWait(["mkdir","-p",is(da(t.filename))]),await la({v2:this.supportsSendReceiveV2,socket:this._socket,...t})}lockSocket(){return this._socket.lock()}async dispose(){super.dispose(),await this._socket.close()}}Be=new WeakMap,zt=new WeakMap,Ot=new WeakMap,Rt=new WeakMap,qt=new WeakMap;var At,as;class ga extends xs{constructor(){super(...arguments);l(this,At)}async getListenAddresses(){const t=await this.adb.getProp("service.adb.listen_addrs"),s=await this.adb.getProp("service.adb.tcp.port"),i=await this.adb.getProp("persist.adb.tcp.port");return{serviceListenAddresses:t!=""?t.split(","):[],servicePort:y(this,At,as).call(this,s),persistPort:y(this,At,as).call(this,i)}}async setPort(t){if(t<=0)throw new TypeError(`Invalid port ${t}`);const s=await this.adb.createSocketAndWait(`tcpip:${t}`);if(s!==`restarting in TCP mode port: ${t}
|
|
5
5
|
`)throw new Error(s);return s}async disable(){const t=await this.adb.createSocketAndWait("usb:");if(t!==`restarting in USB mode
|
|
6
|
-
`)throw new Error(t);return t}}_t=new WeakSet,as=function(t){if(!(!t||t==="0"))return Number.parseInt(t,10)};class pa{constructor(e){g(this,"transport");g(this,"subprocess");g(this,"power");g(this,"reverse");g(this,"tcpip");this.transport=e,this.subprocess=new Kr(this),this.power=new Rr(this),this.reverse=new jr(this),this.tcpip=new ga(this)}get serial(){return this.transport.serial}get maxPayloadSize(){return this.transport.maxPayloadSize}get banner(){return this.transport.banner}get disconnected(){return this.transport.disconnected}get clientFeatures(){return this.transport.clientFeatures}get deviceFeatures(){return this.banner.features}canUseFeature(e){return this.clientFeatures.includes(e)&&this.deviceFeatures.includes(e)}async createSocket(e){return this.transport.connect(e)}async createSocketAndWait(e){return await(await this.createSocket(e)).readable.pipeThrough(new Zn).pipeThrough(new Xn)}async getProp(e){return(await this.subprocess.spawnAndWaitLegacy(["getprop",e])).trim()}async rm(e,t){const s=["rm"];if(t!=null&&t.recursive&&s.push("-r"),t!=null&&t.force&&s.push("-f"),Array.isArray(e))for(const r of e)s.push(is(r));else s.push(is(e));return s.push("</dev/null"),await this.subprocess.spawnAndWaitLegacy(s)}async sync(){const e=await this.createSocket("sync:");return new wa(this,e)}async framebuffer(){return Or(this)}async close(){await this.transport.close()}}var je;(function(n){n.Product="ro.product.name",n.Model="ro.product.model",n.Device="ro.product.device",n.Features="features"})(je||(je={}));var At,Ut,Mt,Wt;const Ns=class Ns{constructor(e,t,s,i){l(this,At);l(this,Ut);l(this,Mt);l(this,Wt,[]);u(this,At,e),u(this,Ut,t),u(this,Mt,s),u(this,Wt,i)}static parse(e){let t,s,i,r=[];const o=e.split("::");if(o.length>1){const c=o[1];for(const w of c.split(";")){if(!w)continue;const d=w.split("=");if(d.length!==2)continue;const[p,b]=d;switch(p){case je.Product:t=b;break;case je.Model:s=b;break;case je.Device:i=b;break;case je.Features:r=b.split(",");break}}}return new Ns(t,s,i,r)}get product(){return a(this,At)}get model(){return a(this,Ut)}get device(){return a(this,Mt)}get features(){return a(this,Wt)}};At=new WeakMap,Ut=new WeakMap,Mt=new WeakMap,Wt=new WeakMap;let kn=Ns;function os(n,e,t){let s=0n;for(let i=e;i<e+t;i+=8){s<<=64n;const r=er(n,i);s|=r}return s}function cs(n,e,t,s,i){if(i)for(;s>0n;)Hi(n,e,s),e+=8,s>>=64n;else{let r=e+t-8;for(;s>0n;)Ki(n,r,s),r-=8,s>>=64n}}const fa=38,ya=2048/8,ma=303,ba=2048/8;function yi(n){const e=os(n,fa,ya),t=os(n,ma,ba);return[e,t]}function Ws(n,e){const t=n%e;return t>0?t:t+e}function va(n,e){if(n=Ws(n,e),!n||e<2)return NaN;const t=[];let s=e;for(;s;)[n,s]=[s,n%s],t.push({a:n,b:s});if(n!==1)return NaN;let i=1,r=0;for(let o=t.length-2;o>=0;o-=1)[i,r]=[r,i-r*Math.floor(t[o].a/t[o].b)];return Ws(r,e)}const Ee=2048/8,Ea=Ee/4;function mi(){return 8+Ee+Ee+4}function Sa(n,e){let t;const s=mi();if(!e)e=new Uint8Array(s),t="Uint8Array";else{if(e.length<s)throw new TypeError("output buffer is too small");t="number"}const i=new DataView(e.buffer,e.byteOffset,e.length);let r=0;i.setUint32(r,Ea,!0),r+=4;const[o]=yi(n),c=-va(Number(o%2n**32n),2**32);i.setInt32(r,c,!0),r+=4,cs(e,r,Ee,o,!0),r+=Ee;const w=2n**4096n%o;return cs(e,r,Ee,w,!0),r+=Ee,i.setUint32(r,65537,!0),r+=4,t==="Uint8Array"?e:s}function xa(n,e,t){if(t===1n)return 0n;let s=1n;for(n=n%t;e>0n;)BigInt.asUintN(1,e)===1n&&(s=s*n%t),n=n*n%t,e>>=1n;return s}const Vs=20,Fs=48,La=4,ka=5,Ta=6,Hn=new Uint8Array([Fs,13+Vs,Fs,9,Ta,5,43,14,3,2,26,ka,0,La,Vs]);function Ia(n,e){const[t,s]=yi(n),i=new Uint8Array(256);let r=0;i[r]=0,r+=1,i[r]=1,r+=1;const o=i.length-Hn.length-e.length-1;for(;r<o;)i[r]=255,r+=1;i[r]=0,r+=1,i.set(Hn,r),r+=Hn.length,i.set(e,r);const c=xa(os(i,0,i.length),s,t);return cs(i,0,i.length,c,!1),i}var L;(function(n){n[n.Auth=1213486401]="Auth",n[n.Close=1163086915]="Close",n[n.Connect=1314410051]="Connect",n[n.Okay=1497451343]="Okay",n[n.Open=1313165391]="Open",n[n.Write=1163154007]="Write"})(L||(L={}));const Tn=new x({littleEndian:!0}).uint32("command").uint32("arg0").uint32("arg1").uint32("payloadLength").uint32("checksum").int32("magic");new x({littleEndian:!0}).concat(Tn).uint8Array("payload",{lengthField:"payloadLength"});function bi(n){return n.reduce((e,t)=>e+t,0)}class Da extends Es{constructor(){const e=new Uint8Array(Tn.size);super({transform:async(t,s)=>{await t.tryConsume(async i=>{const r=i;r.payloadLength=r.payload.length,await M.ReadableStream.enqueue(s,Tn.serialize(r,e)),r.payloadLength&&await M.ReadableStream.enqueue(s,r.payload)})}})}}var wt;(function(n){n[n.Token=1]="Token",n[n.Signature=2]="Signature",n[n.PublicKey=3]="PublicKey"})(wt||(wt={}));const Pa=async function*(n,e){for await(const t of n.iterateKeys()){const s=await e();if(s.arg0!==wt.Token)return;const i=Ia(t.buffer,s.payload);yield{command:L.Auth,arg0:wt.Signature,arg1:0,payload:i}}},Ca=async function*(n,e){var w;if((await e()).arg0!==wt.Token)return;let s;for await(const d of n.iterateKeys()){s=d;break}s||(s=await n.generateKey());const i=mi(),[r]=li(i),o=(w=s.name)!=null&&w.length?Y(s.name):Q,c=new Uint8Array(r+(o.length?o.length+1:0)+1);Sa(s.buffer,c),qr(c.subarray(0,i),c),o.length&&(c[r]=32,c.set(o,r+1)),yield{command:L.Auth,arg0:wt.PublicKey,arg1:0,payload:c}},Na=[Pa,Ca];var Vt,ct,$e,zn,On,vi;class Ba{constructor(e,t){l(this,On);g(this,"authenticators");l(this,Vt);l(this,ct,new P);l(this,$e);l(this,zn,()=>a(this,ct).promise);this.authenticators=e,u(this,Vt,t)}async process(e){a(this,$e)||u(this,$e,y(this,On,vi).call(this)),a(this,ct).resolve(e);const t=await a(this,$e).next();if(t.done)throw new Error("No authenticator can handle the request");return t.value}dispose(){var e,t;(t=(e=a(this,$e))==null?void 0:e.return)==null||t.call(e)}}Vt=new WeakMap,ct=new WeakMap,$e=new WeakMap,zn=new WeakMap,On=new WeakSet,vi=async function*(){for(const e of this.authenticators)for await(const t of e(a(this,Vt),a(this,zn)))u(this,ct,new P),yield t};var ze,Ft,ce,jt,Ht,Kt,Qt,Oe,ie,Rn,Ei;class js{constructor(e){l(this,Rn);l(this,ze);g(this,"localId");g(this,"remoteId");g(this,"localCreated");g(this,"service");l(this,Ft);l(this,ce);l(this,jt);g(this,"writable");l(this,Ht,!1);l(this,Kt,new P);l(this,Qt);l(this,Oe);l(this,ie,0);u(this,ze,e.dispatcher),this.localId=e.localId,this.remoteId=e.remoteId,this.localCreated=e.localCreated,this.service=e.service,u(this,Ft,new dt(t=>{u(this,ce,t)})),this.writable=new pe.WritableStream({start:t=>{u(this,jt,t),t.signal.addEventListener("abort",()=>{var s;(s=a(this,Oe))==null||s.reject(t.signal.reason)})},write:async t=>{const s=t.length,i=a(this,ze).options.maxPayloadSize;for(let r=0,o=i;r<s;r=o,o+=i){const c=t.subarray(r,o);await y(this,Rn,Ei).call(this,c)}}}),u(this,Qt,new $a(this)),u(this,ie,e.availableWriteBytes)}get readable(){return a(this,Ft)}get closed(){return a(this,Kt).promise}get socket(){return a(this,Qt)}async enqueue(e){if(!a(this,ce).abortSignal.aborted)try{await a(this,ce).enqueue(e)}catch(t){if(a(this,ce).abortSignal.aborted)return;throw t}}ack(e){var t;u(this,ie,a(this,ie)+e),(t=a(this,Oe))==null||t.resolve()}async close(){var e;if(!a(this,Ht)){u(this,Ht,!0),(e=a(this,Oe))==null||e.reject(new Error("Socket closed"));try{a(this,jt).error(new Error("Socket closed"))}catch{}await a(this,ze).sendPacket(L.Close,this.localId,this.remoteId,Q)}}dispose(){try{a(this,ce).close()}catch{}a(this,Kt).resolve()}}ze=new WeakMap,Ft=new WeakMap,ce=new WeakMap,jt=new WeakMap,Ht=new WeakMap,Kt=new WeakMap,Qt=new WeakMap,Oe=new WeakMap,ie=new WeakMap,Rn=new WeakSet,Ei=async function(e){const t=e.length;for(;a(this,ie)<t;){const s=new P;u(this,Oe,s),await s.promise}a(this,ie)===1/0?u(this,ie,-1):u(this,ie,a(this,ie)-t),await a(this,ze).sendPacket(L.Write,this.localId,this.remoteId,e)};var _;class $a{constructor(e){l(this,_);u(this,_,e)}get localId(){return a(this,_).localId}get remoteId(){return a(this,_).remoteId}get localCreated(){return a(this,_).localCreated}get service(){return a(this,_).service}get readable(){return a(this,_).readable}get writable(){return a(this,_).writable}get closed(){return a(this,_).closed}close(){return a(this,_).close()}}_=new WeakMap;var le,j,Re,Gt,lt,qe,Yt,I,Si,xi,ls,Li,ki,us;class za{constructor(e,t){l(this,I);l(this,le,new fr(1));l(this,j,new Map);l(this,Re);g(this,"options");l(this,Gt,!1);l(this,lt,new P);l(this,qe,new Map);l(this,Yt,new hn);this.options=t,this.options.initialDelayedAckBytes<0&&(this.options.initialDelayedAckBytes=0),e.readable.pipeTo(new J({write:async s=>{switch(s.command){case L.Close:await y(this,I,Si).call(this,s);break;case L.Okay:y(this,I,xi).call(this,s);break;case L.Open:await y(this,I,Li).call(this,s);break;case L.Write:await y(this,I,ki).call(this,s);break;default:throw new Error(`Unknown command: ${s.command.toString(16)}`)}}}),{preventCancel:t.preserveConnection??!1,signal:a(this,Yt).signal}).then(()=>{y(this,I,us).call(this)},s=>{a(this,Gt)||a(this,lt).reject(s),y(this,I,us).call(this)}),u(this,Re,e.writable.getWriter())}get disconnected(){return a(this,lt).promise}async createSocket(e){this.options.appendNullToServiceString&&(e+="\0");const[t,s]=a(this,le).add();await this.sendPacket(L.Open,t,this.options.initialDelayedAckBytes,e);const{remoteId:i,availableWriteBytes:r}=await s,o=new js({dispatcher:this,localId:t,remoteId:i,localCreated:!0,service:e,availableWriteBytes:r});return a(this,j).set(t,o),o.socket}addReverseTunnel(e,t){a(this,qe).set(e,t)}removeReverseTunnel(e){a(this,qe).delete(e)}clearReverseTunnels(){a(this,qe).clear()}async sendPacket(e,t,s,i){if(typeof i=="string"&&(i=Y(i)),i.length>this.options.maxPayloadSize)throw new TypeError("payload too large");await M.WritableStream.write(a(this,Re),{command:e,arg0:t,arg1:s,payload:i,checksum:this.options.calculateChecksum?bi(i):0,magic:e^4294967295})}async close(){await Promise.all(Array.from(a(this,j).values(),e=>e.close())),u(this,Gt,!0),a(this,Yt).abort(),this.options.preserveConnection?a(this,Re).releaseLock():await a(this,Re).close()}}le=new WeakMap,j=new WeakMap,Re=new WeakMap,Gt=new WeakMap,lt=new WeakMap,qe=new WeakMap,Yt=new WeakMap,I=new WeakSet,Si=async function(e){if(e.arg0===0&&a(this,le).reject(e.arg1,new Error("Socket open failed")))return;const t=a(this,j).get(e.arg1);if(t){await t.close(),t.dispose(),a(this,j).delete(e.arg1);return}},xi=function(e){let t;if(this.options.initialDelayedAckBytes!==0){if(e.payload.length!==4)throw new Error("Invalid OKAY packet. Payload size should be 4");t=Un(e.payload,0)}else{if(e.payload.length!==0)throw new Error("Invalid OKAY packet. Payload size should be 0");t=1/0}if(a(this,le).resolve(e.arg1,{remoteId:e.arg0,availableWriteBytes:t}))return;const s=a(this,j).get(e.arg1);if(s){s.ack(t);return}this.sendPacket(L.Close,e.arg1,e.arg0,Q)},ls=function(e,t,s){let i;return this.options.initialDelayedAckBytes!==0?(i=new Uint8Array(4),Xi(i,0,s)):i=Q,this.sendPacket(L.Okay,e,t,i)},Li=async function(e){const[t]=a(this,le).add();a(this,le).resolve(t,void 0);const s=e.arg0;let i=e.arg1,r=We(e.payload);if(r.endsWith("\0")&&(r=r.substring(0,r.length-1)),this.options.initialDelayedAckBytes===0){if(i!==0)throw new Error("Invalid OPEN packet. arg1 should be 0");i=1/0}else if(i===0)throw new Error("Invalid OPEN packet. arg1 should be greater than 0");const o=a(this,qe).get(r);if(!o){await this.sendPacket(L.Close,0,s,Q);return}const c=new js({dispatcher:this,localId:t,remoteId:s,localCreated:!1,service:r,availableWriteBytes:i});try{await o(c.socket),a(this,j).set(t,c),await y(this,I,ls).call(this,t,s,this.options.initialDelayedAckBytes)}catch{await this.sendPacket(L.Close,0,s,Q)}},ki=async function(e){const t=a(this,j).get(e.arg1);if(!t)throw new Error(`Unknown local socket id: ${e.arg1}`);let s=!1;const i=[(async()=>{await t.enqueue(e.payload),await y(this,I,ls).call(this,e.arg1,e.arg0,e.payload.length),s=!0})()];this.options.readTimeLimit&&i.push((async()=>{if(await yr(this.options.readTimeLimit),!s)throw new Error(`readable of \`${t.service}\` has stalled for ${this.options.readTimeLimit} milliseconds`)})()),await Promise.race(i)},us=function(){for(const e of a(this,j).values())e.dispose();a(this,lt).resolve()};const Oa=16777217,Hs=[m.ShellV2,m.Cmd,m.StatV2,m.ListV2,m.FixedPushMkdir,"apex",m.Abb,"fixed_push_symlink_timestamp",m.AbbExec,"remount_shell","track_app",m.SendReceiveV2,"sendrecv_v2_brotli","sendrecv_v2_lz4","sendrecv_v2_zstd","sendrecv_v2_dry_run_send",m.DelayedAck],Ra=32*1024*1024;var Jt,H,Xt,Zt,ut,en;const Bs=class Bs{constructor({serial:e,connection:t,version:s,banner:i,features:r=Hs,initialDelayedAckBytes:o,...c}){l(this,Jt);l(this,H);l(this,Xt);l(this,Zt);l(this,ut);l(this,en);if(u(this,Xt,e),u(this,Jt,t),u(this,ut,kn.parse(i)),u(this,en,r),r.includes(m.DelayedAck)){if(o<=0)throw new TypeError("`initialDelayedAckBytes` must be greater than 0 when DelayedAck feature is enabled.");a(this,ut).features.includes(m.DelayedAck)||(o=0)}else o=0;let w,d;s>=Oa?(w=!1,d=!1):(w=!0,d=!0),u(this,H,new za(t,{calculateChecksum:w,appendNullToServiceString:d,initialDelayedAckBytes:o,...c})),u(this,Zt,s)}static async authenticate({serial:e,connection:t,credentialStore:s,authenticators:i=Na,features:r=Hs,initialDelayedAckBytes:o=Ra,...c}){let w=16777217,d=1024*1024;const p=new P,b=new Ba(i,s),E=new hn,K=t.readable.pipeTo(new J({async write(T){switch(T.command){case L.Connect:w=Math.min(w,T.arg0),d=Math.min(d,T.arg1),p.resolve(We(T.payload));break;case L.Auth:{const _i=await b.process(T);await $s(_i);break}}}}),{preventCancel:!0,signal:E.signal}).then(()=>{p.reject(new Error("Connection closed unexpectedly"))},T=>{p.reject(T)}),gn=t.writable.getWriter();async function $s(T){T.checksum=bi(T.payload),T.magic=T.command^4294967295,await M.WritableStream.write(gn,T)}const Wn=r.slice();if(o<=0){const T=r.indexOf(m.DelayedAck);T!==-1&&Wn.splice(T,1)}let zs;try{await $s({command:L.Connect,arg0:w,arg1:d,payload:Y(`host::features=${Wn.join(",")}`)}),zs=await p.promise}finally{E.abort(),gn.releaseLock(),await K}return new Bs({serial:e,connection:t,version:w,maxPayloadSize:d,banner:zs,features:Wn,initialDelayedAckBytes:o,...c})}get connection(){return a(this,Jt)}get serial(){return a(this,Xt)}get protocolVersion(){return a(this,Zt)}get maxPayloadSize(){return a(this,H).options.maxPayloadSize}get banner(){return a(this,ut)}get disconnected(){return a(this,H).disconnected}get clientFeatures(){return a(this,en)}connect(e){return a(this,H).createSocket(e)}addReverseTunnel(e,t){return t||(t=`localabstract:reverse_${Math.random().toString().substring(2)}`),a(this,H).addReverseTunnel(t,e),t}removeReverseTunnel(e){a(this,H).removeReverseTunnel(e)}clearReverseTunnels(){a(this,H).clearReverseTunnels()}close(){return a(this,H).close()}};Jt=new WeakMap,H=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,ut=new WeakMap,en=new WeakMap;let hs=Bs;const qa=[m.ShellV2,m.Cmd,m.StatV2,m.ListV2,m.FixedPushMkdir,"apex",m.Abb,"fixed_push_symlink_timestamp",m.AbbExec,"remount_shell","track_app",m.SendReceiveV2,"sendrecv_v2_brotli","sendrecv_v2_lz4","sendrecv_v2_zstd","sendrecv_v2_dry_run_send"];var ue,tn,nn;class _a{constructor(e,t,s,i){l(this,ue);g(this,"serial");g(this,"transportId");g(this,"maxPayloadSize",1*1024*1024);g(this,"banner");l(this,tn,new P);l(this,nn,new hn);g(this,"disconnected");u(this,ue,e),this.serial=t,this.banner=s,this.transportId=i,this.disconnected=Promise.race([a(this,tn).promise,e.waitFor({transportId:i},"disconnect",{signal:a(this,nn).signal,unref:!0})])}get clientFeatures(){return qa}async connect(e){return await a(this,ue).createDeviceConnection({transportId:this.transportId},e)}async addReverseTunnel(e,t){return await a(this,ue).connector.addReverseTunnel(e,t)}async removeReverseTunnel(e){await a(this,ue).connector.removeReverseTunnel(e)}async clearReverseTunnels(){await a(this,ue).connector.clearReverseTunnels()}close(){a(this,tn).resolve(),a(this,nn).abort()}}ue=new WeakMap,tn=new WeakMap,nn=new WeakMap;const Aa=Y("OKAY"),Ti=Y("FAIL");var he,_e,Ae;class Ks{constructor(e){l(this,he);l(this,_e);l(this,Ae);u(this,he,e),u(this,_e,new dn(e.readable)),u(this,Ae,e.writable.getWriter())}readExactly(e){return a(this,_e).readExactly(e)}readString(){return re.try(()=>this.readExactly(4)).then(e=>{const t=gt(e);return t===0?Q:this.readExactly(t)}).then(e=>We(e)).valueOrPromise()}async writeString(e){const t=Y(e),s=new Uint8Array(4+t.length);Ur(s,0,t.length),s.set(t,4),await a(this,Ae).write(s)}async readOkay(){const e=await this.readExactly(4);if(!mn(e,Aa)){if(mn(e,Ti)){const t=await this.readString();throw new Error(t)}throw new Error(`Unexpected response: ${We(e)}`)}}release(){return a(this,Ae).releaseLock(),{readable:a(this,_e).release(),writable:a(this,he).writable,closed:a(this,he).closed,close:()=>a(this,he).close()}}async dispose(){await a(this,_e).cancel().catch(ts),await a(this,Ae).close().catch(ts);try{await a(this,he).close()}catch{}}}he=new WeakMap,_e=new WeakMap,Ae=new WeakMap;const ve=class ve{constructor(e){g(this,"connector");g(this,"wireless",new ve.WirelessCommands(this));g(this,"mDns",new ve.MDnsCommands(this));this.connector=e}async createConnection(e,t){const s=await this.connector.connect(t),i=new Ks(s);try{await i.writeString(e)}catch(r){throw await i.dispose(),r}try{return await Qs(()=>i.readOkay(),t==null?void 0:t.signal),i}catch(r){throw await i.dispose(),r}}async getVersion(){const e=await this.createConnection("host:version");try{const t=gt(await e.readExactly(4));return gt(await e.readExactly(t))}finally{await e.dispose()}}async validateVersion(){const e=await this.getVersion();if(e!==ve.VERSION)throw new Error(`adb server version (${e}) doesn't match this client (${ve.VERSION})`)}async killServer(){await(await this.createConnection("host:kill")).dispose()}async getServerFeatures(){const e=await this.createConnection("host:host-features");try{return(await e.readString()).split(",")}finally{await e.dispose()}}parseDeviceList(e){const t=[];for(const s of e.split(`
|
|
7
|
-
`)){if(!s)continue;const i=s.split(" ").filter(Boolean),r=i[0],o=i[1];if(o!=="device"&&o!=="unauthorized")continue;let c,w,d,p;for(let b=2;b<i.length;b+=1){const[E,K]=i[b].split(":");switch(E){case"product":c=K;break;case"model":w=K;break;case"device":d=K;break;case"transport_id":p=BigInt(K);break}}if(!p)throw new Error(`No transport id for device ${r}`);t.push({serial:r,authenticating:o==="unauthorized",product:c,model:w,device:d,transportId:p})}return t}async getDevices(){const e=await this.createConnection("host:devices-l");try{const t=await e.readString();return this.parseDeviceList(t)}finally{await e.dispose()}}async*trackDevices(e){const t=await this.createConnection("host:track-devices-l");try{for(;;){const s=await Qs(async()=>await t.readString(),e);yield this.parseDeviceList(s)}}catch(s){if(s===(e==null?void 0:e.reason))return}finally{await t.dispose()}}formatDeviceService(e,t){if(!e)return`host:${t}`;if("transportId"in e)return`host-transport-id:${e.transportId}:${t}`;if("serial"in e)return`host-serial:${e.serial}:${t}`;if("usb"in e)return`host-usb:${t}`;if("tcp"in e)return`host-local:${t}`;throw new TypeError("Invalid device selector")}async reconnectDevice(e){const t=await this.createConnection(e==="offline"?"host:reconnect-offline":this.formatDeviceService(e,"reconnect"));try{await t.readString()}finally{await t.dispose()}}async getDeviceFeatures(e){const t=await this.createDeviceConnection(e,"host:features"),s=new Ks(t);try{const r=(await s.readString()).split(",");return{transportId:t.transportId,features:r}}finally{await s.dispose()}}async createDeviceConnection(e,t){await this.validateVersion();let s,i;if(!e)s="host:tport:any";else if("transportId"in e)s=`host:transport-id:${e.transportId}`,i=e.transportId;else if("serial"in e)s=`host:tport:serial:${e.serial}`;else if("usb"in e)s="host:tport:usb";else if("tcp"in e)s="host:tport:local";else throw new TypeError("Invalid device selector");const r=await this.createConnection(s);try{await r.writeString(t)}catch(o){throw await r.dispose(),o}try{if(i===void 0){const c=await r.readExactly(8);i=Zi(c,0)}await r.readOkay();const o=r.release();return{transportId:i,service:t,readable:o.readable,writable:new es(o.writable).bePipedThroughFrom(new pe.UnwrapStream),get closed(){return o.closed},async close(){await o.close()}}}catch(o){throw await r.dispose(),o}}async waitFor(e,t,s){let i;if(!e)i="any";else if("transportId"in e)i="any";else if("serial"in e)i="any";else if("usb"in e)i="usb";else if("tcp"in e)i="local";else throw new TypeError("Invalid device selector");const r=this.formatDeviceService(e,`wait-for-${i}-${t}`),o=await this.createConnection(r,s);try{await o.readOkay()}finally{await o.dispose()}}async createTransport(e){const{transportId:t,features:s}=await this.getDeviceFeatures(e),r=(await this.getDevices()).find(c=>c.transportId===t),o=new kn(r==null?void 0:r.product,r==null?void 0:r.model,r==null?void 0:r.device,s);return new
|
|
8
|
-
`).filter(Boolean).map(b=>{const E=b.split(" ");return{name:E[0],service:E[1],address:E[2]}})}finally{await d.dispose()}}}c=new WeakMap,n.MDnsCommands=r})(In||(In={}));function Ii(n,e){return typeof n=="object"&&n!==null&&"name"in n&&n.name===e}function Ua(n,e){return e.some(t=>n.interfaceClass===t.classCode&&n.interfaceSubclass===t.subclassCode&&n.interfaceProtocol===t.protocolCode)}function Di(n,e){for(const t of n.configurations)for(const s of t.interfaces)for(const i of s.alternates)if(Ua(i,e))return{configuration:t,interface_:s,alternate:i};throw new TypeError("No matched alternate interface found")}function Gs(n){return n.toString(16).padStart(4,"0")}function Pi(n){return n.serialNumber?n.serialNumber:Gs(n.vendorId)+"x"+Gs(n.productId)}const ds={classCode:255,subclassCode:66,protocolCode:1};function Ma(n){if(n.length===0)throw new TypeError("No endpoints given");let e,t;for(const s of n)switch(s.direction){case"in":if(e=s,t)return{inEndpoint:e,outEndpoint:t};break;case"out":if(t=s,e)return{inEndpoint:e,outEndpoint:t};break}throw e?t?new Error("unreachable"):new TypeError("No output endpoint found."):new TypeError("No input endpoint found.")}var sn,de;class Wa{constructor(e){l(this,sn);l(this,de);u(this,sn,e),u(this,de,0)}get position(){return a(this,de)}readExactly(e){const t=a(this,sn).subarray(a(this,de),a(this,de)+e);return u(this,de,a(this,de)+e),t}}sn=new WeakMap,de=new WeakMap;var Ue,we,rn,an,on,qn,
|
|
6
|
+
`)throw new Error(t);return t}}At=new WeakSet,as=function(t){if(!(!t||t==="0"))return Number.parseInt(t,10)};class pa{constructor(e){g(this,"transport");g(this,"subprocess");g(this,"power");g(this,"reverse");g(this,"tcpip");this.transport=e,this.subprocess=new Kr(this),this.power=new Rr(this),this.reverse=new jr(this),this.tcpip=new ga(this)}get serial(){return this.transport.serial}get maxPayloadSize(){return this.transport.maxPayloadSize}get banner(){return this.transport.banner}get disconnected(){return this.transport.disconnected}get clientFeatures(){return this.transport.clientFeatures}get deviceFeatures(){return this.banner.features}canUseFeature(e){return this.clientFeatures.includes(e)&&this.deviceFeatures.includes(e)}async createSocket(e){return this.transport.connect(e)}async createSocketAndWait(e){return await(await this.createSocket(e)).readable.pipeThrough(new Zn).pipeThrough(new Xn)}async getProp(e){return(await this.subprocess.spawnAndWaitLegacy(["getprop",e])).trim()}async rm(e,t){const s=["rm"];if(t!=null&&t.recursive&&s.push("-r"),t!=null&&t.force&&s.push("-f"),Array.isArray(e))for(const r of e)s.push(is(r));else s.push(is(e));return s.push("</dev/null"),await this.subprocess.spawnAndWaitLegacy(s)}async sync(){const e=await this.createSocket("sync:");return new wa(this,e)}async framebuffer(){return Or(this)}async close(){await this.transport.close()}}var je;(function(n){n.Product="ro.product.name",n.Model="ro.product.model",n.Device="ro.product.device",n.Features="features"})(je||(je={}));var _t,Ut,Mt,Wt;const Cs=class Cs{constructor(e,t,s,i){l(this,_t);l(this,Ut);l(this,Mt);l(this,Wt,[]);u(this,_t,e),u(this,Ut,t),u(this,Mt,s),u(this,Wt,i)}static parse(e){let t,s,i,r=[];const o=e.split("::");if(o.length>1){const c=o[1];for(const w of c.split(";")){if(!w)continue;const d=w.split("=");if(d.length!==2)continue;const[p,b]=d;switch(p){case je.Product:t=b;break;case je.Model:s=b;break;case je.Device:i=b;break;case je.Features:r=b.split(",");break}}}return new Cs(t,s,i,r)}get product(){return a(this,_t)}get model(){return a(this,Ut)}get device(){return a(this,Mt)}get features(){return a(this,Wt)}};_t=new WeakMap,Ut=new WeakMap,Mt=new WeakMap,Wt=new WeakMap;let kn=Cs;function os(n,e,t){let s=0n;for(let i=e;i<e+t;i+=8){s<<=64n;const r=er(n,i);s|=r}return s}function cs(n,e,t,s,i){if(i)for(;s>0n;)Hi(n,e,s),e+=8,s>>=64n;else{let r=e+t-8;for(;s>0n;)Ki(n,r,s),r-=8,s>>=64n}}const fa=38,ya=2048/8,ma=303,ba=2048/8;function yi(n){const e=os(n,fa,ya),t=os(n,ma,ba);return[e,t]}function Ws(n,e){const t=n%e;return t>0?t:t+e}function va(n,e){if(n=Ws(n,e),!n||e<2)return NaN;const t=[];let s=e;for(;s;)[n,s]=[s,n%s],t.push({a:n,b:s});if(n!==1)return NaN;let i=1,r=0;for(let o=t.length-2;o>=0;o-=1)[i,r]=[r,i-r*Math.floor(t[o].a/t[o].b)];return Ws(r,e)}const Ee=2048/8,Ea=Ee/4;function mi(){return 8+Ee+Ee+4}function Sa(n,e){let t;const s=mi();if(!e)e=new Uint8Array(s),t="Uint8Array";else{if(e.length<s)throw new TypeError("output buffer is too small");t="number"}const i=new DataView(e.buffer,e.byteOffset,e.length);let r=0;i.setUint32(r,Ea,!0),r+=4;const[o]=yi(n),c=-va(Number(o%2n**32n),2**32);i.setInt32(r,c,!0),r+=4,cs(e,r,Ee,o,!0),r+=Ee;const w=2n**4096n%o;return cs(e,r,Ee,w,!0),r+=Ee,i.setUint32(r,65537,!0),r+=4,t==="Uint8Array"?e:s}function xa(n,e,t){if(t===1n)return 0n;let s=1n;for(n=n%t;e>0n;)BigInt.asUintN(1,e)===1n&&(s=s*n%t),n=n*n%t,e>>=1n;return s}const Vs=20,Fs=48,La=4,ka=5,Ta=6,Hn=new Uint8Array([Fs,13+Vs,Fs,9,Ta,5,43,14,3,2,26,ka,0,La,Vs]);function Ia(n,e){const[t,s]=yi(n),i=new Uint8Array(256);let r=0;i[r]=0,r+=1,i[r]=1,r+=1;const o=i.length-Hn.length-e.length-1;for(;r<o;)i[r]=255,r+=1;i[r]=0,r+=1,i.set(Hn,r),r+=Hn.length,i.set(e,r);const c=xa(os(i,0,i.length),s,t);return cs(i,0,i.length,c,!1),i}var L;(function(n){n[n.Auth=1213486401]="Auth",n[n.Close=1163086915]="Close",n[n.Connect=1314410051]="Connect",n[n.Okay=1497451343]="Okay",n[n.Open=1313165391]="Open",n[n.Write=1163154007]="Write"})(L||(L={}));const Tn=new x({littleEndian:!0}).uint32("command").uint32("arg0").uint32("arg1").uint32("payloadLength").uint32("checksum").int32("magic");new x({littleEndian:!0}).concat(Tn).uint8Array("payload",{lengthField:"payloadLength"});function bi(n){return n.reduce((e,t)=>e+t,0)}class Da extends Es{constructor(){const e=new Uint8Array(Tn.size);super({transform:async(t,s)=>{await t.tryConsume(async i=>{const r=i;r.payloadLength=r.payload.length,await M.ReadableStream.enqueue(s,Tn.serialize(r,e)),r.payloadLength&&await M.ReadableStream.enqueue(s,r.payload)})}})}}var wt;(function(n){n[n.Token=1]="Token",n[n.Signature=2]="Signature",n[n.PublicKey=3]="PublicKey"})(wt||(wt={}));const Pa=async function*(n,e){for await(const t of n.iterateKeys()){const s=await e();if(s.arg0!==wt.Token)return;const i=Ia(t.buffer,s.payload);yield{command:L.Auth,arg0:wt.Signature,arg1:0,payload:i}}},Na=async function*(n,e){var w;if((await e()).arg0!==wt.Token)return;let s;for await(const d of n.iterateKeys()){s=d;break}s||(s=await n.generateKey());const i=mi(),[r]=li(i),o=(w=s.name)!=null&&w.length?Y(s.name):Q,c=new Uint8Array(r+(o.length?o.length+1:0)+1);Sa(s.buffer,c),qr(c.subarray(0,i),c),o.length&&(c[r]=32,c.set(o,r+1)),yield{command:L.Auth,arg0:wt.PublicKey,arg1:0,payload:c}},Ca=[Pa,Na];var Vt,ct,$e,zn,On,vi;class Ba{constructor(e,t){l(this,On);g(this,"authenticators");l(this,Vt);l(this,ct,new P);l(this,$e);l(this,zn,()=>a(this,ct).promise);this.authenticators=e,u(this,Vt,t)}async process(e){a(this,$e)||u(this,$e,y(this,On,vi).call(this)),a(this,ct).resolve(e);const t=await a(this,$e).next();if(t.done)throw new Error("No authenticator can handle the request");return t.value}dispose(){var e,t;(t=(e=a(this,$e))==null?void 0:e.return)==null||t.call(e)}}Vt=new WeakMap,ct=new WeakMap,$e=new WeakMap,zn=new WeakMap,On=new WeakSet,vi=async function*(){for(const e of this.authenticators)for await(const t of e(a(this,Vt),a(this,zn)))u(this,ct,new P),yield t};var ze,Ft,ce,jt,Ht,Kt,Qt,Oe,ie,Rn,Ei;class js{constructor(e){l(this,Rn);l(this,ze);g(this,"localId");g(this,"remoteId");g(this,"localCreated");g(this,"service");l(this,Ft);l(this,ce);l(this,jt);g(this,"writable");l(this,Ht,!1);l(this,Kt,new P);l(this,Qt);l(this,Oe);l(this,ie,0);u(this,ze,e.dispatcher),this.localId=e.localId,this.remoteId=e.remoteId,this.localCreated=e.localCreated,this.service=e.service,u(this,Ft,new dt(t=>{u(this,ce,t)})),this.writable=new pe.WritableStream({start:t=>{u(this,jt,t),t.signal.addEventListener("abort",()=>{var s;(s=a(this,Oe))==null||s.reject(t.signal.reason)})},write:async t=>{const s=t.length,i=a(this,ze).options.maxPayloadSize;for(let r=0,o=i;r<s;r=o,o+=i){const c=t.subarray(r,o);await y(this,Rn,Ei).call(this,c)}}}),u(this,Qt,new $a(this)),u(this,ie,e.availableWriteBytes)}get readable(){return a(this,Ft)}get closed(){return a(this,Kt).promise}get socket(){return a(this,Qt)}async enqueue(e){if(!a(this,ce).abortSignal.aborted)try{await a(this,ce).enqueue(e)}catch(t){if(a(this,ce).abortSignal.aborted)return;throw t}}ack(e){var t;u(this,ie,a(this,ie)+e),(t=a(this,Oe))==null||t.resolve()}async close(){var e;if(!a(this,Ht)){u(this,Ht,!0),(e=a(this,Oe))==null||e.reject(new Error("Socket closed"));try{a(this,jt).error(new Error("Socket closed"))}catch{}await a(this,ze).sendPacket(L.Close,this.localId,this.remoteId,Q)}}dispose(){try{a(this,ce).close()}catch{}a(this,Kt).resolve()}}ze=new WeakMap,Ft=new WeakMap,ce=new WeakMap,jt=new WeakMap,Ht=new WeakMap,Kt=new WeakMap,Qt=new WeakMap,Oe=new WeakMap,ie=new WeakMap,Rn=new WeakSet,Ei=async function(e){const t=e.length;for(;a(this,ie)<t;){const s=new P;u(this,Oe,s),await s.promise}a(this,ie)===1/0?u(this,ie,-1):u(this,ie,a(this,ie)-t),await a(this,ze).sendPacket(L.Write,this.localId,this.remoteId,e)};var A;class $a{constructor(e){l(this,A);u(this,A,e)}get localId(){return a(this,A).localId}get remoteId(){return a(this,A).remoteId}get localCreated(){return a(this,A).localCreated}get service(){return a(this,A).service}get readable(){return a(this,A).readable}get writable(){return a(this,A).writable}get closed(){return a(this,A).closed}close(){return a(this,A).close()}}A=new WeakMap;var le,j,Re,Gt,lt,qe,Yt,I,Si,xi,ls,Li,ki,us;class za{constructor(e,t){l(this,I);l(this,le,new fr(1));l(this,j,new Map);l(this,Re);g(this,"options");l(this,Gt,!1);l(this,lt,new P);l(this,qe,new Map);l(this,Yt,new hn);this.options=t,this.options.initialDelayedAckBytes<0&&(this.options.initialDelayedAckBytes=0),e.readable.pipeTo(new J({write:async s=>{switch(s.command){case L.Close:await y(this,I,Si).call(this,s);break;case L.Okay:y(this,I,xi).call(this,s);break;case L.Open:await y(this,I,Li).call(this,s);break;case L.Write:await y(this,I,ki).call(this,s);break;default:throw new Error(`Unknown command: ${s.command.toString(16)}`)}}}),{preventCancel:t.preserveConnection??!1,signal:a(this,Yt).signal}).then(()=>{y(this,I,us).call(this)},s=>{a(this,Gt)||a(this,lt).reject(s),y(this,I,us).call(this)}),u(this,Re,e.writable.getWriter())}get disconnected(){return a(this,lt).promise}async createSocket(e){this.options.appendNullToServiceString&&(e+="\0");const[t,s]=a(this,le).add();await this.sendPacket(L.Open,t,this.options.initialDelayedAckBytes,e);const{remoteId:i,availableWriteBytes:r}=await s,o=new js({dispatcher:this,localId:t,remoteId:i,localCreated:!0,service:e,availableWriteBytes:r});return a(this,j).set(t,o),o.socket}addReverseTunnel(e,t){a(this,qe).set(e,t)}removeReverseTunnel(e){a(this,qe).delete(e)}clearReverseTunnels(){a(this,qe).clear()}async sendPacket(e,t,s,i){if(typeof i=="string"&&(i=Y(i)),i.length>this.options.maxPayloadSize)throw new TypeError("payload too large");await M.WritableStream.write(a(this,Re),{command:e,arg0:t,arg1:s,payload:i,checksum:this.options.calculateChecksum?bi(i):0,magic:e^4294967295})}async close(){await Promise.all(Array.from(a(this,j).values(),e=>e.close())),u(this,Gt,!0),a(this,Yt).abort(),this.options.preserveConnection?a(this,Re).releaseLock():await a(this,Re).close()}}le=new WeakMap,j=new WeakMap,Re=new WeakMap,Gt=new WeakMap,lt=new WeakMap,qe=new WeakMap,Yt=new WeakMap,I=new WeakSet,Si=async function(e){if(e.arg0===0&&a(this,le).reject(e.arg1,new Error("Socket open failed")))return;const t=a(this,j).get(e.arg1);if(t){await t.close(),t.dispose(),a(this,j).delete(e.arg1);return}},xi=function(e){let t;if(this.options.initialDelayedAckBytes!==0){if(e.payload.length!==4)throw new Error("Invalid OKAY packet. Payload size should be 4");t=Un(e.payload,0)}else{if(e.payload.length!==0)throw new Error("Invalid OKAY packet. Payload size should be 0");t=1/0}if(a(this,le).resolve(e.arg1,{remoteId:e.arg0,availableWriteBytes:t}))return;const s=a(this,j).get(e.arg1);if(s){s.ack(t);return}this.sendPacket(L.Close,e.arg1,e.arg0,Q)},ls=function(e,t,s){let i;return this.options.initialDelayedAckBytes!==0?(i=new Uint8Array(4),Xi(i,0,s)):i=Q,this.sendPacket(L.Okay,e,t,i)},Li=async function(e){const[t]=a(this,le).add();a(this,le).resolve(t,void 0);const s=e.arg0;let i=e.arg1,r=We(e.payload);if(r.endsWith("\0")&&(r=r.substring(0,r.length-1)),this.options.initialDelayedAckBytes===0){if(i!==0)throw new Error("Invalid OPEN packet. arg1 should be 0");i=1/0}else if(i===0)throw new Error("Invalid OPEN packet. arg1 should be greater than 0");const o=a(this,qe).get(r);if(!o){await this.sendPacket(L.Close,0,s,Q);return}const c=new js({dispatcher:this,localId:t,remoteId:s,localCreated:!1,service:r,availableWriteBytes:i});try{await o(c.socket),a(this,j).set(t,c),await y(this,I,ls).call(this,t,s,this.options.initialDelayedAckBytes)}catch{await this.sendPacket(L.Close,0,s,Q)}},ki=async function(e){const t=a(this,j).get(e.arg1);if(!t)throw new Error(`Unknown local socket id: ${e.arg1}`);let s=!1;const i=[(async()=>{await t.enqueue(e.payload),await y(this,I,ls).call(this,e.arg1,e.arg0,e.payload.length),s=!0})()];this.options.readTimeLimit&&i.push((async()=>{if(await yr(this.options.readTimeLimit),!s)throw new Error(`readable of \`${t.service}\` has stalled for ${this.options.readTimeLimit} milliseconds`)})()),await Promise.race(i)},us=function(){for(const e of a(this,j).values())e.dispose();a(this,lt).resolve()};const Oa=16777217,Hs=[m.ShellV2,m.Cmd,m.StatV2,m.ListV2,m.FixedPushMkdir,"apex",m.Abb,"fixed_push_symlink_timestamp",m.AbbExec,"remount_shell","track_app",m.SendReceiveV2,"sendrecv_v2_brotli","sendrecv_v2_lz4","sendrecv_v2_zstd","sendrecv_v2_dry_run_send",m.DelayedAck],Ra=32*1024*1024;var Jt,H,Xt,Zt,ut,en;const Bs=class Bs{constructor({serial:e,connection:t,version:s,banner:i,features:r=Hs,initialDelayedAckBytes:o,...c}){l(this,Jt);l(this,H);l(this,Xt);l(this,Zt);l(this,ut);l(this,en);if(u(this,Xt,e),u(this,Jt,t),u(this,ut,kn.parse(i)),u(this,en,r),r.includes(m.DelayedAck)){if(o<=0)throw new TypeError("`initialDelayedAckBytes` must be greater than 0 when DelayedAck feature is enabled.");a(this,ut).features.includes(m.DelayedAck)||(o=0)}else o=0;let w,d;s>=Oa?(w=!1,d=!1):(w=!0,d=!0),u(this,H,new za(t,{calculateChecksum:w,appendNullToServiceString:d,initialDelayedAckBytes:o,...c})),u(this,Zt,s)}static async authenticate({serial:e,connection:t,credentialStore:s,authenticators:i=Ca,features:r=Hs,initialDelayedAckBytes:o=Ra,...c}){let w=16777217,d=1024*1024;const p=new P,b=new Ba(i,s),E=new hn,K=t.readable.pipeTo(new J({async write(T){switch(T.command){case L.Connect:w=Math.min(w,T.arg0),d=Math.min(d,T.arg1),p.resolve(We(T.payload));break;case L.Auth:{const Ai=await b.process(T);await $s(Ai);break}}}}),{preventCancel:!0,signal:E.signal}).then(()=>{p.reject(new Error("Connection closed unexpectedly"))},T=>{p.reject(T)}),gn=t.writable.getWriter();async function $s(T){T.checksum=bi(T.payload),T.magic=T.command^4294967295,await M.WritableStream.write(gn,T)}const Wn=r.slice();if(o<=0){const T=r.indexOf(m.DelayedAck);T!==-1&&Wn.splice(T,1)}let zs;try{await $s({command:L.Connect,arg0:w,arg1:d,payload:Y(`host::features=${Wn.join(",")}`)}),zs=await p.promise}finally{E.abort(),gn.releaseLock(),await K}return new Bs({serial:e,connection:t,version:w,maxPayloadSize:d,banner:zs,features:Wn,initialDelayedAckBytes:o,...c})}get connection(){return a(this,Jt)}get serial(){return a(this,Xt)}get protocolVersion(){return a(this,Zt)}get maxPayloadSize(){return a(this,H).options.maxPayloadSize}get banner(){return a(this,ut)}get disconnected(){return a(this,H).disconnected}get clientFeatures(){return a(this,en)}connect(e){return a(this,H).createSocket(e)}addReverseTunnel(e,t){return t||(t=`localabstract:reverse_${Math.random().toString().substring(2)}`),a(this,H).addReverseTunnel(t,e),t}removeReverseTunnel(e){a(this,H).removeReverseTunnel(e)}clearReverseTunnels(){a(this,H).clearReverseTunnels()}close(){return a(this,H).close()}};Jt=new WeakMap,H=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,ut=new WeakMap,en=new WeakMap;let hs=Bs;const qa=[m.ShellV2,m.Cmd,m.StatV2,m.ListV2,m.FixedPushMkdir,"apex",m.Abb,"fixed_push_symlink_timestamp",m.AbbExec,"remount_shell","track_app",m.SendReceiveV2,"sendrecv_v2_brotli","sendrecv_v2_lz4","sendrecv_v2_zstd","sendrecv_v2_dry_run_send"];var ue,tn,nn;class Aa{constructor(e,t,s,i){l(this,ue);g(this,"serial");g(this,"transportId");g(this,"maxPayloadSize",1*1024*1024);g(this,"banner");l(this,tn,new P);l(this,nn,new hn);g(this,"disconnected");u(this,ue,e),this.serial=t,this.banner=s,this.transportId=i,this.disconnected=Promise.race([a(this,tn).promise,e.waitFor({transportId:i},"disconnect",{signal:a(this,nn).signal,unref:!0})])}get clientFeatures(){return qa}async connect(e){return await a(this,ue).createDeviceConnection({transportId:this.transportId},e)}async addReverseTunnel(e,t){return await a(this,ue).connector.addReverseTunnel(e,t)}async removeReverseTunnel(e){await a(this,ue).connector.removeReverseTunnel(e)}async clearReverseTunnels(){await a(this,ue).connector.clearReverseTunnels()}close(){a(this,tn).resolve(),a(this,nn).abort()}}ue=new WeakMap,tn=new WeakMap,nn=new WeakMap;const _a=Y("OKAY"),Ti=Y("FAIL");var he,Ae,_e;class Ks{constructor(e){l(this,he);l(this,Ae);l(this,_e);u(this,he,e),u(this,Ae,new dn(e.readable)),u(this,_e,e.writable.getWriter())}readExactly(e){return a(this,Ae).readExactly(e)}readString(){return re.try(()=>this.readExactly(4)).then(e=>{const t=gt(e);return t===0?Q:this.readExactly(t)}).then(e=>We(e)).valueOrPromise()}async writeString(e){const t=Y(e),s=new Uint8Array(4+t.length);Ur(s,0,t.length),s.set(t,4),await a(this,_e).write(s)}async readOkay(){const e=await this.readExactly(4);if(!mn(e,_a)){if(mn(e,Ti)){const t=await this.readString();throw new Error(t)}throw new Error(`Unexpected response: ${We(e)}`)}}release(){return a(this,_e).releaseLock(),{readable:a(this,Ae).release(),writable:a(this,he).writable,closed:a(this,he).closed,close:()=>a(this,he).close()}}async dispose(){await a(this,Ae).cancel().catch(ts),await a(this,_e).close().catch(ts);try{await a(this,he).close()}catch{}}}he=new WeakMap,Ae=new WeakMap,_e=new WeakMap;const ve=class ve{constructor(e){g(this,"connector");g(this,"wireless",new ve.WirelessCommands(this));g(this,"mDns",new ve.MDnsCommands(this));this.connector=e}async createConnection(e,t){const s=await this.connector.connect(t),i=new Ks(s);try{await i.writeString(e)}catch(r){throw await i.dispose(),r}try{return await Qs(()=>i.readOkay(),t==null?void 0:t.signal),i}catch(r){throw await i.dispose(),r}}async getVersion(){const e=await this.createConnection("host:version");try{const t=gt(await e.readExactly(4));return gt(await e.readExactly(t))}finally{await e.dispose()}}async validateVersion(){const e=await this.getVersion();if(e!==ve.VERSION)throw new Error(`adb server version (${e}) doesn't match this client (${ve.VERSION})`)}async killServer(){await(await this.createConnection("host:kill")).dispose()}async getServerFeatures(){const e=await this.createConnection("host:host-features");try{return(await e.readString()).split(",")}finally{await e.dispose()}}parseDeviceList(e){const t=[];for(const s of e.split(`
|
|
7
|
+
`)){if(!s)continue;const i=s.split(" ").filter(Boolean),r=i[0],o=i[1];if(o!=="device"&&o!=="unauthorized")continue;let c,w,d,p;for(let b=2;b<i.length;b+=1){const[E,K]=i[b].split(":");switch(E){case"product":c=K;break;case"model":w=K;break;case"device":d=K;break;case"transport_id":p=BigInt(K);break}}if(!p)throw new Error(`No transport id for device ${r}`);t.push({serial:r,authenticating:o==="unauthorized",product:c,model:w,device:d,transportId:p})}return t}async getDevices(){const e=await this.createConnection("host:devices-l");try{const t=await e.readString();return this.parseDeviceList(t)}finally{await e.dispose()}}async*trackDevices(e){const t=await this.createConnection("host:track-devices-l");try{for(;;){const s=await Qs(async()=>await t.readString(),e);yield this.parseDeviceList(s)}}catch(s){if(s===(e==null?void 0:e.reason))return}finally{await t.dispose()}}formatDeviceService(e,t){if(!e)return`host:${t}`;if("transportId"in e)return`host-transport-id:${e.transportId}:${t}`;if("serial"in e)return`host-serial:${e.serial}:${t}`;if("usb"in e)return`host-usb:${t}`;if("tcp"in e)return`host-local:${t}`;throw new TypeError("Invalid device selector")}async reconnectDevice(e){const t=await this.createConnection(e==="offline"?"host:reconnect-offline":this.formatDeviceService(e,"reconnect"));try{await t.readString()}finally{await t.dispose()}}async getDeviceFeatures(e){const t=await this.createDeviceConnection(e,"host:features"),s=new Ks(t);try{const r=(await s.readString()).split(",");return{transportId:t.transportId,features:r}}finally{await s.dispose()}}async createDeviceConnection(e,t){await this.validateVersion();let s,i;if(!e)s="host:tport:any";else if("transportId"in e)s=`host:transport-id:${e.transportId}`,i=e.transportId;else if("serial"in e)s=`host:tport:serial:${e.serial}`;else if("usb"in e)s="host:tport:usb";else if("tcp"in e)s="host:tport:local";else throw new TypeError("Invalid device selector");const r=await this.createConnection(s);try{await r.writeString(t)}catch(o){throw await r.dispose(),o}try{if(i===void 0){const c=await r.readExactly(8);i=Zi(c,0)}await r.readOkay();const o=r.release();return{transportId:i,service:t,readable:o.readable,writable:new es(o.writable).bePipedThroughFrom(new pe.UnwrapStream),get closed(){return o.closed},async close(){await o.close()}}}catch(o){throw await r.dispose(),o}}async waitFor(e,t,s){let i;if(!e)i="any";else if("transportId"in e)i="any";else if("serial"in e)i="any";else if("usb"in e)i="usb";else if("tcp"in e)i="local";else throw new TypeError("Invalid device selector");const r=this.formatDeviceService(e,`wait-for-${i}-${t}`),o=await this.createConnection(r,s);try{await o.readOkay()}finally{await o.dispose()}}async createTransport(e){const{transportId:t,features:s}=await this.getDeviceFeatures(e),r=(await this.getDevices()).find(c=>c.transportId===t),o=new kn(r==null?void 0:r.product,r==null?void 0:r.model,r==null?void 0:r.device,s);return new Aa(this,(r==null?void 0:r.serial)??"",o,t)}};g(ve,"VERSION",41);let In=ve;async function Qs(n,...e){const t=new P;function s(){t.reject(this.reason)}try{for(const i of e)if(i){if(i.aborted)throw i.reason;i.addEventListener("abort",s)}return await Promise.race([n(),t.promise])}finally{for(const i of e)i&&i.removeEventListener("abort",s)}}(function(n){var o,c;class e extends Error{constructor(d){super(d),this.name="NetworkError"}}n.NetworkError=e;class t extends Error{constructor(d){super(d),this.name="UnauthorizedError"}}n.UnauthorizedError=t;class s extends Error{constructor(d){super(d),this.name="AlreadyConnectedError"}}n.AlreadyConnectedError=s;class i{constructor(d){l(this,o);u(this,o,d)}async pair(d,p){const b=await a(this,o).createConnection(`host:pair:${p}:${d}`);try{const E=await b.readExactly(4);if(mn(E,Ti))throw new Error(await b.readString());const K=gt(E);await b.readExactly(K)}finally{await b.dispose()}}async connect(d){const p=await a(this,o).createConnection(`host:connect:${d}`);try{const b=await p.readString();switch(b){case`already connected to ${d}`:throw new n.AlreadyConnectedError(b);case`failed to connect to ${d}`:case`failed to authenticate to ${d}`:throw new n.UnauthorizedError(b);case`connected to ${d}`:return;default:throw new n.NetworkError(b)}}finally{await p.dispose()}}async disconnect(d){const p=await a(this,o).createConnection(`host:disconnect:${d}`);try{await p.readString()}finally{await p.dispose()}}}o=new WeakMap,n.WirelessCommands=i;class r{constructor(d){l(this,c);u(this,c,d)}async check(){const d=await a(this,c).createConnection("host:mdns:check");try{return!(await d.readString()).startsWith("ERROR:")}finally{await d.dispose()}}async getServices(){const d=await a(this,c).createConnection("host:mdns:services");try{return(await d.readString()).split(`
|
|
8
|
+
`).filter(Boolean).map(b=>{const E=b.split(" ");return{name:E[0],service:E[1],address:E[2]}})}finally{await d.dispose()}}}c=new WeakMap,n.MDnsCommands=r})(In||(In={}));function Ii(n,e){return typeof n=="object"&&n!==null&&"name"in n&&n.name===e}function Ua(n,e){return e.some(t=>n.interfaceClass===t.classCode&&n.interfaceSubclass===t.subclassCode&&n.interfaceProtocol===t.protocolCode)}function Di(n,e){for(const t of n.configurations)for(const s of t.interfaces)for(const i of s.alternates)if(Ua(i,e))return{configuration:t,interface_:s,alternate:i};throw new TypeError("No matched alternate interface found")}function Gs(n){return n.toString(16).padStart(4,"0")}function Pi(n){return n.serialNumber?n.serialNumber:Gs(n.vendorId)+"x"+Gs(n.productId)}const ds={classCode:255,subclassCode:66,protocolCode:1};function Ma(n){if(n.length===0)throw new TypeError("No endpoints given");let e,t;for(const s of n)switch(s.direction){case"in":if(e=s,t)return{inEndpoint:e,outEndpoint:t};break;case"out":if(t=s,e)return{inEndpoint:e,outEndpoint:t};break}throw e?t?new Error("unreachable"):new TypeError("No output endpoint found."):new TypeError("No input endpoint found.")}var sn,de;class Wa{constructor(e){l(this,sn);l(this,de);u(this,sn,e),u(this,de,0)}get position(){return a(this,de)}readExactly(e){const t=a(this,sn).subarray(a(this,de),a(this,de)+e);return u(this,de,a(this,de)+e),t}}sn=new WeakMap,de=new WeakMap;var Ue,we,rn,an,on,qn,Ni;class Va{constructor(e,t,s,i){l(this,qn);l(this,Ue);l(this,we);l(this,rn);l(this,an);l(this,on);u(this,Ue,e),u(this,we,t),u(this,rn,s);let r=!1;const o=new kr({close:async()=>{try{r=!0,await e.raw.close()}catch{}},dispose:()=>{r=!0,i.removeEventListener("disconnect",c)}});function c(d){d.device===e.raw&&o.dispose().catch(ui)}i.addEventListener("disconnect",c),u(this,an,o.wrapReadable(new Ve({pull:async d=>{const p=await y(this,qn,Ni).call(this);p?d.enqueue(p):d.close()}},{highWaterMark:0})));const w=s.packetSize-1;u(this,on,Ir(o.createWritable(new pe.WritableStream({write:async d=>{try{await e.raw.transferOut(s.endpointNumber,d),w&&(d.length&w)===0&&await e.raw.transferOut(s.endpointNumber,Q)}catch(p){if(r)return;throw p}}})),new Da))}get device(){return a(this,Ue)}get inEndpoint(){return a(this,we)}get outEndpoint(){return a(this,rn)}get readable(){return a(this,an)}get writable(){return a(this,on)}}Ue=new WeakMap,we=new WeakMap,rn=new WeakMap,an=new WeakMap,on=new WeakMap,qn=new WeakSet,Ni=async function(){try{for(;;){const e=await a(this,Ue).raw.transferIn(a(this,we).endpointNumber,a(this,we).packetSize);if(e.data.byteLength!==24)continue;const t=new Uint8Array(e.data.buffer),s=new Wa(t),i=Tn.deserialize(s);if(i.magic===(i.command^4294967295)){if(i.payloadLength!==0){const r=await a(this,Ue).raw.transferIn(a(this,we).endpointNumber,i.payloadLength);i.payload=new Uint8Array(r.data.buffer)}else i.payload=Q;return i}}}catch(e){if(Ii(e,"NetworkError")){if(await new Promise(t=>{setTimeout(()=>{t()},100)}),closed)return;throw e}throw e}};var cn,ln,B,un,An,Ci;class Ys{constructor(e,t=[ds],s){l(this,An);l(this,cn);l(this,ln);l(this,B);l(this,un);u(this,B,e),u(this,un,Pi(e)),u(this,cn,t),u(this,ln,s)}get raw(){return a(this,B)}get serial(){return a(this,un)}get name(){return a(this,B).productName}async connect(){const[e,t]=await y(this,An,Ci).call(this);return new Va(this,e,t,a(this,ln))}}cn=new WeakMap,ln=new WeakMap,B=new WeakMap,un=new WeakMap,An=new WeakSet,Ci=async function(){var o;a(this,B).opened||await a(this,B).open();const{configuration:e,interface_:t,alternate:s}=Di(a(this,B),a(this,cn));((o=a(this,B).configuration)==null?void 0:o.configurationValue)!==e.configurationValue&&await a(this,B).selectConfiguration(e.configurationValue),t.claimed||await a(this,B).claimInterface(t.interfaceNumber),t.alternate.alternateSetting!==s.alternateSetting&&await a(this,B).selectAlternateInterface(t.interfaceNumber,s.alternateSetting);const{inEndpoint:i,outEndpoint:r}=Ma(s.endpoints);return[i,r]};var ge;const _n=class _n{constructor(e){l(this,ge);u(this,ge,e)}async requestDevice(e={}){if(!e.filters)e.filters=[ds];else if(e.filters.length===0)throw new TypeError("filters must not be empty");try{const t=await a(this,ge).requestDevice(e);return new Ys(t,e.filters,a(this,ge))}catch(t){if(Ii(t,"NotFoundError"))return;throw t}}async getDevices(e=[ds]){if(e.length===0)throw new TypeError("filters must not be empty");return(await a(this,ge).getDevices()).filter(s=>{for(const i of e)if(!("vendorId"in i&&s.vendorId!==i.vendorId)&&!("productId"in i&&s.productId!==i.productId)&&!("serialNumber"in i&&Pi(s)!==i.serialNumber))try{return Di(s,e),!0}catch{continue}return!1}).map(s=>new Ys(s,e,a(this,ge)))}};ge=new WeakMap,g(_n,"BROWSER",typeof globalThis.navigator<"u"&&globalThis.navigator.usb?new _n(globalThis.navigator.usb):void 0);let ws=_n;function Bi(){return new Promise((n,e)=>{const t=indexedDB.open("Tango",1);t.onerror=()=>{e(t.error)},t.onupgradeneeded=()=>{t.result.createObjectStore("Authentication",{autoIncrement:!0})},t.onsuccess=()=>{const s=t.result;n(s)}})}async function Fa(n){const e=await Bi();return new Promise((t,s)=>{const i=e.transaction("Authentication","readwrite"),o=i.objectStore("Authentication").add(n);o.onerror=()=>{s(o.error)},o.onsuccess=()=>{t()},i.onerror=()=>{s(i.error)},i.oncomplete=()=>{e.close()}})}async function ja(){const n=await Bi();return new Promise((e,t)=>{const s=n.transaction("Authentication","readonly"),r=s.objectStore("Authentication").getAll();r.onerror=()=>{t(r.error)},r.onsuccess=()=>{e(r.result)},s.onerror=()=>{t(s.error)},s.oncomplete=()=>{n.close()}})}var ht;class Ha{constructor(e="Tango"){l(this,ht);u(this,ht,e)}async generateKey(){const{privateKey:e}=await crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:"SHA-1"},!0,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("pkcs8",e));return await Fa(t),{buffer:t,name:`${a(this,ht)}@${globalThis.location.hostname}`}}async*iterateKeys(){for(const e of await ja())yield{buffer:e,name:`${a(this,ht)}@${globalThis.location.hostname}`}}}ht=new WeakMap;const Fe=ws.BROWSER,Ka=new Ha;class Qa{constructor(){this.adb=null,this.device=null,this.packageName="",this.dbName="",this.dbPath="",this.sqlite3Path="",this.mode="webusb",this.bridgeUrl="",this.bridgeSerial=""}async connectBridge(e=15555){const t=[];(location.hostname==="127.0.0.1"||location.hostname==="localhost")&&t.push(location.origin),t.push(`http://127.0.0.1:${e}`);const i=new Set;for(const r of t)if(!i.has(r)){i.add(r);try{if((await(await fetch(`${r}/api/ping`,{signal:AbortSignal.timeout(2e3)})).json()).ok)return this.mode="bridge",this.bridgeUrl=r,!0}catch{}}return!1}async _bridgeShell(e){const t=await fetch(`${this.bridgeUrl}/api/shell`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({command:e,serial:this.bridgeSerial||void 0})}),s=await t.json();if(!t.ok)throw new Error(s.error||"Bridge shell command failed");return(s.output||"").replace(/\r\n/g,`
|
|
9
9
|
`).trimEnd()}async _bridgeGetDevices(){const e=await fetch(`${this.bridgeUrl}/api/devices`),t=await e.json();if(!e.ok)throw new Error(t.error||"Bridge devices request failed");return t.devices||[]}async requestDevice(){if(!Fe)throw new Error("WebUSB is not supported in this browser. Use Chrome or Edge.");const e=await Fe.requestDevice();if(!e)throw new Error("No device selected.");return await this._connectDevice(e),this.getDeviceInfo()}async getDevices(){return this.mode==="bridge"?this._bridgeGetDevices():Fe?(await Fe.getDevices()).map(t=>({serial:t.serial,name:t.name,display_name:`${t.name||t.serial} (${t.serial})`})):[]}async connectBySerial(e){if(this.mode==="bridge")return this.bridgeSerial=e,this.getDeviceInfo();if(!Fe)throw new Error("WebUSB not supported.");const s=(await Fe.getDevices()).find(i=>i.serial===e);if(!s)throw new Error(`Device ${e} not found.`);return await this._connectDevice(s),this.getDeviceInfo()}async _connectDevice(e){var i;await this.disconnect();let t;try{t=await e.connect()}catch(r){throw(i=r==null?void 0:r.message)!=null&&i.includes("claimInterface")?new Error("Cannot claim USB device — another program (likely ADB) is using it. Run 'adb kill-server' in your terminal, then retry."):r}const s=await hs.authenticate({serial:e.serial,connection:t,credentialStore:Ka});this.adb=new pa(s),this.device=e}async disconnect(){if(this.mode==="bridge"){this.bridgeSerial="",this.bridgeUrl="",this.mode="webusb";return}if(this.adb){try{await this.adb.close()}catch{}this.adb=null,this.device=null}}checkConnection(){const e=this.mode==="bridge"?!!this.bridgeUrl:!!this.adb;return{connected:e,device:e?this.getDeviceInfo():null,package:this.packageName,database:this.dbName}}getDeviceInfo(){return this.mode==="bridge"?this.bridgeSerial?{serial:this.bridgeSerial,name:this.bridgeSerial,display_name:`${this.bridgeSerial} (ADB Bridge)`}:null:this.device?{serial:this.device.serial,name:this.device.name,display_name:`${this.device.name||this.device.serial} (${this.device.serial})`}:null}setPackage(e){this.packageName=e,this.dbName="",this.dbPath="",this.sqlite3Path=""}setDatabase(e,t){this.dbName=e,this.dbPath=t||""}async shell(e){if(this.mode==="bridge")return this._bridgeShell(e);if(!this.adb)throw new Error("Not connected to a device.");const t=await this.adb.subprocess.spawnAndWaitLegacy(e);let s;return typeof t=="string"?s=t:t instanceof Uint8Array?s=new TextDecoder().decode(t):(t==null?void 0:t.stdout)!==void 0?s=typeof t.stdout=="string"?t.stdout:new TextDecoder().decode(t.stdout):s=String(t),s.replace(/\r\n/g,`
|
|
10
10
|
`).trimEnd()}async runAs(e){return this.shell(`run-as ${this.packageName} ${e}`)}async getPackages(){const s=(await this.shell('for p in $(pm list packages --user 0 -3 2>/dev/null | tr -d "\\r" | sed "s/package://"); do run-as $p id 2>/dev/null 1>/dev/null && echo $p; done')).split(`
|
|
11
11
|
`).map(i=>i.trim()).filter(Boolean);return s.sort(),s}async getDatabases(e){const t=e||this.packageName;if(!t)throw new Error("No package selected.");const s=["databases","files","files/SQLite"],i=[],r=new Set;for(const o of s)try{const c=await this.shell(`run-as ${t} ls ${o} 2>/dev/null`);for(const w of c.split(`
|
|
12
12
|
`)){const d=w.trim();d&&(d.endsWith(".db")||d.endsWith(".sqlite")||d.endsWith(".sqlite3"))&&(r.has(d)||(r.add(d),i.push({name:d,path:`${o}/${d}`})))}}catch{}return i}async searchDatabases(e,t){const s=e||this.packageName;if(!s)throw new Error("No package selected.");const i=await this.shell(`run-as ${s} find . -name "*.db" -o -name "*.sqlite" -o -name "*.sqlite3" 2>/dev/null`),r=(t||"").toLowerCase(),o=[];for(const c of i.split(`
|
|
13
|
-
`)){let w=c.trim();if(!w)continue;w.startsWith("./")&&(w=w.slice(2));const d=w.split("/").pop();d.endsWith("-journal")||d.endsWith("-wal")||d.endsWith("-shm")||(!r||d.toLowerCase().includes(r)||w.toLowerCase().includes(r))&&o.push({name:d,path:w})}return o.sort((c,w)=>c.name.toLowerCase().localeCompare(w.name.toLowerCase())),o}async ensureSqlite3(){if(this.sqlite3Path)return this.sqlite3Path;try{const t=await this.runAs("./sqlite3 -version");if(
|
|
13
|
+
`)){let w=c.trim();if(!w)continue;w.startsWith("./")&&(w=w.slice(2));const d=w.split("/").pop();d.endsWith("-journal")||d.endsWith("-wal")||d.endsWith("-shm")||(!r||d.toLowerCase().includes(r)||w.toLowerCase().includes(r))&&o.push({name:d,path:w})}return o.sort((c,w)=>c.name.toLowerCase().localeCompare(w.name.toLowerCase())),o}async ensureSqlite3(){if(this.sqlite3Path)return this.sqlite3Path;try{const t=await this.runAs("./sqlite3 -version");if(/^3\.\d+/.test(t.trim()))return this.sqlite3Path="./sqlite3",this.sqlite3Path}catch{}const e=["/system/bin/sqlite3","/system/xbin/sqlite3","/data/local/tmp/sqlite3"];for(const t of e)try{const s=await this.shell(`${t} -version 2>&1`);if(/^3\.\d+/.test(s.trim())){try{await this.runAs(`cp ${t} ./sqlite3`),await this.runAs("chmod 755 ./sqlite3");const i=await this.runAs("./sqlite3 -version");if(/^3\.\d+/.test(i.trim()))return this.sqlite3Path="./sqlite3",this.sqlite3Path}catch{}return this.sqlite3Path=t,this.sqlite3Path}}catch{}if(this.mode==="bridge"&&this.bridgeUrl)try{const t=await fetch(`${this.bridgeUrl}/api/push-sqlite3`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({serial:this.bridgeSerial||void 0})}),s=await t.json();if(t.ok&&s.ok){try{await this.runAs("cp /data/local/tmp/sqlite3 ./sqlite3"),await this.runAs("chmod 755 ./sqlite3");const i=await this.runAs("./sqlite3 -version");if(/^3\.\d+/.test(i.trim()))return this.sqlite3Path="./sqlite3",this.sqlite3Path}catch{}return this.sqlite3Path="/data/local/tmp/sqlite3",this.sqlite3Path}}catch{}throw new Error("sqlite3 not found on device. Ensure a sqlite3 binary is available at /system/bin/sqlite3 or /data/local/tmp/sqlite3.")}async findDatabasePath(){if(this.dbPath)return this.dbPath;const e=[`databases/${this.dbName}`,`files/${this.dbName}`,`files/SQLite/${this.dbName}`];for(const t of e)try{if((await this.runAs(`ls ${t}`)).includes(this.dbName))return this.dbPath=t,t}catch{}throw new Error(`Database ${this.dbName} not found on device.`)}async _sqliteJson(e){const t=await this.ensureSqlite3(),s=await this.findDatabasePath(),i=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`"),r=`${t} ${s} -json "${i}"`,o=await this.runAs(r);if(!o)return[];try{const c=JSON.parse(o);return Array.isArray(c)?c:[]}catch{return this._sqliteFallback(e,t,s)}}async _sqliteFallback(e,t,s){const i=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`"),r=`${t} ${s} -header -separator "|" "${i}"`,c=(await this.runAs(r)).split(`
|
|
14
14
|
`).filter(Boolean);if(c.length===0)return[];const w=c[0].split("|").map(p=>p.trim()),d=[];for(let p=1;p<c.length;p++){const b=c[p].split("|").map(E=>E.trim());if(b.length===w.length){const E={};w.forEach((K,gn)=>E[K]=b[gn]),d.push(E)}}return d}async _sqliteExec(e){const t=await this.ensureSqlite3(),s=await this.findDatabasePath(),i=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`"),r=`${t} ${s} "${i}"`;await this.runAs(r)}_isWriteQuery(e){const t=e.trim().toUpperCase();return["INSERT","UPDATE","DELETE","DROP","CREATE","ALTER","REPLACE"].some(s=>t.startsWith(s))}async getTables(){return(await this._sqliteJson("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")).map(t=>({name:t.name,row_count:0}))}async getTableStructure(e){return this._sqliteJson(`PRAGMA table_info(${e});`)}async getTableData(e,t=100,s=0){const i=await this.getTableStructure(e);if(!i.length)throw new Error(`Table ${e} not found`);const r=await this._sqliteJson(`SELECT * FROM ${e} LIMIT ${t} OFFSET ${s};`),o=await this._sqliteJson(`SELECT COUNT(*) as count FROM ${e};`),c=o.length?Number(o[0].count):0;return{columns:i.map(w=>w.name),rows:r,row_count:r.length,total_count:c,offset:s,limit:t}}async executeQuery(e,t){const s=e.trim();if(this._isWriteQuery(s))return await this._sqliteExec(s),{columns:[],rows:[],row_count:0};let i=s;t&&!s.toUpperCase().includes("LIMIT")&&s.toUpperCase().startsWith("SELECT")&&(i=`${s.replace(/;$/,"")} LIMIT ${t};`);const r=await this._sqliteJson(i);return{columns:r.length?Object.keys(r[0]):[],rows:r,row_count:r.length}}async checkDatabaseExists(){try{return await this.findDatabasePath(),!0}catch{return!1}}}const f=new Qa;let U=null,D=0,k=100,$=0,$i="query",Js=null,He=[],z="";const h=n=>document.getElementById(n);window.addEventListener("DOMContentLoaded",()=>{const n=localStorage.getItem("sqliteViewerQuery");n&&(h("queryInput").value=n),localStorage.getItem("sqliteViewerConfigCollapsed")==="true"&&h("configSection").classList.remove("expanded"),h("queryInput").addEventListener("input",e=>{localStorage.setItem("sqliteViewerQuery",e.target.value)}),document.addEventListener("keydown",e=>{e.key==="F5"&&(e.preventDefault(),Xs())}),h("tableSearch").addEventListener("input",e=>oo(e.target.value)),document.addEventListener("click",e=>{!e.target.closest("#searchResultsDropdown")&&!e.target.closest("#dbSearchInput")&&h("searchResultsDropdown").classList.remove("visible"),!e.target.closest("#packageDropdown")&&!e.target.closest("#packageSearchInput")&&h("packageDropdown").classList.remove("visible")}),h("configToggleBtn").addEventListener("click",eo),h("usbConnectBtn").addEventListener("click",Za),h("packageSearchInput").addEventListener("focus",to),h("packageSearchInput").addEventListener("input",ks),h("packageClearBtn").addEventListener("click",e=>so(e)),h("databaseSelect").addEventListener("change",()=>Ts()),h("dbSearchInput").addEventListener("input",ro),h("dbSearchInput").addEventListener("keydown",e=>{e.key==="Enter"&&fs()}),h("dbSearchBtn").addEventListener("click",fs),h("executeBtn").addEventListener("click",()=>Xs()),h("executeAllBtn").addEventListener("click",wo),h("refreshTablesBtn").addEventListener("click",Eo),h("clearQueryBtn").addEventListener("click",So),h("formatQueryBtn").addEventListener("click",xo),h("firstBtn").addEventListener("click",po),h("prevBtn").addEventListener("click",fo),h("nextBtn").addEventListener("click",yo),h("lastBtn").addEventListener("click",mo),h("gotoPageBtn").addEventListener("click",Zs),h("gotoPageInput").addEventListener("keypress",e=>{e.key==="Enter"&&Zs()}),h("limitSelect").addEventListener("change",bo),document.querySelectorAll(".tab").forEach(e=>{e.addEventListener("click",()=>vo(e.dataset.tab))}),Ga()});async function Ga(){try{if(await f.connectBridge()){Ya(),await Ja();return}}catch{}await Xa()}function Ya(){const n=h("connectionStatus");n.textContent="ADB Bridge",n.className="connection-status bridge";const e=f.bridgeUrl?new URL(f.bridgeUrl).port:"15555";h("deviceStatus").textContent=`Bridge connected on :${e}`,h("deviceStatus").classList.add("ok");const t=h("usbConnectBtn");t.textContent="Disconnect Bridge",t.classList.add("disconnect")}async function Ja(){try{const n=await f.getDevices();if(n.length===0){h("deviceStatus").textContent="Bridge connected — no devices found. Plug in a phone.",h("deviceStatus").classList.remove("ok");return}if(n.length===1){f.bridgeSerial=n[0].serial,h("deviceStatus").textContent=n[0].display_name,h("deviceStatus").classList.add("ok"),await ps();return}f.bridgeSerial=n[0].serial,h("deviceStatus").textContent=n[0].display_name,h("deviceStatus").classList.add("ok"),await ps()}catch(n){h("deviceStatus").textContent=`Bridge error: ${n.message}`,h("deviceStatus").classList.remove("ok")}}async function Xa(){try{const n=await f.getDevices(),e=localStorage.getItem("sqliteViewerDevice");n.length===1?(h("deviceStatus").textContent="Reconnecting...",await f.connectBySerial(n[0].serial),await gs()):e&&n.find(s=>s.serial===e)&&(h("deviceStatus").textContent="Reconnecting...",await f.connectBySerial(e),await gs())}catch{}}async function Za(){const n=h("usbConnectBtn");if(f.mode==="bridge"||f.adb){await f.disconnect(),n.textContent="Connect Device",n.classList.remove("disconnect"),h("deviceStatus").textContent="No device connected",h("deviceStatus").classList.remove("ok"),h("connectionStatus").textContent="Disconnected",h("connectionStatus").className="connection-status disconnected",h("packageSearchInput").disabled=!0,h("packageSearchInput").placeholder="Connect device first...",h("databaseSelect").disabled=!0,h("tablesList").innerHTML='<div class="info" style="margin: 10px; font-size: 12px;">Connect a USB device to get started.</div>';return}n.textContent="Connecting...",h("deviceStatus").textContent="Check your phone — approve USB debugging if prompted";try{await f.requestDevice(),await gs()}catch(e){n.textContent="Connect Device",h("deviceStatus").textContent=`Error: ${e.message}`,h("deviceStatus").classList.remove("ok")}}async function gs(){const n=f.getDeviceInfo(),e=h("usbConnectBtn");e.textContent="Disconnect",e.classList.add("disconnect"),h("deviceStatus").textContent=n.display_name,h("deviceStatus").classList.add("ok"),h("connectionStatus").textContent="Connected",h("connectionStatus").className="connection-status connected",localStorage.setItem("sqliteViewerDevice",n.serial),await ps()}function eo(){const n=h("configSection");n.classList.toggle("expanded"),localStorage.setItem("sqliteViewerConfigCollapsed",!n.classList.contains("expanded"))}async function ps(){const n=h("packageSearchInput"),e=h("packageComboWrapper");n.disabled=!1,n.placeholder="Scanning debuggable apps...",n.value="",e.classList.remove("has-value"),z="",He=[];try{He=await f.getPackages(),n.placeholder=`Search ${He.length} debuggable apps...`;const t=localStorage.getItem("sqliteViewerPackage");t&&He.includes(t)&&(z=t,n.value=t,e.classList.add("has-value")),await zi(!0)}catch(t){n.placeholder=`Failed: ${t.message}`}}function to(){const n=h("packageSearchInput");z&&n.value===z&&n.select(),ks()}function ks(){const n=h("packageSearchInput"),e=h("packageDropdown"),t=n.value.trim().toLowerCase(),s=t?He.filter(i=>i.toLowerCase().includes(t)):He;s.length===0?e.innerHTML='<div class="combo-empty">No matching packages</div>':(e.innerHTML=s.map(i=>`<div class="combo-item${i===z?" active":""}" data-pkg="${i}">${i}</div>`).join(""),e.querySelectorAll(".combo-item").forEach(i=>{i.addEventListener("click",()=>no(i.dataset.pkg))})),e.classList.add("visible")}async function no(n){const e=h("packageSearchInput"),t=h("packageComboWrapper"),s=h("packageDropdown");z=n,e.value=n,t.classList.add("has-value"),s.classList.remove("visible"),await zi()}async function so(n){n&&n.stopPropagation();const e=h("packageSearchInput"),t=h("packageComboWrapper");z="",e.value="",t.classList.remove("has-value"),e.focus(),ks(),h("databaseSelect").innerHTML='<option value="">Select a package first</option>',h("databaseSelect").disabled=!0,localStorage.removeItem("sqliteViewerPackage")}async function zi(n=!1){if(!z){h("databaseSelect").innerHTML='<option value="">Select a package first</option>',h("databaseSelect").disabled=!0;return}localStorage.setItem("sqliteViewerPackage",z),f.setPackage(z),await io(n)}async function io(n=!1){const e=h("databaseSelect");e.disabled=!1,e.innerHTML='<option value="">Loading databases...</option>';try{const t=await f.getDatabases(z),s=localStorage.getItem("sqliteViewerDatabase");e.innerHTML='<option value="">-- Select database --</option>',t.forEach(i=>{const r=document.createElement("option");r.value=i.name,r.textContent=`${i.name} (${i.path})`,r.dataset.path=i.path,s&&i.name===s&&(r.selected=!0),e.appendChild(r)}),await Ts(n)}catch(t){e.innerHTML=`<option value="">Error: ${t.message}</option>`}}async function Ts(n=!1){var r;const e=h("databaseSelect"),t=e.value;if(!t){n||(h("tablesList").innerHTML='<div class="info" style="margin: 10px; font-size: 12px;">Select a database to view tables</div>');return}const s=e.options[e.selectedIndex],i=((r=s==null?void 0:s.dataset)==null?void 0:r.path)||"";localStorage.setItem("sqliteViewerDatabase",t),f.setDatabase(t,i),await Oi(),await Ri()}function ro(){if(clearTimeout(Js),h("dbSearchInput").value.trim().length<1){h("searchResultsDropdown").classList.remove("visible");return}Js=setTimeout(()=>fs(),400)}async function fs(){const n=h("dbSearchInput").value.trim(),e=h("searchResultsDropdown");if(!z){e.innerHTML='<div class="search-result-item"><span class="file-name">Select a package first</span></div>',e.classList.add("visible");return}if(!n){e.classList.remove("visible");return}e.innerHTML='<div class="search-result-item"><span class="file-name">Searching...</span></div>',e.classList.add("visible");try{const t=await f.searchDatabases(z,n);if(t.length===0){e.innerHTML='<div class="search-result-item"><span class="file-name">No databases found</span></div>';return}e.innerHTML=t.map(s=>`<div class="search-result-item" data-name="${s.name}" data-path="${s.path}">
|
|
15
15
|
<div class="file-name">${s.name}</div>
|
|
16
16
|
<div class="file-path">${s.path}</div>
|
package/dist/index.html
CHANGED
package/electron/main.cjs
CHANGED
|
@@ -5,6 +5,14 @@ const path = require("path");
|
|
|
5
5
|
let bridge = null;
|
|
6
6
|
let mainWindow = null;
|
|
7
7
|
|
|
8
|
+
function setupBundledAdb() {
|
|
9
|
+
if (app.isPackaged) {
|
|
10
|
+
const toolsDir = path.join(process.resourcesPath, "tools");
|
|
11
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
12
|
+
process.env.PATH = toolsDir + sep + (process.env.PATH || "");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
function getBridgePath() {
|
|
9
17
|
if (app.isPackaged) {
|
|
10
18
|
return path.join(process.resourcesPath, "bridge", "server.js");
|
|
@@ -73,6 +81,7 @@ function createWindow() {
|
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
app.whenReady().then(async () => {
|
|
84
|
+
setupBundledAdb();
|
|
76
85
|
try {
|
|
77
86
|
console.log("Starting ADB bridge server...");
|
|
78
87
|
await startBridge();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adb-sqlite-viewer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "ADB SQLite database viewer for Android — inspect tables, schemas, and run queries on-device",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "electron/main.cjs",
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"cli/",
|
|
12
12
|
"bridge/server.js",
|
|
13
|
+
"bridge/package.json",
|
|
14
|
+
"sqlite3-arm64",
|
|
13
15
|
"dist/"
|
|
14
16
|
],
|
|
15
17
|
"scripts": {
|
|
@@ -66,6 +68,14 @@
|
|
|
66
68
|
{
|
|
67
69
|
"from": "bridge/package.json",
|
|
68
70
|
"to": "bridge/package.json"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"from": "tools/",
|
|
74
|
+
"to": "tools/"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"from": "sqlite3-arm64",
|
|
78
|
+
"to": "sqlite3-arm64"
|
|
69
79
|
}
|
|
70
80
|
],
|
|
71
81
|
"win": {
|
package/sqlite3-arm64
ADDED
|
Binary file
|