dsh-multigameassistant 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/emulator.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  EMULATORS_CAPABILITY,
11
11
  EmulatorSettings
12
- } from "./chunk-LXHF6AKU.js";
12
+ } from "./chunk-7EFZ5KR6.js";
13
13
  import {
14
14
  external_exports
15
15
  } from "./chunk-6DSSLS7I.js";
@@ -17,13 +17,635 @@ import "./chunk-2UFLGPDY.js";
17
17
 
18
18
  // packages/emulator/lib/index.js
19
19
  import { execFile } from "node:child_process";
20
- import { access, readFile } from "node:fs/promises";
21
- import { basename, dirname as dirname2, join as join2 } from "node:path";
20
+ import { access, readFile as readFile2 } from "node:fs/promises";
21
+ import { basename, dirname as dirname2, join as join3 } from "node:path";
22
22
  import { Service } from "@deepseek-ai/cordis";
23
23
 
24
+ // packages/emulator/lib/apps.js
25
+ import { mkdir, readFile } from "node:fs/promises";
26
+ import { join } from "node:path";
27
+
28
+ // packages/emulator/lib/apk.js
29
+ import { inflateRawSync } from "node:zlib";
30
+ var MAX_ENTRY = 48 * 1024 * 1024;
31
+ var Zip = class _Zip {
32
+ file;
33
+ entries;
34
+ constructor(file, entries2) {
35
+ this.file = file;
36
+ this.entries = entries2;
37
+ }
38
+ static async open(file) {
39
+ const tailLength = Math.min(file.size, 22 + 65535 + 20);
40
+ const tail = await file.read(file.size - tailLength, tailLength);
41
+ let at = -1;
42
+ for (let i = tail.length - 22; i >= 0; i--)
43
+ if (tail.readUInt32LE(i) === 101010256) {
44
+ at = i;
45
+ break;
46
+ }
47
+ if (at < 0)
48
+ throw new Error("\u4E0D\u662F APK\uFF08zip \u6587\u4EF6\u6CA1\u6709\u76EE\u5F55\uFF09");
49
+ let count = tail.readUInt16LE(at + 10);
50
+ let cdSize = tail.readUInt32LE(at + 12);
51
+ let cdOffset = tail.readUInt32LE(at + 16);
52
+ if (cdOffset === 4294967295 || cdSize === 4294967295 || count === 65535) {
53
+ if (at < 20 || tail.readUInt32LE(at - 20) !== 117853008)
54
+ throw new Error("APK \u7684 zip64 \u76EE\u5F55\u8BFB\u4E0D\u51FA\u6765");
55
+ const end = await file.read(Number(tail.readBigUInt64LE(at - 12)), 56);
56
+ if (end.readUInt32LE(0) !== 101075792)
57
+ throw new Error("APK \u7684 zip64 \u76EE\u5F55\u8BFB\u4E0D\u51FA\u6765");
58
+ count = Number(end.readBigUInt64LE(32));
59
+ cdSize = Number(end.readBigUInt64LE(40));
60
+ cdOffset = Number(end.readBigUInt64LE(48));
61
+ }
62
+ if (cdSize > 64 * 1024 * 1024 || cdOffset + cdSize > file.size)
63
+ throw new Error("APK \u7684\u76EE\u5F55\u4E0D\u5BF9");
64
+ const cd = await file.read(cdOffset, cdSize);
65
+ const entries2 = /* @__PURE__ */ new Map();
66
+ for (let p = 0, i = 0; i < count && p + 46 <= cd.length; i++) {
67
+ if (cd.readUInt32LE(p) !== 33639248)
68
+ break;
69
+ const method = cd.readUInt16LE(p + 10);
70
+ let compressedSize = cd.readUInt32LE(p + 20);
71
+ let size = cd.readUInt32LE(p + 24);
72
+ const nameLength = cd.readUInt16LE(p + 28);
73
+ const extraLength = cd.readUInt16LE(p + 30);
74
+ const commentLength = cd.readUInt16LE(p + 32);
75
+ let offset = cd.readUInt32LE(p + 42);
76
+ const name = cd.toString("utf8", p + 46, p + 46 + nameLength);
77
+ for (let e = p + 46 + nameLength, end = e + extraLength; e + 4 <= end; ) {
78
+ const id = cd.readUInt16LE(e);
79
+ const length = cd.readUInt16LE(e + 2);
80
+ if (id === 1) {
81
+ let q = e + 4;
82
+ if (size === 4294967295) {
83
+ size = Number(cd.readBigUInt64LE(q));
84
+ q += 8;
85
+ }
86
+ if (compressedSize === 4294967295) {
87
+ compressedSize = Number(cd.readBigUInt64LE(q));
88
+ q += 8;
89
+ }
90
+ if (offset === 4294967295)
91
+ offset = Number(cd.readBigUInt64LE(q));
92
+ }
93
+ e += 4 + length;
94
+ }
95
+ entries2.set(name, { method, compressedSize, size, offset });
96
+ p += 46 + nameLength + extraLength + commentLength;
97
+ }
98
+ return new _Zip(file, entries2);
99
+ }
100
+ has(name) {
101
+ return this.entries.has(name);
102
+ }
103
+ /** An entry's contents, or undefined when there is no such entry. @throws Error when it cannot be read. */
104
+ async read(name) {
105
+ const entry = this.entries.get(name);
106
+ if (entry === void 0)
107
+ return void 0;
108
+ if (entry.size > MAX_ENTRY || entry.compressedSize > MAX_ENTRY)
109
+ throw new Error(`${name} \u592A\u5927`);
110
+ const local = await this.file.read(entry.offset, 30);
111
+ if (local.readUInt32LE(0) !== 67324752)
112
+ throw new Error(`${name} \u7684\u4F4D\u7F6E\u4E0D\u5BF9`);
113
+ const start = entry.offset + 30 + local.readUInt16LE(26) + local.readUInt16LE(28);
114
+ const data = await this.file.read(start, entry.compressedSize);
115
+ if (entry.method === 0)
116
+ return data;
117
+ if (entry.method === 8)
118
+ return inflateRawSync(data);
119
+ throw new Error(`${name} \u7528\u4E86\u4E0D\u8BA4\u8BC6\u7684\u538B\u7F29\u65B9\u5F0F ${entry.method}`);
120
+ }
121
+ };
122
+ var RES_STRING_POOL = 1;
123
+ var RES_TABLE = 2;
124
+ var RES_XML = 3;
125
+ var RES_XML_START_ELEMENT = 258;
126
+ var RES_XML_RESOURCE_MAP = 384;
127
+ var RES_TABLE_PACKAGE = 512;
128
+ var RES_TABLE_TYPE = 513;
129
+ function stringPool(buf, start) {
130
+ const headerSize = buf.readUInt16LE(start + 2);
131
+ const count = buf.readUInt32LE(start + 8);
132
+ const utf8 = (buf.readUInt32LE(start + 16) & 256) !== 0;
133
+ const strings = start + buf.readUInt32LE(start + 20);
134
+ const cache = /* @__PURE__ */ new Map();
135
+ return (index) => {
136
+ if (index < 0 || index >= count)
137
+ return void 0;
138
+ const hit = cache.get(index);
139
+ if (hit !== void 0)
140
+ return hit;
141
+ let p = strings + buf.readUInt32LE(start + headerSize + index * 4);
142
+ let text;
143
+ if (utf8) {
144
+ p += (buf[p] & 128) !== 0 ? 2 : 1;
145
+ let n = buf[p];
146
+ if ((n & 128) !== 0) {
147
+ n = (n & 127) << 8 | buf[p + 1];
148
+ p += 2;
149
+ } else
150
+ p += 1;
151
+ text = buf.toString("utf8", p, p + n);
152
+ } else {
153
+ let n = buf.readUInt16LE(p);
154
+ p += 2;
155
+ if ((n & 32768) !== 0) {
156
+ n = (n & 32767) << 16 | buf.readUInt16LE(p);
157
+ p += 2;
158
+ }
159
+ text = buf.toString("utf16le", p, p + n * 2);
160
+ }
161
+ cache.set(index, text);
162
+ return text;
163
+ };
164
+ }
165
+ var TYPE_REFERENCE = 1;
166
+ var TYPE_STRING = 3;
167
+ var isColor = (type) => type >= 28 && type <= 31;
168
+ function parseXml(buf) {
169
+ if (buf.length < 8 || buf.readUInt16LE(0) !== RES_XML)
170
+ throw new Error("\u4E0D\u662F\u7F16\u8BD1\u8FC7\u7684 XML");
171
+ let strings = () => void 0;
172
+ let ids = [];
173
+ const elements = [];
174
+ let depth = 0;
175
+ for (let p = buf.readUInt16LE(2); p + 8 <= buf.length; ) {
176
+ const type = buf.readUInt16LE(p);
177
+ const size = buf.readUInt32LE(p + 4);
178
+ if (size < 8)
179
+ break;
180
+ if (type === RES_STRING_POOL)
181
+ strings = stringPool(buf, p);
182
+ else if (type === RES_XML_RESOURCE_MAP) {
183
+ const headerSize = buf.readUInt16LE(p + 2);
184
+ ids = [];
185
+ for (let q = p + headerSize; q + 4 <= p + size; q += 4)
186
+ ids.push(buf.readUInt32LE(q));
187
+ } else if (type === RES_XML_START_ELEMENT) {
188
+ const ext = p + buf.readUInt16LE(p + 2);
189
+ const name = strings(buf.readUInt32LE(ext + 4)) ?? "";
190
+ const attributeStart = buf.readUInt16LE(ext + 8);
191
+ const attributeSize = buf.readUInt16LE(ext + 10);
192
+ const attributeCount = buf.readUInt16LE(ext + 12);
193
+ const attributes = [];
194
+ for (let i = 0; i < attributeCount; i++) {
195
+ const a = ext + attributeStart + i * attributeSize;
196
+ const nameIndex = buf.readUInt32LE(a + 4);
197
+ const rawIndex = buf.readUInt32LE(a + 8);
198
+ const raw = rawIndex === 4294967295 ? void 0 : strings(rawIndex);
199
+ const id = ids[nameIndex];
200
+ attributes.push({
201
+ name: strings(nameIndex) ?? "",
202
+ type: buf[a + 15],
203
+ data: buf.readUInt32LE(a + 16),
204
+ ...id === void 0 ? {} : { id },
205
+ ...raw === void 0 ? {} : { raw }
206
+ });
207
+ }
208
+ elements.push({ name, depth: depth++, attributes });
209
+ } else if (type === 259)
210
+ depth = Math.max(0, depth - 1);
211
+ p += size;
212
+ }
213
+ return elements;
214
+ }
215
+ var FLAG_COMPLEX = 1;
216
+ var FLAG_COMPACT = 8;
217
+ var TYPE_FLAG_SPARSE = 1;
218
+ var TYPE_FLAG_OFFSET16 = 2;
219
+ var ResourceTable = class {
220
+ buf;
221
+ strings = () => void 0;
222
+ /** package id → type id → type chunk offsets. */
223
+ types = /* @__PURE__ */ new Map();
224
+ constructor(buf) {
225
+ if (buf.length < 12 || buf.readUInt16LE(0) !== RES_TABLE)
226
+ throw new Error("\u4E0D\u662F resources.arsc");
227
+ this.buf = buf;
228
+ for (let p = buf.readUInt16LE(2); p + 8 <= buf.length; ) {
229
+ const type = buf.readUInt16LE(p);
230
+ const size = buf.readUInt32LE(p + 4);
231
+ if (size < 8)
232
+ break;
233
+ if (type === RES_STRING_POOL)
234
+ this.strings = stringPool(buf, p);
235
+ else if (type === RES_TABLE_PACKAGE)
236
+ this.package(p, size);
237
+ p += size;
238
+ }
239
+ }
240
+ package(start, size) {
241
+ const id = this.buf.readUInt32LE(start + 8);
242
+ const byType = this.types.get(id) ?? /* @__PURE__ */ new Map();
243
+ this.types.set(id, byType);
244
+ for (let p = start + this.buf.readUInt16LE(start + 2); p + 8 <= start + size; ) {
245
+ const type = this.buf.readUInt16LE(p);
246
+ const chunk = this.buf.readUInt32LE(p + 4);
247
+ if (chunk < 8)
248
+ break;
249
+ if (type === RES_TABLE_TYPE) {
250
+ const typeId = this.buf[p + 8];
251
+ const list = byType.get(typeId) ?? [];
252
+ list.push(p);
253
+ byType.set(typeId, list);
254
+ }
255
+ p += chunk;
256
+ }
257
+ }
258
+ /** Every configuration's value of a resource. */
259
+ values(resId) {
260
+ const chunks = this.types.get(resId >>> 24)?.get(resId >>> 16 & 255) ?? [];
261
+ const index = resId & 65535;
262
+ const out = [];
263
+ for (const p of chunks) {
264
+ const b = this.buf;
265
+ const flags = b[p + 9];
266
+ const count = b.readUInt32LE(p + 12);
267
+ const entries2 = p + b.readUInt32LE(p + 16);
268
+ const offsets = p + b.readUInt16LE(p + 2);
269
+ let offset;
270
+ if ((flags & TYPE_FLAG_SPARSE) !== 0) {
271
+ for (let i = 0; i < count; i++) {
272
+ if (b.readUInt16LE(offsets + i * 4) === index) {
273
+ offset = b.readUInt16LE(offsets + i * 4 + 2) * 4;
274
+ break;
275
+ }
276
+ }
277
+ } else if (index < count) {
278
+ if ((flags & TYPE_FLAG_OFFSET16) !== 0) {
279
+ const v = b.readUInt16LE(offsets + index * 2);
280
+ offset = v === 65535 ? void 0 : v * 4;
281
+ } else {
282
+ const v = b.readUInt32LE(offsets + index * 4);
283
+ offset = v === 4294967295 ? void 0 : v;
284
+ }
285
+ }
286
+ if (offset === void 0)
287
+ continue;
288
+ const e = entries2 + offset;
289
+ if (e + 8 > b.length)
290
+ continue;
291
+ const entryFlags = b.readUInt16LE(e + 2);
292
+ let value;
293
+ if ((entryFlags & FLAG_COMPACT) !== 0)
294
+ value = { type: entryFlags >>> 8, data: b.readUInt32LE(e + 4) };
295
+ else if ((entryFlags & FLAG_COMPLEX) !== 0)
296
+ continue;
297
+ else {
298
+ const v = e + b.readUInt16LE(e);
299
+ value = { type: b[v + 3], data: b.readUInt32LE(v + 4) };
300
+ }
301
+ const config = p + 20;
302
+ const string = value.type === TYPE_STRING ? this.strings(value.data) : void 0;
303
+ out.push({ ...value, config: configAt(b, config), ...string === void 0 ? {} : { string } });
304
+ }
305
+ return out;
306
+ }
307
+ /** Values with references followed (an icon that is an alias of another, a label pointing at a string). */
308
+ resolve(resId, depth = 0) {
309
+ if (depth > 6)
310
+ return [];
311
+ return this.values(resId).flatMap((v) => v.type === TYPE_REFERENCE && v.data !== 0 ? this.resolve(v.data, depth + 1).map((r) => ({ ...r, config: v.config.language === "" && v.config.density === 0 ? r.config : v.config })) : [v]);
312
+ }
313
+ };
314
+ function configAt(b, c) {
315
+ const size = b.readUInt32LE(c);
316
+ const lang = size >= 12 && (b[c + 8] & 128) === 0 && b[c + 8] !== 0 ? String.fromCharCode(b[c + 8], b[c + 9]) : "";
317
+ const country = size >= 12 && (b[c + 10] & 128) === 0 && b[c + 10] !== 0 ? String.fromCharCode(b[c + 10], b[c + 11]) : "";
318
+ return { language: lang, country, density: size >= 16 ? b.readUInt16LE(c + 14) : 0 };
319
+ }
320
+ var ATTR_LABEL = 16842753;
321
+ var ATTR_ICON = 16842754;
322
+ var ATTR_SRC = 16843033;
323
+ var ATTR_DRAWABLE = 16843161;
324
+ var ATTR_ROUND_ICON = 16844076;
325
+ var BITMAP = /\.(png|webp|jpe?g)$/i;
326
+ function pickLabel(values) {
327
+ const strings = values.filter((v) => v.string !== void 0 && v.string.trim() !== "");
328
+ const rank = (c) => c.language === "zh" ? c.country === "CN" || c.country === "" ? 0 : 1 : c.language === "" ? 2 : c.language === "en" ? 3 : 4;
329
+ return strings.sort((a, b) => rank(a.config) - rank(b.config))[0]?.string?.trim();
330
+ }
331
+ function pickIconFile(values) {
332
+ const files = values.filter((v) => v.string !== void 0);
333
+ const dpi = (c) => c.density === 0 ? 160 : c.density === 65535 ? 1 : c.density === 65534 ? 0 : c.density;
334
+ const bitmaps = files.filter((v) => BITMAP.test(v.string)).sort((a, b) => dpi(b.config) - dpi(a.config));
335
+ const xml = files.find((v) => /\.xml$/i.test(v.string))?.string;
336
+ return { ...bitmaps[0] === void 0 ? {} : { bitmap: bitmaps[0].string }, ...xml === void 0 ? {} : { xml } };
337
+ }
338
+ var mediaTypeOf = (file) => /\.webp$/i.test(file) ? "image/webp" : /\.jpe?g$/i.test(file) ? "image/jpeg" : "image/png";
339
+ async function readApkInfo(zips) {
340
+ const base = zips[0];
341
+ if (base === void 0)
342
+ return {};
343
+ const manifestXml = await base.read("AndroidManifest.xml");
344
+ if (manifestXml === void 0)
345
+ throw new Error("APK \u91CC\u6CA1\u6709 AndroidManifest.xml");
346
+ const application = parseXml(manifestXml).find((e) => e.name === "application");
347
+ const arsc = await base.read("resources.arsc");
348
+ const table = arsc === void 0 ? void 0 : new ResourceTable(arsc);
349
+ const attr = (id) => application?.attributes.find((a) => a.id === id);
350
+ let label;
351
+ const labelAttr = attr(ATTR_LABEL);
352
+ if (labelAttr?.type === TYPE_STRING)
353
+ label = labelAttr.raw;
354
+ else if (labelAttr?.type === TYPE_REFERENCE && table !== void 0)
355
+ label = pickLabel(table.resolve(labelAttr.data));
356
+ const file = async (name) => {
357
+ for (const zip of zips)
358
+ if (zip.has(name))
359
+ return zip.read(name);
360
+ return void 0;
361
+ };
362
+ const bitmapOf = async (resId) => {
363
+ if (table === void 0)
364
+ return void 0;
365
+ const { bitmap } = pickIconFile(table.resolve(resId));
366
+ const data = bitmap === void 0 ? void 0 : await file(bitmap);
367
+ return data === void 0 ? void 0 : { mediaType: mediaTypeOf(bitmap), data };
368
+ };
369
+ let icon;
370
+ for (const id of [ATTR_ICON, ATTR_ROUND_ICON]) {
371
+ const a = attr(id);
372
+ if (icon === void 0 && a?.type === TYPE_REFERENCE)
373
+ icon = await bitmapOf(a.data).catch(() => void 0);
374
+ }
375
+ const iconAttr = attr(ATTR_ICON);
376
+ if (icon === void 0 && iconAttr?.type === TYPE_REFERENCE && table !== void 0) {
377
+ const { xml } = pickIconFile(table.resolve(iconAttr.data));
378
+ const doc = xml === void 0 ? void 0 : await file(xml);
379
+ if (doc !== void 0)
380
+ icon = await adaptiveIcon(parseXml(doc), table, file, bitmapOf).catch(() => void 0);
381
+ }
382
+ return { ...label === void 0 || label === "" ? {} : { label }, ...icon === void 0 ? {} : { icon } };
383
+ }
384
+ async function adaptiveIcon(elements, table, file, bitmapOf) {
385
+ if (elements[0]?.name !== "adaptive-icon")
386
+ return void 0;
387
+ const layer = async (name) => {
388
+ const at = elements.findIndex((e) => e.name === name);
389
+ if (at < 0)
390
+ return void 0;
391
+ const candidates = [elements[at], ...elements.slice(at + 1).filter((e) => e.depth > elements[at].depth).slice(0, 2)];
392
+ for (const e of candidates) {
393
+ const value = e.attributes.find((a) => a.id === ATTR_DRAWABLE || a.id === ATTR_SRC);
394
+ if (value === void 0)
395
+ continue;
396
+ if (isColor(value.type))
397
+ return `<rect width="108" height="108" fill="${color(value)}"/>`;
398
+ if (value.type !== TYPE_REFERENCE)
399
+ continue;
400
+ const colorValue = table.resolve(value.data).find((v) => isColor(v.type));
401
+ if (colorValue !== void 0)
402
+ return `<rect width="108" height="108" fill="${color(colorValue)}"/>`;
403
+ const bitmap = await bitmapOf(value.data);
404
+ if (bitmap !== void 0)
405
+ return `<image width="108" height="108" href="data:${bitmap.mediaType};base64,${bitmap.data.toString("base64")}"/>`;
406
+ const { xml } = pickIconFile(table.resolve(value.data));
407
+ const nested = xml === void 0 ? void 0 : await file(xml);
408
+ const inner = nested === void 0 ? void 0 : parseXml(nested)[0]?.attributes.find((a) => a.id === ATTR_SRC || a.id === ATTR_DRAWABLE);
409
+ const innerBitmap = inner?.type === TYPE_REFERENCE ? await bitmapOf(inner.data) : void 0;
410
+ if (innerBitmap !== void 0)
411
+ return `<image width="108" height="108" href="data:${innerBitmap.mediaType};base64,${innerBitmap.data.toString("base64")}"/>`;
412
+ }
413
+ return void 0;
414
+ };
415
+ const foreground = await layer("foreground");
416
+ if (foreground === void 0)
417
+ return void 0;
418
+ const background = await layer("background") ?? "";
419
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="18 18 72 72" width="192" height="192">${background}${foreground}</svg>`;
420
+ return { mediaType: "image/svg+xml", data: Buffer.from(svg) };
421
+ }
422
+ function color(value) {
423
+ const v = value.data >>> 0;
424
+ const a = (v >>> 24 & 255) / 255;
425
+ return `rgba(${v >>> 16 & 255},${v >>> 8 & 255},${v & 255},${a.toFixed(3)})`;
426
+ }
427
+
428
+ // packages/emulator/lib/apps.js
429
+ var CHANNELS = [
430
+ [/\.bilibili$/i, "B\u670D"],
431
+ [/\.(mi|xiaomi)$/i, "\u5C0F\u7C73\u670D"],
432
+ [/\.huawei$/i, "\u534E\u4E3A\u670D"],
433
+ [/\.vivo$/i, "vivo \u670D"],
434
+ [/\.(nearme\.gamecenter|oppo)$/i, "OPPO \u670D"],
435
+ [/\.(uc|aligames|9game)$/i, "\u4E5D\u6E38\u670D"],
436
+ [/\.m4399$/i, "4399 \u670D"],
437
+ [/\.(qihoo|qh360)$/i, "360 \u670D"],
438
+ [/\.baidu$/i, "\u767E\u5EA6\u670D"],
439
+ [/\.(yyb|tencent)$/i, "\u5E94\u7528\u5B9D\u670D"]
440
+ ];
441
+ var channelOf = (pkg) => CHANNELS.find(([re]) => re.test(pkg))?.[1];
442
+ var norm = (s) => s.toLowerCase().replace(/[\s·・::\-—_()()[\]【】「」《》'"!!??.,,。™®]/g, "");
443
+ function nameForms(name) {
444
+ const out = [name, name.replace(/[((][^))]*[))]/g, ""), .../[::](.{2,})$/.exec(name)?.slice(1) ?? []];
445
+ return [...new Set(out.map(norm).filter((n) => n.length >= 2))];
446
+ }
447
+ function rankApps(apps, hints) {
448
+ const known = new Map(hints.packages.map((p) => [p.package.toLowerCase(), p]));
449
+ const names = hints.names.flatMap(nameForms);
450
+ const out = [];
451
+ for (const app of apps) {
452
+ const pkg = app.package.toLowerCase();
453
+ let score = 0;
454
+ let reason = "";
455
+ let client;
456
+ const exact = known.get(pkg);
457
+ if (exact !== void 0) {
458
+ score = 100;
459
+ reason = exact.source ?? "\u5DF2\u77E5\u7684\u5305\u540D";
460
+ client = exact.client;
461
+ } else {
462
+ for (const hint of known.values()) {
463
+ const h = hint.package.toLowerCase();
464
+ if (pkg.startsWith(`${h}.`) && score < 85) {
465
+ score = 85;
466
+ client = channelOf(app.package);
467
+ reason = `${hint.package} \u7684\u5176\u4ED6\u7248\u672C`;
468
+ } else if (h.startsWith(`${pkg}.`) && score < 80) {
469
+ score = 80;
470
+ client = void 0;
471
+ reason = `\u548C ${hint.package} \u662F\u540C\u4E00\u6B3E\u6E38\u620F`;
472
+ }
473
+ }
474
+ }
475
+ const label = app.label === void 0 ? "" : norm(app.label);
476
+ if (label !== "" && names.length > 0) {
477
+ const byName = names.includes(label) ? 90 : names.some((n) => n.length >= 3 && label.includes(n)) ? 70 : 0;
478
+ if (byName > 0 && score > 0)
479
+ score = Math.min(100, score + 5);
480
+ else if (byName > score) {
481
+ score = byName;
482
+ reason = byName === 90 ? "\u5E94\u7528\u540D\u548C\u6E38\u620F\u540D\u4E00\u6837" : "\u5E94\u7528\u540D\u91CC\u6709\u6E38\u620F\u540D";
483
+ client ??= channelOf(app.package);
484
+ }
485
+ }
486
+ if (score < 70)
487
+ continue;
488
+ out.push({
489
+ package: app.package,
490
+ score,
491
+ reason,
492
+ ...app.label === void 0 ? {} : { label: app.label },
493
+ ...client === void 0 ? {} : { client }
494
+ });
495
+ }
496
+ const sure = out.some((c) => c.score >= 80);
497
+ return out.filter((c) => !sure || c.score >= 80).sort((a, b) => b.score - a.score || a.package.localeCompare(b.package));
498
+ }
499
+ function parsePackageList(text) {
500
+ const out = [];
501
+ for (const line of text.split(/\r?\n/)) {
502
+ const m = /^package:(.+)$/.exec(line.trim());
503
+ if (m === null)
504
+ continue;
505
+ const at = m[1].lastIndexOf("=");
506
+ if (at <= 0)
507
+ continue;
508
+ const pkg = m[1].slice(at + 1).trim();
509
+ if (/^[A-Za-z][\w]*(\.[A-Za-z_][\w]*)+$/.test(pkg))
510
+ out.push({ package: pkg, apk: m[1].slice(0, at) });
511
+ }
512
+ return out;
513
+ }
514
+ var quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
515
+ function deviceFile(execBuffer, adb, address, path, size) {
516
+ const BLOCK = 4096;
517
+ return {
518
+ size,
519
+ async read(offset, length) {
520
+ if (length <= 0)
521
+ return Buffer.alloc(0);
522
+ const skip = Math.floor(offset / BLOCK);
523
+ const count = Math.ceil((offset + length) / BLOCK) - skip;
524
+ const result = await execBuffer(adb, ["-s", address, "exec-out", `dd if=${quote(path)} bs=${BLOCK} skip=${skip} count=${count} 2>/dev/null`], { timeoutMs: 12e4 });
525
+ if (result === void 0)
526
+ throw new Error("\u627E\u4E0D\u5230 adb");
527
+ const start = offset - skip * BLOCK;
528
+ if (result.stdout.length < start + length)
529
+ throw new Error(`\u8BFB ${path} \u5931\u8D25\uFF1A${result.stderr.trim() || `\u53EA\u8BFB\u5230 ${result.stdout.length} \u5B57\u8282`}`);
530
+ return result.stdout.subarray(start, start + length);
531
+ }
532
+ };
533
+ }
534
+ var DeviceApps = class {
535
+ memory = /* @__PURE__ */ new Map();
536
+ dir;
537
+ exec;
538
+ execBuffer;
539
+ constructor(dir, exec, execBuffer) {
540
+ this.dir = dir;
541
+ this.exec = exec;
542
+ this.execBuffer = execBuffer;
543
+ }
544
+ /** Third-party apps with their base APK and its size. @throws Error when adb fails. */
545
+ async list(adb, address) {
546
+ let listed = [];
547
+ for (const command of [["pm", "list", "packages", "-3", "-f"], ["cmd", "package", "list", "packages", "-3", "-f"]]) {
548
+ const result = await this.exec(adb, ["-s", address, "shell", ...command], { timeoutMs: 3e4 });
549
+ if (result === void 0)
550
+ throw new Error("\u627E\u4E0D\u5230 adb");
551
+ listed = parsePackageList(result.stdout);
552
+ if (listed.length > 0)
553
+ break;
554
+ if (result.code !== 0 && command[0] === "cmd")
555
+ throw new Error(`\u8BFB\u4E0D\u5230\u6A21\u62DF\u5668\u91CC\u88C5\u7684\u5E94\u7528\uFF1A${(result.stderr || result.stdout).trim() || `\u9000\u51FA\u4EE3\u7801 ${result.code}`}`);
556
+ }
557
+ return this.withSizes(adb, address, listed);
558
+ }
559
+ /** One package, by `pm path` (its base APK first). */
560
+ async find(adb, address, pkg) {
561
+ const paths = await this.paths(adb, address, pkg);
562
+ if (paths[0] === void 0)
563
+ return void 0;
564
+ return (await this.withSizes(adb, address, [{ package: pkg, apk: paths[0] }]))[0];
565
+ }
566
+ async paths(adb, address, pkg) {
567
+ const result = await this.exec(adb, ["-s", address, "shell", "pm", "path", pkg], { timeoutMs: 2e4 });
568
+ const paths = (result?.stdout ?? "").split(/\r?\n/).map((l) => /^package:(.+)$/.exec(l.trim())?.[1]).filter((p) => p !== void 0);
569
+ return paths.sort((a, b) => Number(!/\/base\.apk$/.test(a)) - Number(!/\/base\.apk$/.test(b)));
570
+ }
571
+ async withSizes(adb, address, apps) {
572
+ const sizes = /* @__PURE__ */ new Map();
573
+ for (let i = 0; i < apps.length; i += 40) {
574
+ const chunk = apps.slice(i, i + 40);
575
+ const result = await this.exec(adb, ["-s", address, "shell", `stat -c '%s %n' ${chunk.map((a) => quote(a.apk)).join(" ")} 2>/dev/null`], { timeoutMs: 3e4 });
576
+ for (const line of (result?.stdout ?? "").split(/\r?\n/)) {
577
+ const m = /^(\d+) (.+)$/.exec(line.trim());
578
+ if (m !== null)
579
+ sizes.set(m[2], Number(m[1]));
580
+ }
581
+ }
582
+ return apps.map((a) => ({ ...a, ...sizes.has(a.apk) ? { size: sizes.get(a.apk) } : {} }));
583
+ }
584
+ /** The app's name and icon: from the cache when its APK has not changed, else read from the device. */
585
+ async info(adb, address, app) {
586
+ if (app.size === void 0)
587
+ return void 0;
588
+ const key = `${address}|${app.apk}|${app.size}`;
589
+ let pending = this.memory.get(key);
590
+ if (pending === void 0) {
591
+ pending = this.load(adb, address, app);
592
+ this.memory.set(key, pending);
593
+ pending.catch(() => this.memory.delete(key));
594
+ }
595
+ return pending;
596
+ }
597
+ /** What was read of a package before, whatever device it was on. */
598
+ async cached(pkg) {
599
+ try {
600
+ return JSON.parse(await readFile(this.file(pkg), "utf8"));
601
+ } catch {
602
+ return void 0;
603
+ }
604
+ }
605
+ file(pkg) {
606
+ return join(this.dir, `${pkg.replace(/[^\w.]/g, "_")}.json`);
607
+ }
608
+ async load(adb, address, app) {
609
+ const before = await this.cached(app.package);
610
+ if (before !== void 0 && before.apk === app.apk && before.size === app.size)
611
+ return before;
612
+ const base = await Zip.open(deviceFile(this.execBuffer, adb, address, app.apk, app.size));
613
+ const zips = [base];
614
+ let info = await readApkInfo(zips);
615
+ if (info.icon === void 0) {
616
+ const splits = (await this.paths(adb, address, app.package)).filter((p) => p !== app.apk);
617
+ if (splits.length > 0) {
618
+ const sized = await this.withSizes(adb, address, splits.map((apk) => ({ package: app.package, apk })));
619
+ for (const split of sized)
620
+ if (split.size !== void 0)
621
+ zips.push(await Zip.open(deviceFile(this.execBuffer, adb, address, split.apk, split.size)));
622
+ info = await readApkInfo(zips);
623
+ }
624
+ }
625
+ const entry = {
626
+ package: app.package,
627
+ apk: app.apk,
628
+ size: app.size,
629
+ ...info.label === void 0 ? {} : { label: info.label },
630
+ ...info.icon === void 0 ? {} : { icon: { mediaType: info.icon.mediaType, data: info.icon.data.toString("base64") } }
631
+ };
632
+ await mkdir(this.dir, { recursive: true });
633
+ await writeFileAtomic(this.file(app.package), `${JSON.stringify(entry)}
634
+ `);
635
+ return entry;
636
+ }
637
+ };
638
+ async function eachLimited(items, limit, fn) {
639
+ let next = 0;
640
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
641
+ while (next < items.length)
642
+ await fn(items[next++]);
643
+ }));
644
+ }
645
+
24
646
  // packages/emulator/lib/detect.js
25
647
  import { stat } from "node:fs/promises";
26
- import { dirname, join } from "node:path";
648
+ import { dirname, join as join2 } from "node:path";
27
649
  var NAMES = /(mumu player|mumuplayer|netease mumu|mumu模拟器|mumu 模拟器)/i;
28
650
  var MANAGER = "MuMuManager.exe";
29
651
  var SUBDIRS = ["shell", "nx_main", ""];
@@ -74,7 +696,7 @@ function rootsOf(entry) {
74
696
  }
75
697
  async function managerUnder(root) {
76
698
  for (const sub of SUBDIRS) {
77
- const candidate = join(root, sub, MANAGER);
699
+ const candidate = join2(root, sub, MANAGER);
78
700
  if (await stat(candidate).then((s) => s.isFile(), () => false))
79
701
  return candidate;
80
702
  }
@@ -82,7 +704,43 @@ async function managerUnder(root) {
82
704
  }
83
705
  function defaultRoots() {
84
706
  const programFiles = [process.env["ProgramFiles"] ?? "C:\\Program Files", "D:\\Program Files", "E:\\Program Files"];
85
- return programFiles.flatMap((base) => [join(base, "Netease", "MuMu Player 12"), join(base, "Netease", "MuMuPlayer-12.0"), join(base, "Netease", "MuMuPlayer"), join(base, "Netease", "MuMu")]);
707
+ return programFiles.flatMap((base) => [join2(base, "Netease", "MuMu Player 12"), join2(base, "Netease", "MuMuPlayer-12.0"), join2(base, "Netease", "MuMuPlayer"), join2(base, "Netease", "MuMu")]);
708
+ }
709
+ var MUMU_ADB = ["../../../nx_main/adb.exe", "../vmonitor/bin/adb_server.exe", "../../MuMu/emulator/nemu/vmonitor/bin/adb_server.exe", "adb.exe"];
710
+ var EMULATOR_PROCESSES = [
711
+ { process: "HD-Player", name: "BlueStacks", adb: ["HD-Adb.exe", "Engine/ProgramFiles/HD-Adb.exe"] },
712
+ { process: "dnplayer", name: "\u96F7\u7535\u6A21\u62DF\u5668", adb: ["adb.exe"] },
713
+ { process: "Nox", name: "\u591C\u795E\u6A21\u62DF\u5668", adb: ["nox_adb.exe"] },
714
+ { process: "MuMuPlayer", name: "MuMu \u6A21\u62DF\u5668", adb: MUMU_ADB },
715
+ { process: "MuMuNxDevice", name: "MuMu \u6A21\u62DF\u5668", adb: MUMU_ADB },
716
+ { process: "MEmu", name: "\u900D\u9065\u6A21\u62DF\u5668", adb: ["adb.exe"] }
717
+ ];
718
+ async function findRunningEmulators(exec) {
719
+ const names = EMULATOR_PROCESSES.map((e) => `'${e.process}'`).join(",");
720
+ const query = `Get-Process -Name ${names} -ErrorAction SilentlyContinue | Where-Object { $_.Path } | Select-Object Name, Path | ConvertTo-Json -Compress`;
721
+ const result = await exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", query], { timeoutMs: 2e4 });
722
+ if (result?.code !== 0 || result.stdout.trim() === "")
723
+ return [];
724
+ let parsed;
725
+ try {
726
+ parsed = JSON.parse(result.stdout);
727
+ } catch {
728
+ return [];
729
+ }
730
+ const out = [];
731
+ for (const p of Array.isArray(parsed) ? parsed : [parsed]) {
732
+ const known = EMULATOR_PROCESSES.find((e) => e.process.toLowerCase() === p.Name?.toLowerCase());
733
+ if (known === void 0 || p.Path === void 0 || out.some((o) => o.exe === p.Path))
734
+ continue;
735
+ for (const relative of known.adb) {
736
+ const adb = join2(dirname(p.Path), relative);
737
+ if (await stat(adb).then((s) => s.isFile(), () => false)) {
738
+ out.push({ name: known.name, exe: p.Path, adb });
739
+ break;
740
+ }
741
+ }
742
+ }
743
+ return out;
86
744
  }
87
745
 
88
746
  // packages/emulator/lib/mumu.js
@@ -238,7 +896,7 @@ function addressOf(entry) {
238
896
  var DEFAULTS = { instance: 0, autoStart: true, bootTimeoutSeconds: 180 };
239
897
  var INSTALLER_HOSTS = /(^|\.)(163\.com|netease\.com|126\.net|127\.net|nosdn\.127\.net)$/i;
240
898
  var ConfigSchema = external_exports.object({
241
- /** Settings file and nothing else: `<dataDir>/emulators.json`. */
899
+ /** Settings: `<dataDir>/emulators.json`; apps' names and icons read from the emulator: `<dataDir>/android-apps/`. */
242
900
  dataDir: external_exports.string().min(1),
243
901
  /** Where installers are downloaded: `<sharedDir>/downloads`. */
244
902
  sharedDir: external_exports.string().min(1)
@@ -265,14 +923,21 @@ var AdgEmulators = class extends Service {
265
923
  execBuffer;
266
924
  settings = DEFAULTS;
267
925
  found;
926
+ /** Emulators running a moment ago (MAA's process table), for their adb.exe. */
927
+ running;
928
+ /** Installed apps, their names and icons (apps.ts). */
929
+ apps;
930
+ /** Packages whose icon could not be read just now: not asked of the device again for a while. */
931
+ iconMisses = /* @__PURE__ */ new Map();
268
932
  ready;
269
933
  constructor(ctx, config, exec = systemExec, execBuffer = systemExecBuffer) {
270
934
  super(ctx, "adgEmulators");
271
935
  const spec = ConfigSchema.parse(config);
272
- this.file = join2(spec.dataDir, "emulators.json");
936
+ this.file = join3(spec.dataDir, "emulators.json");
273
937
  this.sharedDir = spec.sharedDir;
274
938
  this.exec = exec;
275
939
  this.execBuffer = execBuffer;
940
+ this.apps = new DeviceApps(join3(spec.dataDir, "android-apps"), exec, execBuffer);
276
941
  this.ready = this.load();
277
942
  const log = ctx.logger("adg-emulators");
278
943
  ctx.inject(["adgScripts"], (scoped) => {
@@ -485,7 +1150,7 @@ var AdgEmulators = class extends Service {
485
1150
  const name = basename(decodeURIComponent(parsed.pathname)) || "mumu-installer.exe";
486
1151
  if (!/\.exe$/i.test(name))
487
1152
  throw new Error(`\u4E0B\u8F7D\u5730\u5740\u4E0D\u662F\u5B89\u88C5\u7A0B\u5E8F\uFF08.exe\uFF09\uFF1A${name}`);
488
- const dest = join2(this.sharedDir, "downloads", name);
1153
+ const dest = join3(this.sharedDir, "downloads", name);
489
1154
  onProgress(`\u4E0B\u8F7D ${name}`);
490
1155
  await download({ url, dest, signal, onProgress: (received, total) => onProgress(`\u4E0B\u8F7D\u4E2D ${Math.round(received / 1048576)} / ${total === void 0 ? "?" : Math.round(total / 1048576)} MB`) });
491
1156
  onProgress("\u8FD0\u884C\u5B89\u88C5\u7A0B\u5E8F\uFF08\u53EF\u80FD\u51FA\u73B0\u5B89\u88C5\u5411\u5BFC\u548C\u7BA1\u7406\u5458\u6388\u6743\uFF09");
@@ -497,25 +1162,131 @@ var AdgEmulators = class extends Service {
497
1162
  const path = this.settings.mumuManager ?? (await this.detected())[0]?.manager;
498
1163
  return path === void 0 ? void 0 : new MuMuManager(path, this.exec);
499
1164
  }
500
- /** adb.exe: the configured one, else MuMu's own next to MuMuManager.exe, else `adb` on PATH. */
1165
+ /**
1166
+ * adb.exe: the configured one, else MuMu's own next to MuMuManager.exe,
1167
+ * else the one a running emulator ships (found as MAA finds it), else `adb` on PATH.
1168
+ */
501
1169
  async adb() {
502
1170
  if (this.settings.adbPath !== void 0)
503
1171
  return this.settings.adbPath;
504
1172
  const manager = this.settings.mumuManager ?? (await this.detected())[0]?.manager;
505
1173
  if (manager !== void 0) {
506
- const sibling = join2(dirname2(manager), "adb.exe");
1174
+ const sibling = join3(dirname2(manager), "adb.exe");
507
1175
  if (await access(sibling).then(() => true, () => false))
508
1176
  return sibling;
509
1177
  }
1178
+ if (process.platform === "win32") {
1179
+ if (this.running === void 0 || Date.now() - this.running.at > 6e4)
1180
+ this.running = { at: Date.now(), list: findRunningEmulators(this.exec).catch(() => []) };
1181
+ const running = (await this.running.list)[0];
1182
+ if (running !== void 0)
1183
+ return running.adb;
1184
+ }
510
1185
  return "adb";
511
1186
  }
1187
+ /** `adb connect` a host:port address that does not answer yet (an emulator's address needs it once per adb server). */
1188
+ async connect(adb, address) {
1189
+ const state = await this.exec(adb, ["-s", address, "get-state"], { timeoutMs: 1e4 });
1190
+ if (state === void 0)
1191
+ throw new Error(`\u627E\u4E0D\u5230 adb\uFF08${adb}\uFF09\u3002\u53EF\u4EE5\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u62DF\u5668\u300D\u586B\u5199 adb.exe \u7684\u4F4D\u7F6E`);
1192
+ if (state.stdout.trim() === "device")
1193
+ return;
1194
+ if (!/^[\w.-]+:\d+$/.test(address))
1195
+ throw new Error(`\u8BBE\u5907 ${address} \u6CA1\u6709\u8FDE\u63A5\uFF1A${(state.stderr || state.stdout).trim()}`);
1196
+ const connected = await this.exec(adb, ["connect", address], { timeoutMs: 2e4 });
1197
+ if (connected === void 0 || !/connected to|already connected/i.test(connected.stdout)) {
1198
+ throw new Error(`\u8FDE\u4E0D\u4E0A\u6A21\u62DF\u5668 ${address}\uFF1A${((connected?.stdout ?? "") + (connected?.stderr ?? "")).trim() || "\u6CA1\u6709\u8F93\u51FA"}`);
1199
+ }
1200
+ }
1201
+ // ── apps in the emulator ──────────────────────────────────────────────
1202
+ /**
1203
+ * The installed apps that are the game the hints describe, best first, with
1204
+ * their names and icons. Starts the emulator tasks use when it is not up
1205
+ * (as a run would). Every app's name is read once (from its APK) and kept,
1206
+ * so a game known only by its name is found too.
1207
+ */
1208
+ async findApps(hints, signal, onStatus = () => {
1209
+ }, options = {}) {
1210
+ let target;
1211
+ if (options.start === false) {
1212
+ await this.ready;
1213
+ const address = await this.upAddress();
1214
+ if (address === void 0)
1215
+ throw new Error("\u6A21\u62DF\u5668\u6CA1\u6709\u8FD0\u884C");
1216
+ target = { address, label: this.settings.manualAddress === void 0 ? `MuMu ${this.settings.instance}` : "\u624B\u52A8\u914D\u7F6E\u7684 ADB \u5730\u5740" };
1217
+ } else {
1218
+ target = await this.prepare({ signal, onStatus });
1219
+ }
1220
+ const adb = await this.adb();
1221
+ await this.connect(adb, target.address);
1222
+ onStatus("\u8BFB\u53D6\u6A21\u62DF\u5668\u91CC\u88C5\u7684\u5E94\u7528");
1223
+ const listed = await this.apps.list(adb, target.address);
1224
+ const read = /* @__PURE__ */ new Map();
1225
+ await eachLimited(listed, 4, async (app) => {
1226
+ if (signal.aborted)
1227
+ return;
1228
+ const info = await this.apps.info(adb, target.address, app).catch(() => void 0);
1229
+ if (info !== void 0)
1230
+ read.set(app.package, info);
1231
+ });
1232
+ const apps = listed.map((a) => {
1233
+ const label = read.get(a.package)?.label;
1234
+ return label === void 0 ? a : { ...a, label };
1235
+ });
1236
+ const candidates = rankApps(apps, hints).slice(0, 8).map((c) => {
1237
+ this.iconMisses.delete(c.package);
1238
+ const icon = read.get(c.package)?.icon;
1239
+ return icon === void 0 ? c : { ...c, icon };
1240
+ });
1241
+ return { device: target.label, installed: listed.length, candidates };
1242
+ }
1243
+ /**
1244
+ * An app's name and icon as last read. `live`: when none was kept, read it
1245
+ * now if the emulator tasks use is already up (it is never started for this).
1246
+ */
1247
+ async appInfo(pkg, live = false) {
1248
+ await this.ready;
1249
+ const cached = await this.apps.cached(pkg);
1250
+ if (cached !== void 0 || !live)
1251
+ return cached;
1252
+ const missed = this.iconMisses.get(pkg);
1253
+ if (missed !== void 0 && Date.now() - missed < 5 * 6e4)
1254
+ return void 0;
1255
+ this.iconMisses.set(pkg, Date.now());
1256
+ try {
1257
+ const address = await this.upAddress();
1258
+ if (address === void 0)
1259
+ return void 0;
1260
+ const adb = await this.adb();
1261
+ await this.connect(adb, address);
1262
+ const app = await this.apps.find(adb, address, pkg);
1263
+ const info = app === void 0 ? void 0 : await this.apps.info(adb, address, app);
1264
+ if (info !== void 0)
1265
+ this.iconMisses.delete(pkg);
1266
+ return info;
1267
+ } catch {
1268
+ return void 0;
1269
+ }
1270
+ }
1271
+ /** The address tasks use when that emulator is running now; undefined when it is not (or is not known). */
1272
+ async upAddress() {
1273
+ if (this.settings.manualAddress !== void 0)
1274
+ return this.settings.manualAddress;
1275
+ const mumu = await this.manager();
1276
+ if (mumu === void 0)
1277
+ return void 0;
1278
+ const current = await mumu.instance(this.settings.instance).catch(() => void 0);
1279
+ if (current?.ready !== true)
1280
+ return void 0;
1281
+ return current.adb ?? await mumu.adbAddress(this.settings.instance).catch(() => void 0);
1282
+ }
512
1283
  async detected() {
513
1284
  this.found ??= await findMuMu(this.exec);
514
1285
  return this.found;
515
1286
  }
516
1287
  async load() {
517
1288
  try {
518
- this.settings = EmulatorSettings.parse({ ...DEFAULTS, ...JSON.parse(await readFile(this.file, "utf8")) });
1289
+ this.settings = EmulatorSettings.parse({ ...DEFAULTS, ...JSON.parse(await readFile2(this.file, "utf8")) });
519
1290
  } catch {
520
1291
  this.settings = DEFAULTS;
521
1292
  }
@@ -555,6 +1326,22 @@ var AdgEmulators = class extends Service {
555
1326
  execute: async (a, signal) => this.prepare({ index: optionalIndex(a["index"]), signal, onStatus: () => {
556
1327
  } })
557
1328
  }),
1329
+ tool({
1330
+ name: "emulator_apps",
1331
+ description: "\u5728\u4EFB\u52A1\u7528\u7684\u6A21\u62DF\u5668\u91CC\u627E\u67D0\u4E2A\u6E38\u620F\u7684\u5B89\u5353\u5305\u540D\uFF1A\u8BFB\u51FA\u88C5\u4E86\u54EA\u4E9B\u5E94\u7528\uFF08pm list packages -3\uFF09\u548C\u6BCF\u4E2A\u5E94\u7528\u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u6309\u5DF2\u77E5\u5305\u540D\u3001\u540C\u4E00\u5305\u540D\u7684\u5176\u4ED6\u7248\u672C\uFF08B\u670D\u3001\u6E20\u9053\u670D\uFF09\u548C\u5E94\u7528\u540D\u6392\u5E8F\u3002\u5199\u811A\u672C\u5305\u7684 game.android.package \u6216\u56DE\u7B54\u300C\u5305\u540D\u662F\u4EC0\u4E48\u300D\u65F6\u7528\uFF0C\u4E0D\u8981\u731C\u5305\u540D\u3002\u6A21\u62DF\u5668\u6CA1\u5F00\u65F6\u4F1A\u5148\u542F\u52A8\u5B83\u3002",
1332
+ properties: {
1333
+ name: { type: "string", description: "\u6E38\u620F\u540D\uFF08\u4E5F\u53EF\u4EE5\u662F\u522B\u540D\uFF09\uFF0C\u548C\u5E94\u7528\u540D\u6BD4\u8F83\u3002" },
1334
+ packages: { type: "array", items: { type: "string" }, description: '\u5DF2\u77E5\u6216\u731C\u6D4B\u7684\u5305\u540D\uFF0C\u4F8B\u5982 ["com.hypergryph.arknights"]\uFF1B\u5B83\u7684\u5176\u4ED6\u7248\u672C\u4E5F\u4F1A\u627E\u51FA\u6765\u3002' }
1335
+ },
1336
+ timeoutMs: 15 * 6e4,
1337
+ title: "\u67E5\u627E\u6A21\u62DF\u5668\u91CC\u7684\u6E38\u620F",
1338
+ execute: async (a, signal) => {
1339
+ const names = typeof a["name"] === "string" && a["name"].trim() !== "" ? [a["name"].trim()] : [];
1340
+ const packages = Array.isArray(a["packages"]) ? a["packages"].filter((p) => typeof p === "string").map((p) => ({ package: p.trim(), source: "\u4F60\u7ED9\u7684\u5305\u540D" })) : [];
1341
+ const found = await this.findApps({ packages, names }, signal);
1342
+ return { ...found, candidates: found.candidates.map(({ icon: _icon, ...c }) => c) };
1343
+ }
1344
+ }),
558
1345
  tool({
559
1346
  name: "emulator_stop",
560
1347
  description: "\u5173\u95ED\u6A21\u62DF\u5668\u5B9E\u4F8B\u3002",
@@ -602,11 +1389,22 @@ var AdgEmulators = class extends Service {
602
1389
  var lib_default = AdgEmulators;
603
1390
  export {
604
1391
  AdgEmulators,
1392
+ DeviceApps,
1393
+ EMULATOR_PROCESSES,
605
1394
  MuMuManager,
1395
+ ResourceTable,
1396
+ Zip,
606
1397
  lib_default as default,
607
1398
  defaultMumuPort,
608
1399
  findMuMu,
1400
+ findRunningEmulators,
1401
+ parsePackageList,
609
1402
  parsePolluted,
1403
+ parseXml,
1404
+ pickIconFile,
1405
+ pickLabel,
1406
+ rankApps,
1407
+ readApkInfo,
610
1408
  systemExec,
611
1409
  systemExecBuffer
612
1410
  };