@androperator/emulator-macos-tweaks 1.0.2 → 1.0.4
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 +21 -10
- package/assets/launcher/launcher +0 -0
- package/assets/launcher/manifest.json +2 -2
- package/bin/androperator-emulator-tweaks.js +1 -1
- package/package.json +1 -1
- package/src/core.js +41 -20
- package/src/names.js +10 -7
- package/src/png.js +12 -5
- package/src/launch.mjs +0 -72
package/README.md
CHANGED
|
@@ -16,12 +16,13 @@ This is an independent CLI. It does not depend on ADBuddy or change emulator lau
|
|
|
16
16
|
|
|
17
17
|
## Requirements and supported builds
|
|
18
18
|
|
|
19
|
-
- macOS 14 or newer
|
|
19
|
+
- macOS 14 or newer. The CLI requires Node.js 22 or newer.
|
|
20
20
|
- Write access to your Android SDK and backup location; do not run with sudo.
|
|
21
|
-
- Android Emulator
|
|
22
|
-
- Executable SHA-256: `eaa97a970b81f81640db73ed79e19ee173323653a0a1203217e1199d078011f3`.
|
|
21
|
+
- An Apple Silicon Android Emulator GUI binary with a compatible Mach-O layout and embedded icons.
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
The reference build is 37.1.11, build 15917651. Compatibility checks use the
|
|
24
|
+
executable structure and embedded icon contents across SDK revisions, including
|
|
25
|
+
different major versions. Intel binaries are unsupported.
|
|
25
26
|
|
|
26
27
|
Patching replaces Google's signature with a **local ad-hoc signature**, preserving the original entitlements and hardened runtime. The modified emulator is no longer Google-signed or notarized. No developer certificate or private key is used. Gatekeeper may treat the patched emulator differently. The CLI does not disable Gatekeeper or change system security settings.
|
|
27
28
|
|
|
@@ -92,12 +93,11 @@ reports `names` and `namingHealthy`; `restore` restores the exact original
|
|
|
92
93
|
backend and removes an unchanged managed naming configuration. Unrecognized
|
|
93
94
|
configuration files are never overwritten or deleted.
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
backup directory in place: it contains the backend, dispatcher, launch script,
|
|
96
|
+
The native dispatcher prepares launches without Node.js. If you installed an
|
|
97
|
+
earlier Node-backed naming patch, reapply with this CLI to migrate it. Keep the
|
|
98
|
+
printed backup directory in place. It contains the backend, dispatcher,
|
|
99
99
|
configuration and per-AVD SDK copies. Missing or corrupt naming resources stop
|
|
100
|
-
launching with an error
|
|
100
|
+
launching with an error. The CLI can still restore the original.
|
|
101
101
|
The first launch copies the backend for that AVD. Later launches reuse the
|
|
102
102
|
hash-verified copy. These copies link SDK libraries and system images and must
|
|
103
103
|
not be used for SDK maintenance. No AVD data is copied or renamed.
|
|
@@ -120,7 +120,7 @@ node scripts/verify-names.mjs
|
|
|
120
120
|
|
|
121
121
|
Tests use synthetic executables and fake process integrations. They require neither an Android SDK nor a device. macOS CI runs on Node.js 22 and 24. Real signing and boot checks supplement these tests for the supported build.
|
|
122
122
|
|
|
123
|
-
To add support for a build, use an untouched, signature-verified vendor executable. Record its revision, build ID, architecture, full SHA-256, and each original PNG hash and allocation length in `src/profiles.json`. The patcher discovers images by content rather than fixed offsets. Provide replacement PNGs that fit those allocations exactly, with valid chunks and checksums. Verify signing, boot, Dock appearance, and exact restore on that build before adding it to the support table.
|
|
123
|
+
To add support for a build, use an untouched, signature-verified vendor executable. Record its revision, build ID, architecture, full SHA-256, and each original PNG hash and allocation length in `src/profiles.json`. The patcher discovers images by content rather than fixed offsets. Provide replacement PNGs that fit those allocations exactly, with valid chunks and checksums. Verify signing, boot, Dock appearance, and exact restore on that build before adding it to the support table. New layouts require a new verified profile; a compatible new build does not require a separate profile.
|
|
124
124
|
|
|
125
125
|
The editable `assets/Emulator.icon` source uses a vector phone/Android symbol, white background, and Apple's native icon renderer. The bundled 32, 128 and 256 pixel PNGs were compiled with Xcode's asset compiler and palette-compressed to fit the emulator's allocations. Xcode is not required by CLI users. Native helper source is in `native/`; `node scripts/build-runtime.mjs` rebuilds the packaged arm64 helper and all five icons and writes their content manifest. `npm run build:launcher` rebuilds the AVD dispatcher and its manifest. Rebuild and run native verification after changing those sources; review the regenerated manifest and runtime files together.
|
|
126
126
|
|
|
@@ -135,3 +135,14 @@ Android is a trademark of Google LLC. This project is not affiliated with or end
|
|
|
135
135
|
Written by clankers. Engineered by [@chrismlacy](https://x.com/chrismlacy).
|
|
136
136
|
|
|
137
137
|
Copyright (C) 2026 Action Launcher Pty Ltd
|
|
138
|
+
|
|
139
|
+
### Compatibility across SDK updates
|
|
140
|
+
|
|
141
|
+
Apple Silicon builds can be patched when their arm64 Mach-O structure and
|
|
142
|
+
embedded icons match a bundled profile. The patcher checks icon contents,
|
|
143
|
+
dimensions, checksums, unique allocations and load-command padding. Status JSON
|
|
144
|
+
includes `supportedVersions` and `compatibilityReason` for diagnosis.
|
|
145
|
+
|
|
146
|
+
Apply and restore still verify exact hashes for the installed executable and
|
|
147
|
+
its backups. The dispatcher also checks that the SDK revision matches the
|
|
148
|
+
patch generation before launching a cached backend against that SDK's libraries.
|
package/assets/launcher/launcher
CHANGED
|
Binary file
|
|
@@ -34,7 +34,7 @@ try {
|
|
|
34
34
|
throw new Error("apply requires --accept-adhoc-signing. Applying this patch replaces Google's signature with a local ad-hoc signature while preserving its entitlements and hardened runtime. No developer certificate or private key is used. Gatekeeper may treat the patched emulator differently. Restore reinstates the original executable and Google's signature. No files changed.\nRun: androperator-emulator-tweaks apply --accept-adhoc-signing");
|
|
35
35
|
}
|
|
36
36
|
const result = await ({ status: inspect, apply, restore }[command])({ sdk: values.sdk, backupDir: values['backup-dir'], icons: values.icons, names: values.names });
|
|
37
|
-
const output = { command, names: result.names, namingHealthy: result.namingHealthy, icons: result.icons, runtimeHealthy: result.runtimeHealthy, sdk: result.sdk, revision: result.revision, state: result.state, changed: result.changed ?? false, executable: result.target, sha256: result.targetHash, backup: result.backup ?? result.receipt?.directory ?? null };
|
|
37
|
+
const output = { compatibilityReason: result.compatibilityReason, supportedVersions: result.supportedVersions, command, names: result.names, namingHealthy: result.namingHealthy, icons: result.icons, runtimeHealthy: result.runtimeHealthy, sdk: result.sdk, revision: result.revision, state: result.state, changed: result.changed ?? false, executable: result.target, sha256: result.targetHash, backup: result.backup ?? result.receipt?.directory ?? null };
|
|
38
38
|
// Refresh the reported hash after a successful mutation.
|
|
39
39
|
if (result.changed) output.sha256 = (await inspect({ sdk: values.sdk, backupDir: values['backup-dir'] })).targetHash;
|
|
40
40
|
console.log(values.json ? JSON.stringify(output, null, 2) : `${result.state}${result.names === 'avd' ? ` (AVD names${result.namingHealthy === false ? ', naming runtime missing or corrupt; restore remains available' : ''})` : ''}${result.icons ? ` (${result.icons} icons${result.runtimeHealthy === false ? ', runtime missing or corrupt; restore remains available' : ''})` : ''}: Android Emulator ${result.revision}\n${result.target}${output.backup ? `\nBackup: ${output.backup}` : ''}${result.changed ? '\nRestart emulators to see the change.' : ''}`);
|
package/package.json
CHANGED
package/src/core.js
CHANGED
|
@@ -3,15 +3,33 @@ import { resolve, join, dirname } from 'node:path';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { sha256, patchImages } from './png.js';
|
|
6
|
+
import { sha256, patchImages, locateIcons } from './png.js';
|
|
7
7
|
import { macOS } from './platform.js';
|
|
8
8
|
import { addIconHelper } from './macho.js';
|
|
9
9
|
import { readRuntime, copyRuntime, verifyRuntime, runtimeHash } from './runtime.js';
|
|
10
|
-
import { readNamingBundle, configurationHash, verifyNaming, installConfiguration, removeConfiguration } from './names.js';
|
|
10
|
+
import { readNamingBundle, configurationHash, isNamingReceipt, verifyNaming, installConfiguration, removeConfiguration } from './names.js';
|
|
11
11
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
12
12
|
const bundledProfiles = JSON.parse(await readFile(new URL('./profiles.json', import.meta.url)));
|
|
13
13
|
const hashFile = async file => sha256(await readFile(file));
|
|
14
14
|
|
|
15
|
+
async function resolveProfile(bytes, revision, profiles, binary) {
|
|
16
|
+
const hash = sha256(bytes);
|
|
17
|
+
const exact = profiles.find(item => item.revision === revision && item.sha256 === hash && item.binary === binary);
|
|
18
|
+
if (exact) return { profile: exact, compatibilityReason: null };
|
|
19
|
+
const candidates = profiles.filter(item => item.binary === binary);
|
|
20
|
+
if (!candidates.length) return { profile: null, compatibilityReason: 'Requires an Apple Silicon emulator at a supported GUI executable path.' };
|
|
21
|
+
let compatibilityReason;
|
|
22
|
+
for (const template of candidates) {
|
|
23
|
+
try {
|
|
24
|
+
addIconHelper(bytes, '/compatibility-check/helper.dylib');
|
|
25
|
+
const profile = { ...template, revision, build: 'structurally compatible', sha256: hash };
|
|
26
|
+
locateIcons(bytes, profile);
|
|
27
|
+
return { profile, compatibilityReason: null };
|
|
28
|
+
} catch (error) { compatibilityReason = error.message; }
|
|
29
|
+
}
|
|
30
|
+
return { profile: null, compatibilityReason };
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
async function atomicJSON(file, value) {
|
|
16
34
|
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
17
35
|
const handle = await open(temporary, 'wx', 0o600);
|
|
@@ -62,11 +80,11 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
62
80
|
try {
|
|
63
81
|
if (!(await lstat(receiptPath)).isFile()) throw new Error('Invalid backup receipt');
|
|
64
82
|
const receipt = JSON.parse(await readFile(receiptPath, 'utf8'));
|
|
65
|
-
if (![1, 2, 3].includes(receipt.schema) || receipt.target !== target || receipt.originalHash !== name.slice(0, 64) || !/^[a-f0-9]{64}$/.test(receipt.patchedHash ?? '') || !['prepared','applied','restored'].includes(receipt.state)) throw new Error('Invalid backup receipt');
|
|
83
|
+
if (![1, 2, 3, 4].includes(receipt.schema) || receipt.target !== target || receipt.originalHash !== name.slice(0, 64) || !/^[a-f0-9]{64}$/.test(receipt.patchedHash ?? '') || !['prepared','applied','restored'].includes(receipt.state)) throw new Error('Invalid backup receipt');
|
|
66
84
|
if (receipt.schema === 1 && name !== receipt.originalHash) throw new Error('Invalid legacy backup directory');
|
|
67
85
|
if (receipt.schema === 2 && (receipt.icons !== 'auto' || name !== `${receipt.originalHash}-automatic-${runtimeHash(receipt.runtime)}`)) throw new Error('Invalid automatic backup directory');
|
|
68
|
-
if (receipt
|
|
69
|
-
if (receipt
|
|
86
|
+
if (isNamingReceipt(receipt) && (name !== `${receipt.originalHash}-names-${receipt.namesHash}` || !['auto', 'phone'].includes(receipt.icons) || ![receipt.namesHash, receipt.backendHash, receipt.configHash, ...(receipt.schema === 3 ? [receipt.scriptHash] : [])].every(hash => /^[a-f0-9]{64}$/.test(hash ?? '')))) throw new Error('Invalid naming backup directory');
|
|
87
|
+
if (isNamingReceipt(receipt) && receipt.icons === 'auto') runtimeHash(receipt.runtime);
|
|
70
88
|
receipts.push({ ...receipt, directory: join(folder, name) });
|
|
71
89
|
} catch (error) {
|
|
72
90
|
throw new Error(`Cannot read backup receipt ${receiptPath}: ${error.message}`);
|
|
@@ -74,8 +92,11 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
74
92
|
}
|
|
75
93
|
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
76
94
|
const configHash = await configurationHash(target);
|
|
77
|
-
const receipt = receipts.find(record => record
|
|
78
|
-
const
|
|
95
|
+
const receipt = receipts.find(record => isNamingReceipt(record) && record.configHash === configHash && [record.patchedHash, record.originalHash].includes(targetHash)) ?? receipts.find(record => record.patchedHash === targetHash) ?? receipts.find(record => record.originalHash === targetHash);
|
|
96
|
+
const originalSource = receipt?.patchedHash === targetHash ? join(receipt.directory, 'original') : target;
|
|
97
|
+
const originalBytes = await readFile(originalSource);
|
|
98
|
+
if (receipt?.patchedHash === targetHash && sha256(originalBytes) !== receipt.originalHash) throw new Error('Original backup is corrupt');
|
|
99
|
+
const { profile, compatibilityReason } = await resolveProfile(originalBytes, revision, profiles, target.slice(sdk.length + '/emulator/'.length));
|
|
79
100
|
const state = receipt?.patchedHash === targetHash ? 'patched' : profile ? 'original' : 'unsupported';
|
|
80
101
|
let runtimeHealthy = null;
|
|
81
102
|
if (receipt?.runtime && state === 'patched') {
|
|
@@ -83,13 +104,13 @@ export async function inspect({ sdk: explicit, backupDir, profiles = bundledProf
|
|
|
83
104
|
catch { runtimeHealthy = false; }
|
|
84
105
|
}
|
|
85
106
|
const icons = state === 'patched' ? (receipt.icons ?? 'phone') : null;
|
|
86
|
-
const names = state === 'patched' && receipt
|
|
107
|
+
const names = state === 'patched' && isNamingReceipt(receipt) ? 'avd' : 'off';
|
|
87
108
|
let namingHealthy = null;
|
|
88
109
|
if (names === 'avd') {
|
|
89
110
|
try { await verifyNaming(receipt); namingHealthy = configHash === receipt.configHash; }
|
|
90
111
|
catch { namingHealthy = false; }
|
|
91
112
|
}
|
|
92
|
-
return { configHash, names, namingHealthy, icons, runtimeHealthy, sdk, revision, target, targetHash, storage, folder, targetId, state, receipt, profile, adapter, mode: info.mode & 0o777, receipts };
|
|
113
|
+
return { compatibilityReason, supportedVersions: ['Apple Silicon builds with compatible binary and icons'], configHash, names, namingHealthy, icons, runtimeHealthy, sdk, revision, target, targetHash, storage, folder, targetId, state, receipt, profile, adapter, mode: info.mode & 0o777, receipts };
|
|
93
114
|
}
|
|
94
115
|
|
|
95
116
|
async function withLock(context, operation) {
|
|
@@ -129,16 +150,17 @@ export async function apply(options = {}) {
|
|
|
129
150
|
const context = await inspect(options);
|
|
130
151
|
const runtimeDirectory = options.runtimeDir ?? join(packageRoot, 'assets/runtime');
|
|
131
152
|
const originalHash = context.state === 'patched' ? context.receipt.originalHash : context.targetHash;
|
|
132
|
-
const profile =
|
|
133
|
-
if (!profile) throw new Error(`Unsupported emulator ${context.revision ?? 'version'} (${context.targetHash}). No files changed.
|
|
153
|
+
const profile = context.profile;
|
|
154
|
+
if (!profile) throw new Error(`Unsupported emulator ${context.revision ?? 'version'} (${context.targetHash}). No files changed. ${context.compatibilityReason}`);
|
|
134
155
|
const bundle = icons === 'auto' ? await readRuntime(runtimeDirectory, context.adapter) : null;
|
|
135
|
-
const naming = names === 'avd' ? await readNamingBundle(options.packageRoot ?? packageRoot, context.adapter
|
|
156
|
+
const naming = names === 'avd' ? await readNamingBundle(options.packageRoot ?? packageRoot, context.adapter) : null;
|
|
157
|
+
if (naming && !context.revision) throw new Error('Cannot verify the installed SDK revision for AVD naming');
|
|
136
158
|
const namesHash = naming ? sha256(Buffer.from(JSON.stringify([naming.hash, icons, bundle?.hash ?? null]))) : null;
|
|
137
159
|
const directory = join(context.folder, naming ? `${originalHash}-names-${namesHash}` : icons === 'auto' ? `${originalHash}-automatic-${bundle.hash}` : originalHash);
|
|
138
160
|
return withLock(context, async () => {
|
|
139
161
|
await context.adapter.verify(context.target);
|
|
140
162
|
const activeConfig = await configurationHash(context.target);
|
|
141
|
-
if (activeConfig && !context.receipts.some(record => record
|
|
163
|
+
if (activeConfig && !context.receipts.some(record => isNamingReceipt(record) && record.configHash === activeConfig)) throw new Error('Unrecognized naming configuration; nothing overwritten');
|
|
142
164
|
const existing = context.receipts.find(record => record.directory === directory);
|
|
143
165
|
if (existing) {
|
|
144
166
|
if (await hashFile(join(directory, 'original')) !== originalHash) throw new Error('Original backup is corrupt; refusing to replace it');
|
|
@@ -147,12 +169,12 @@ export async function apply(options = {}) {
|
|
|
147
169
|
await verifyRuntime(join(directory, 'runtime'), existing.runtime);
|
|
148
170
|
await context.adapter.verify(join(directory, 'runtime/helper.dylib'));
|
|
149
171
|
}
|
|
150
|
-
if (existing
|
|
172
|
+
if (isNamingReceipt(existing)) {
|
|
151
173
|
await verifyNaming(existing);
|
|
152
174
|
await context.adapter.verify(join(directory, 'backend'));
|
|
153
175
|
await installConfiguration(context, existing);
|
|
154
176
|
}
|
|
155
|
-
if (context.targetHash === existing.patchedHash && (existing
|
|
177
|
+
if (context.targetHash === existing.patchedHash && (!isNamingReceipt(existing) || activeConfig === existing.configHash)) return { ...context, changed: false };
|
|
156
178
|
await replace(context, join(directory, 'patched'), existing.patchedHash);
|
|
157
179
|
if (!naming) await removeConfiguration(context);
|
|
158
180
|
await atomicJSON(join(directory, 'receipt.json'), { ...existing, directory: undefined, state: 'applied' });
|
|
@@ -181,16 +203,15 @@ export async function apply(options = {}) {
|
|
|
181
203
|
if (naming) {
|
|
182
204
|
const backend = join(preparation, 'backend');
|
|
183
205
|
await rename(candidate, backend);
|
|
184
|
-
const backendHash = await hashFile(backend)
|
|
185
|
-
|
|
186
|
-
const configuration = { schema: 1, sdk: context.sdk, target: context.target, directory, revision: context.revision, node: naming.node, script: join(directory, 'launch.mjs'), backend: join(directory, 'backend'), backendHash, scriptHash };
|
|
206
|
+
const backendHash = await hashFile(backend);
|
|
207
|
+
const configuration = { schema: 2, sdk: context.sdk, target: context.target, directory, revision: context.revision, backendHash };
|
|
187
208
|
await atomicJSON(join(preparation, 'launch.json'), configuration);
|
|
188
|
-
namingFields = { namesHash, backendHash,
|
|
209
|
+
namingFields = { namesHash, backendHash, configHash: await hashFile(join(preparation, 'launch.json')) };
|
|
189
210
|
await context.adapter.copy(naming.launcher, candidate);
|
|
190
211
|
await context.adapter.sign(backup, candidate, preparation);
|
|
191
212
|
}
|
|
192
213
|
const patchedHash = await hashFile(candidate);
|
|
193
|
-
const receipt = { schema: naming ?
|
|
214
|
+
const receipt = { schema: naming ? 4 : bundle ? 2 : 1, target: context.target, revision: context.revision, build: profile.build, originalHash, patchedHash, state: 'prepared', created: new Date().toISOString(), slots, ...(bundle ? { icons, runtime: bundle.manifest } : {}), ...(naming ? { icons, ...namingFields } : {}) };
|
|
194
215
|
for (const file of [backup, candidate]) {
|
|
195
216
|
const handle = await open(file, 'r');
|
|
196
217
|
try { await handle.sync(); } finally { await handle.close(); }
|
package/src/names.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFile, lstat, writeFile, rename, rm } from 'node:fs/promises';
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { sha256 } from './png.js';
|
|
5
|
+
export const isNamingReceipt = receipt => receipt.schema === 3 || receipt.schema === 4;
|
|
5
6
|
export const configurationPath = target => join(dirname(target), '.emulator-tweaks-launch.json');
|
|
6
7
|
export async function configurationHash(target) {
|
|
7
8
|
try {
|
|
@@ -10,24 +11,26 @@ export async function configurationHash(target) {
|
|
|
10
11
|
return sha256(await readFile(path));
|
|
11
12
|
} catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
12
13
|
}
|
|
13
|
-
export async function readNamingBundle(root, adapter
|
|
14
|
+
export async function readNamingBundle(root, adapter) {
|
|
14
15
|
const directory = join(root, 'assets/launcher');
|
|
15
16
|
const manifest = JSON.parse(await readFile(join(directory, 'manifest.json'), 'utf8'));
|
|
16
17
|
const launcher = join(directory, 'launcher');
|
|
17
|
-
const bytes = await readFile(launcher)
|
|
18
|
-
if (bytes.length < 16 || manifest.schema !==
|
|
18
|
+
const bytes = await readFile(launcher);
|
|
19
|
+
if (bytes.length < 16 || manifest.schema !== 2 || manifest.architecture !== 'arm64' || sha256(bytes) !== manifest.sha256 || bytes.readUInt32LE(0) !== 0xfeedfacf || bytes.readUInt32LE(4) !== 0x100000c || bytes.readUInt32LE(12) !== 2) throw new Error('Invalid bundled AVD launcher');
|
|
19
20
|
await adapter.verify(launcher);
|
|
20
|
-
return { launcher,
|
|
21
|
+
return { launcher, hash: manifest.sha256 };
|
|
21
22
|
}
|
|
22
23
|
export async function verifyNaming(receipt) {
|
|
23
|
-
|
|
24
|
+
const files = [['backend', receipt.backendHash], ['launch.json', receipt.configHash]];
|
|
25
|
+
if (receipt.schema === 3) files.push(['launch.mjs', receipt.scriptHash]);
|
|
26
|
+
for (const [name, expected] of files) {
|
|
24
27
|
const path = join(receipt.directory, name), info = await lstat(path);
|
|
25
28
|
if (!info.isFile() || info.isSymbolicLink() || sha256(await readFile(path)) !== expected) throw new Error('Naming runtime is missing or corrupt');
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
export async function installConfiguration(context, receipt) {
|
|
29
32
|
const current = await configurationHash(context.target);
|
|
30
|
-
if (current && !context.receipts.some(record => record
|
|
33
|
+
if (current && !context.receipts.some(record => isNamingReceipt(record) && record.configHash === current)) throw new Error('Unrecognized naming configuration; nothing overwritten');
|
|
31
34
|
const temporary = `${configurationPath(context.target)}.${randomUUID()}.tmp`;
|
|
32
35
|
try {
|
|
33
36
|
await writeFile(temporary, await readFile(join(receipt.directory, 'launch.json')), { flag: 'wx', mode: 0o600 });
|
|
@@ -36,5 +39,5 @@ export async function installConfiguration(context, receipt) {
|
|
|
36
39
|
}
|
|
37
40
|
export async function removeConfiguration(context) {
|
|
38
41
|
const current = await configurationHash(context.target);
|
|
39
|
-
if (current && context.receipts.some(record => record
|
|
42
|
+
if (current && context.receipts.some(record => isNamingReceipt(record) && record.configHash === current)) await rm(configurationPath(context.target));
|
|
40
43
|
}
|
package/src/png.js
CHANGED
|
@@ -36,13 +36,10 @@ export function pngLength(bytes, offset = 0, expectedSize) {
|
|
|
36
36
|
throw new Error('Missing PNG end');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function
|
|
39
|
+
export function locateIcons(original, profile) {
|
|
40
40
|
if (sha256(original) !== profile.sha256) throw new Error('Unsupported executable hash; no files changed');
|
|
41
|
-
const patched = Buffer.from(original);
|
|
42
41
|
const slots = [];
|
|
43
42
|
for (const slot of profile.slots) {
|
|
44
|
-
const replacement = replacements.get(slot.size);
|
|
45
|
-
if (!replacement || replacement.length !== slot.length || sha256(replacement) !== slot.replacementSha256 || pngLength(replacement, 0, slot.size) !== slot.length) throw new Error('Replacement artwork failed validation');
|
|
46
43
|
const matches = [];
|
|
47
44
|
for (let offset = original.indexOf(signature); offset !== -1; offset = original.indexOf(signature, offset + 8)) {
|
|
48
45
|
if (sha256(original.subarray(offset, offset + slot.length)) === slot.sha256) {
|
|
@@ -53,8 +50,18 @@ export function patchImages(original, profile, replacements) {
|
|
|
53
50
|
if (matches.length !== 1) throw new Error(`Expected exactly one ${slot.size}px icon; found ${matches.length}`);
|
|
54
51
|
const offset = matches[0];
|
|
55
52
|
if (slots.some(other => offset < other.offset + other.length && other.offset < offset + slot.length)) throw new Error('Overlapping icon allocations');
|
|
56
|
-
replacement.copy(patched, offset);
|
|
57
53
|
slots.push({ offset, length: slot.length, size: slot.size });
|
|
58
54
|
}
|
|
55
|
+
return slots;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function patchImages(original, profile, replacements) {
|
|
59
|
+
const slots = locateIcons(original, profile);
|
|
60
|
+
const patched = Buffer.from(original);
|
|
61
|
+
for (const slot of profile.slots) {
|
|
62
|
+
const replacement = replacements.get(slot.size);
|
|
63
|
+
if (!replacement || replacement.length !== slot.length || sha256(replacement) !== slot.replacementSha256 || pngLength(replacement, 0, slot.size) !== slot.length) throw new Error('Replacement artwork failed validation');
|
|
64
|
+
replacement.copy(patched, slots.find(found => found.size === slot.size).offset);
|
|
65
|
+
}
|
|
59
66
|
return { patched, slots };
|
|
60
67
|
}
|
package/src/launch.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { readFile, mkdir, lstat, realpath, readdir, symlink, copyFile, chmod, mkdtemp, rename, rm } from 'node:fs/promises';
|
|
2
|
-
import { constants } from 'node:fs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
-
export function avdName(arguments_) {
|
|
8
|
-
const names = [];
|
|
9
|
-
for (let i = 0; i < arguments_.length; i++) {
|
|
10
|
-
if (arguments_[i] === '-avd' && arguments_[i + 1]) names.push(arguments_[++i]);
|
|
11
|
-
else if (arguments_[i].startsWith('@')) names.push(arguments_[i].slice(1));
|
|
12
|
-
}
|
|
13
|
-
if (new Set(names).size > 1) throw new Error('Conflicting AVD names');
|
|
14
|
-
const name = names[0];
|
|
15
|
-
if (name && (!/^[A-Za-z0-9_.-]{1,255}$/.test(name) || ['.', '..', 'qemu-system-aarch64'].includes(name.toLowerCase()))) throw new Error('Invalid or reserved AVD name');
|
|
16
|
-
return arguments_.includes('-no-window') ? undefined : name;
|
|
17
|
-
}
|
|
18
|
-
async function regularFile(path) {
|
|
19
|
-
const info = await lstat(path);
|
|
20
|
-
if (!info.isFile() || info.isSymbolicLink()) throw new Error(`Not a regular file: ${path}`);
|
|
21
|
-
return info;
|
|
22
|
-
}
|
|
23
|
-
export async function prepareLaunch(config, arguments_) {
|
|
24
|
-
if (config.schema !== 1 || await realpath(config.sdk) !== config.sdk || !config.directory.startsWith('/') ||
|
|
25
|
-
config.target !== join(config.sdk, 'emulator/qemu/darwin-aarch64/qemu-system-aarch64') ||
|
|
26
|
-
config.backend !== join(config.directory, 'backend') || config.script !== join(config.directory, 'launch.mjs')) throw new Error('Invalid naming configuration');
|
|
27
|
-
const revision = (await readFile(join(config.sdk, 'emulator/source.properties'), 'utf8')).match(/^Pkg\.Revision\s*=\s*(\S+)\s*$/m)?.[1];
|
|
28
|
-
if (revision !== config.revision) throw new Error('SDK version changed; restore or reapply emulator tweaks');
|
|
29
|
-
await regularFile(config.backend);
|
|
30
|
-
if (hash(await readFile(config.backend)) !== config.backendHash) throw new Error('Named emulator backend is corrupt');
|
|
31
|
-
const name = avdName(arguments_) ?? 'qemu-system-aarch64';
|
|
32
|
-
const launches = join(config.directory, 'launches');
|
|
33
|
-
await mkdir(launches, { recursive: true, mode: 0o700 });
|
|
34
|
-
const info = await lstat(launches);
|
|
35
|
-
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error('Invalid naming cache directory');
|
|
36
|
-
const destination = join(launches, hash(Buffer.from(name)));
|
|
37
|
-
const executable = join(destination, 'sdk/emulator/qemu/darwin-aarch64', name);
|
|
38
|
-
try {
|
|
39
|
-
await regularFile(executable);
|
|
40
|
-
if (hash(await readFile(executable)) !== config.backendHash) throw new Error('Cached named emulator is corrupt');
|
|
41
|
-
return executable;
|
|
42
|
-
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
43
|
-
const temporary = await mkdtemp(join(launches, '.prepare-'));
|
|
44
|
-
try {
|
|
45
|
-
async function clone(from, to, relative = '') {
|
|
46
|
-
await mkdir(to, { mode: 0o700 });
|
|
47
|
-
for (const entry of await readdir(from, { withFileTypes: true })) {
|
|
48
|
-
const key = relative ? `${relative}/${entry.name}` : entry.name;
|
|
49
|
-
const source = join(from, entry.name), output = join(to, entry.name);
|
|
50
|
-
if (['emulator', 'emulator/qemu', 'emulator/qemu/darwin-aarch64'].includes(key)) await clone(source, output, key);
|
|
51
|
-
else if (key !== 'emulator/qemu/darwin-aarch64/qemu-system-aarch64' && entry.name !== '.emulator-tweaks-launch.json' && entry.name !== '.emulator-icon-macos.lock') await symlink(source, output);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
await clone(config.sdk, join(temporary, 'sdk'));
|
|
55
|
-
const candidate = join(temporary, 'sdk/emulator/qemu/darwin-aarch64', name);
|
|
56
|
-
// Never overwrite a library or other SDK entry that happens to share the AVD name.
|
|
57
|
-
await copyFile(config.backend, candidate, constants.COPYFILE_EXCL);
|
|
58
|
-
await chmod(candidate, (await regularFile(config.backend)).mode & 0o777);
|
|
59
|
-
if (hash(await readFile(candidate)) !== config.backendHash) throw new Error('Named emulator copy changed');
|
|
60
|
-
try { await rename(temporary, destination); }
|
|
61
|
-
catch (error) { if (!['EEXIST', 'ENOTEMPTY'].includes(error.code)) throw error; }
|
|
62
|
-
await regularFile(executable);
|
|
63
|
-
if (hash(await readFile(executable)) !== config.backendHash) throw new Error('Concurrent named emulator cache is corrupt');
|
|
64
|
-
return executable;
|
|
65
|
-
} finally { await rm(temporary, { recursive: true, force: true }); }
|
|
66
|
-
}
|
|
67
|
-
if (process.argv[1] && await realpath(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
68
|
-
try {
|
|
69
|
-
const config = JSON.parse(await readFile(process.argv[2], 'utf8'));
|
|
70
|
-
console.log(await prepareLaunch(config, process.argv.slice(3)));
|
|
71
|
-
} catch (error) { console.error(`androperator-emulator-tweaks: ${error.message}`); process.exitCode = 1; }
|
|
72
|
-
}
|