@orkestrel/sea 0.0.2 → 0.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/dist/src/server/index.cjs +84 -63
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +34 -10
- package/dist/src/server/index.d.ts +34 -10
- package/dist/src/server/index.js +82 -64
- package/dist/src/server/index.js.map +1 -1
- package/package.json +20 -16
|
@@ -92,8 +92,6 @@ var PE_SCN_MEM_READ = 1073741824;
|
|
|
92
92
|
var SEA_PLATFORMS = Object.freeze({
|
|
93
93
|
win32: Object.freeze({
|
|
94
94
|
executable: "node.exe",
|
|
95
|
-
remove: void 0,
|
|
96
|
-
sign: void 0,
|
|
97
95
|
verify: Object.freeze([
|
|
98
96
|
"signtool",
|
|
99
97
|
"verify",
|
|
@@ -114,12 +112,7 @@ var SEA_PLATFORMS = Object.freeze({
|
|
|
114
112
|
"--strict"
|
|
115
113
|
])
|
|
116
114
|
}),
|
|
117
|
-
linux: Object.freeze({
|
|
118
|
-
executable: "node",
|
|
119
|
-
remove: void 0,
|
|
120
|
-
sign: void 0,
|
|
121
|
-
verify: void 0
|
|
122
|
-
})
|
|
115
|
+
linux: Object.freeze({ executable: "node" })
|
|
123
116
|
});
|
|
124
117
|
/** Maps a {@link SEACompressionMode} to its numeric Brotli mode value */
|
|
125
118
|
var SEA_COMPRESSION_MODE_VALUES = Object.freeze({
|
|
@@ -154,7 +147,7 @@ var SEAError = class extends Error {
|
|
|
154
147
|
super(message);
|
|
155
148
|
this.name = "SEAError";
|
|
156
149
|
this.code = code;
|
|
157
|
-
this.context = context;
|
|
150
|
+
if (context !== void 0) this.context = context;
|
|
158
151
|
}
|
|
159
152
|
};
|
|
160
153
|
/**
|
|
@@ -288,6 +281,24 @@ function walkDirectory(directory, base) {
|
|
|
288
281
|
return result;
|
|
289
282
|
}
|
|
290
283
|
/**
|
|
284
|
+
* Redact password arguments from a shell command.
|
|
285
|
+
*
|
|
286
|
+
* @param command - Command arguments to redact
|
|
287
|
+
* @returns A copy with values following password flags replaced by a marker
|
|
288
|
+
*/
|
|
289
|
+
function redactCommand(command) {
|
|
290
|
+
const secretFlags = /* @__PURE__ */ new Set([
|
|
291
|
+
"/p",
|
|
292
|
+
"-p",
|
|
293
|
+
"--password"
|
|
294
|
+
]);
|
|
295
|
+
return command.map((token, index) => {
|
|
296
|
+
const previous = command[index - 1];
|
|
297
|
+
if (previous !== void 0 && secretFlags.has(previous.toLowerCase())) return "***";
|
|
298
|
+
return token;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
291
302
|
* Run a command synchronously and return stdout.
|
|
292
303
|
*
|
|
293
304
|
* @param command - Command to execute (first element is the binary)
|
|
@@ -299,18 +310,6 @@ function walkDirectory(directory, base) {
|
|
|
299
310
|
* @throws ShellError when the command exits with non-zero status
|
|
300
311
|
*/
|
|
301
312
|
function runShell(command, options) {
|
|
302
|
-
function redactCommand(argv) {
|
|
303
|
-
const secretFlags = /* @__PURE__ */ new Set([
|
|
304
|
-
"/p",
|
|
305
|
-
"-p",
|
|
306
|
-
"--password"
|
|
307
|
-
]);
|
|
308
|
-
return argv.map((token, index) => {
|
|
309
|
-
const previous = argv[index - 1];
|
|
310
|
-
if (previous !== void 0 && secretFlags.has(previous.toLowerCase())) return "***";
|
|
311
|
-
return token;
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
313
|
const [cmd, ...args] = command;
|
|
315
314
|
if (cmd === void 0) throw new SEAError("STATE", "Command array must not be empty");
|
|
316
315
|
if (options?.signal?.aborted === true) throw new SEAError("ABORT", "Shell command aborted", { command: redactCommand(command) });
|
|
@@ -414,6 +413,15 @@ function compressDirectory(directory, options, progress) {
|
|
|
414
413
|
};
|
|
415
414
|
}
|
|
416
415
|
/**
|
|
416
|
+
* Check whether a number is a nonzero power of two.
|
|
417
|
+
*
|
|
418
|
+
* @param value - Number to check
|
|
419
|
+
* @returns True when the value is a positive power of two
|
|
420
|
+
*/
|
|
421
|
+
function isPowerOfTwo(value) {
|
|
422
|
+
return value > 0 && (value & value - 1) === 0;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
417
425
|
* Parse the PE header offset from a Windows executable.
|
|
418
426
|
*
|
|
419
427
|
* @param fd - Open file descriptor
|
|
@@ -808,6 +816,16 @@ function createBlobConfig(entry, blob, assets, options) {
|
|
|
808
816
|
};
|
|
809
817
|
}
|
|
810
818
|
/**
|
|
819
|
+
* Align an ELF note component size to its four-byte boundary.
|
|
820
|
+
*
|
|
821
|
+
* @param value - Component size to align
|
|
822
|
+
* @returns The value rounded up to the next multiple of four
|
|
823
|
+
*/
|
|
824
|
+
function alignELFNoteSize(value) {
|
|
825
|
+
const remainder = value % 4;
|
|
826
|
+
return remainder === 0 ? value : value + (4 - remainder);
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
811
829
|
* Build an ELF `PT_NOTE` entry's header bytes (namesz/descsz/type + padded
|
|
812
830
|
* name) for the SEA blob note, without the blob body itself.
|
|
813
831
|
*
|
|
@@ -831,18 +849,14 @@ function createBlobConfig(entry, blob, assets, options) {
|
|
|
831
849
|
* ```
|
|
832
850
|
*/
|
|
833
851
|
function buildELFNoteHeader(resource, blobSize) {
|
|
834
|
-
const alignTo4 = (value) => {
|
|
835
|
-
const remainder = value % 4;
|
|
836
|
-
return remainder === 0 ? value : value + (4 - remainder);
|
|
837
|
-
};
|
|
838
852
|
const nameBytes = Buffer.from(`${resource}\0`, "utf-8");
|
|
839
|
-
const alignedNameSize =
|
|
853
|
+
const alignedNameSize = alignELFNoteSize(nameBytes.length);
|
|
840
854
|
const header = Buffer.alloc(12 + alignedNameSize);
|
|
841
855
|
header.writeUInt32LE(nameBytes.length, 0);
|
|
842
856
|
header.writeUInt32LE(blobSize, 4);
|
|
843
857
|
header.writeUInt32LE(0, 8);
|
|
844
858
|
nameBytes.copy(header, 12);
|
|
845
|
-
const alignedDescSize =
|
|
859
|
+
const alignedDescSize = alignELFNoteSize(blobSize);
|
|
846
860
|
return {
|
|
847
861
|
header,
|
|
848
862
|
entryTotal: header.length + alignedDescSize
|
|
@@ -1840,32 +1854,30 @@ var Injector = class {
|
|
|
1840
1854
|
}
|
|
1841
1855
|
}
|
|
1842
1856
|
#shiftMachoLinkeditOffsets(buf, cmd, threshold, shift) {
|
|
1843
|
-
|
|
1844
|
-
if (fieldOffset + 4 > buf.length) return;
|
|
1845
|
-
const value = buf.readUInt32LE(fieldOffset);
|
|
1846
|
-
if (value >= threshold && value > 0) buf.writeUInt32LE(value + shift, fieldOffset);
|
|
1847
|
-
};
|
|
1848
|
-
const base = cmd.offset;
|
|
1857
|
+
let offsets;
|
|
1849
1858
|
switch (cmd.type) {
|
|
1850
1859
|
case 2:
|
|
1851
|
-
|
|
1852
|
-
bump(base + 16);
|
|
1860
|
+
offsets = [8, 16];
|
|
1853
1861
|
break;
|
|
1854
1862
|
case 11:
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1863
|
+
offsets = [
|
|
1864
|
+
32,
|
|
1865
|
+
40,
|
|
1866
|
+
48,
|
|
1867
|
+
56,
|
|
1868
|
+
64,
|
|
1869
|
+
72
|
|
1870
|
+
];
|
|
1861
1871
|
break;
|
|
1862
1872
|
case 34:
|
|
1863
1873
|
case 2147483682:
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1874
|
+
offsets = [
|
|
1875
|
+
8,
|
|
1876
|
+
16,
|
|
1877
|
+
24,
|
|
1878
|
+
32,
|
|
1879
|
+
40
|
|
1880
|
+
];
|
|
1869
1881
|
break;
|
|
1870
1882
|
case 29:
|
|
1871
1883
|
case 30:
|
|
@@ -1873,9 +1885,15 @@ var Injector = class {
|
|
|
1873
1885
|
case 41:
|
|
1874
1886
|
case 2147483699:
|
|
1875
1887
|
case 2147483700:
|
|
1876
|
-
|
|
1888
|
+
offsets = [8];
|
|
1877
1889
|
break;
|
|
1878
|
-
default:
|
|
1890
|
+
default: return;
|
|
1891
|
+
}
|
|
1892
|
+
for (const offset of offsets) {
|
|
1893
|
+
const fieldOffset = cmd.offset + offset;
|
|
1894
|
+
if (fieldOffset + 4 > buf.length) continue;
|
|
1895
|
+
const value = buf.readUInt32LE(fieldOffset);
|
|
1896
|
+
if (value >= threshold && value > 0) buf.writeUInt32LE(value + shift, fieldOffset);
|
|
1879
1897
|
}
|
|
1880
1898
|
}
|
|
1881
1899
|
#verifyMachoSection(exePath, segmentName, sectionName, expectedOffset, expectedSize) {
|
|
@@ -1950,7 +1968,6 @@ var Injector = class {
|
|
|
1950
1968
|
return remainder === 0 ? value : value + (alignment - remainder);
|
|
1951
1969
|
}
|
|
1952
1970
|
#ensureValidPEAlignment(sectionAlignment, fileAlignment) {
|
|
1953
|
-
const isPowerOfTwo = (n) => n > 0 && (n & n - 1) === 0;
|
|
1954
1971
|
if (!isPowerOfTwo(sectionAlignment) || !isPowerOfTwo(fileAlignment)) throw new SEAError("FORMAT", "PE section/file alignment must be a nonzero power of two", {
|
|
1955
1972
|
executable: this.#options.executable,
|
|
1956
1973
|
sectionAlignment,
|
|
@@ -1995,8 +2012,8 @@ var SEA = class {
|
|
|
1995
2012
|
constructor(options) {
|
|
1996
2013
|
this.#options = options;
|
|
1997
2014
|
this.#emitter = new _orkestrel_emitter.Emitter({
|
|
1998
|
-
on: options.on,
|
|
1999
|
-
error: options.error
|
|
2015
|
+
...options.on === void 0 ? {} : { on: options.on },
|
|
2016
|
+
...options.error === void 0 ? {} : { error: options.error }
|
|
2000
2017
|
});
|
|
2001
2018
|
}
|
|
2002
2019
|
get emitter() {
|
|
@@ -2033,10 +2050,10 @@ var SEA = class {
|
|
|
2033
2050
|
platform: process.platform,
|
|
2034
2051
|
size,
|
|
2035
2052
|
duration,
|
|
2036
|
-
compression,
|
|
2037
2053
|
signed: assembled.signed,
|
|
2038
2054
|
stripped: assembled.stripped,
|
|
2039
|
-
|
|
2055
|
+
...compression === void 0 ? {} : { compression },
|
|
2056
|
+
...assembled.terminal === void 0 ? {} : { terminal: assembled.terminal }
|
|
2040
2057
|
};
|
|
2041
2058
|
this.#status = "done";
|
|
2042
2059
|
this.#emitter.emit("complete", result);
|
|
@@ -2126,7 +2143,7 @@ var SEA = class {
|
|
|
2126
2143
|
const blob = (0, node_path.join)(output, "sea-prep.blob");
|
|
2127
2144
|
const config = createBlobConfig({
|
|
2128
2145
|
path: entry,
|
|
2129
|
-
format: this.#options.entry.format
|
|
2146
|
+
...this.#options.entry.format === void 0 ? {} : { format: this.#options.entry.format }
|
|
2130
2147
|
}, blob, this.#assets(root), this.#options.blob);
|
|
2131
2148
|
(0, node_fs.writeFileSync)(configPath, JSON.stringify(config, null, 2));
|
|
2132
2149
|
runShell([
|
|
@@ -2135,7 +2152,7 @@ var SEA = class {
|
|
|
2135
2152
|
configPath
|
|
2136
2153
|
], {
|
|
2137
2154
|
cwd: output,
|
|
2138
|
-
signal: this.#options.signal
|
|
2155
|
+
...this.#options.signal === void 0 ? {} : { signal: this.#options.signal }
|
|
2139
2156
|
});
|
|
2140
2157
|
if (!(0, node_fs.existsSync)(blob)) throw new SEAError("BLOB", "SEA blob generation failed — blob not found", { blob });
|
|
2141
2158
|
this.#emitter.emit("blob", blob);
|
|
@@ -2148,6 +2165,7 @@ var SEA = class {
|
|
|
2148
2165
|
const ext = process.platform === "win32" ? ".exe" : "";
|
|
2149
2166
|
const finalOutput = (0, node_path.join)(output, process.platform === "win32" ? `${this.#options.name}.exe` : this.#options.name);
|
|
2150
2167
|
const temp = (0, node_path.join)(output, `.${this.#options.name}-${(0, node_crypto.randomUUID)()}.tmp${ext}`);
|
|
2168
|
+
const shell = this.#options.signal === void 0 ? {} : { signal: this.#options.signal };
|
|
2151
2169
|
let signed = false;
|
|
2152
2170
|
let stripped = false;
|
|
2153
2171
|
let terminal;
|
|
@@ -2159,7 +2177,7 @@ var SEA = class {
|
|
|
2159
2177
|
if (platform.remove !== void 0) {
|
|
2160
2178
|
this.#check();
|
|
2161
2179
|
try {
|
|
2162
|
-
runShell([...platform.remove, temp],
|
|
2180
|
+
runShell([...platform.remove, temp], shell);
|
|
2163
2181
|
} catch (thrown) {
|
|
2164
2182
|
throw new SEAError("SIGN", "Failed to strip existing signature", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
|
|
2165
2183
|
}
|
|
@@ -2176,14 +2194,14 @@ var SEA = class {
|
|
|
2176
2194
|
if (platform.sign !== void 0) {
|
|
2177
2195
|
this.#check();
|
|
2178
2196
|
try {
|
|
2179
|
-
runShell([...platform.sign, temp],
|
|
2197
|
+
runShell([...platform.sign, temp], shell);
|
|
2180
2198
|
} catch (thrown) {
|
|
2181
2199
|
throw new SEAError("SIGN", "Failed to sign executable", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
|
|
2182
2200
|
}
|
|
2183
2201
|
if (platform.verify !== void 0) {
|
|
2184
2202
|
this.#check();
|
|
2185
2203
|
try {
|
|
2186
|
-
runShell([...platform.verify, temp],
|
|
2204
|
+
runShell([...platform.verify, temp], shell);
|
|
2187
2205
|
} catch (thrown) {
|
|
2188
2206
|
throw new SEAError("SIGN", "Signature verification failed", { cause: thrown instanceof Error ? thrown.message : String(thrown) });
|
|
2189
2207
|
}
|
|
@@ -2214,7 +2232,7 @@ var SEA = class {
|
|
|
2214
2232
|
file: (0, node_path.resolve)(root, sign.file)
|
|
2215
2233
|
} : sign, temp);
|
|
2216
2234
|
try {
|
|
2217
|
-
runShell(signArgs,
|
|
2235
|
+
runShell(signArgs, shell);
|
|
2218
2236
|
} catch {
|
|
2219
2237
|
throw new SEAError("SIGN", "Windows signing failed", { executable: temp });
|
|
2220
2238
|
}
|
|
@@ -2222,7 +2240,7 @@ var SEA = class {
|
|
|
2222
2240
|
if (platform.verify !== void 0) {
|
|
2223
2241
|
this.#check();
|
|
2224
2242
|
try {
|
|
2225
|
-
runShell([...platform.verify, temp],
|
|
2243
|
+
runShell([...platform.verify, temp], shell);
|
|
2226
2244
|
} catch {
|
|
2227
2245
|
throw new SEAError("SIGN", "Signature verification failed", { executable: temp });
|
|
2228
2246
|
}
|
|
@@ -2250,7 +2268,7 @@ var SEA = class {
|
|
|
2250
2268
|
executable: finalOutput,
|
|
2251
2269
|
signed,
|
|
2252
2270
|
stripped,
|
|
2253
|
-
terminal
|
|
2271
|
+
...terminal === void 0 ? {} : { terminal }
|
|
2254
2272
|
};
|
|
2255
2273
|
}
|
|
2256
2274
|
#assets(root) {
|
|
@@ -2288,8 +2306,8 @@ var AssetManager = class {
|
|
|
2288
2306
|
constructor(options) {
|
|
2289
2307
|
this.#root = options?.root ?? process.cwd();
|
|
2290
2308
|
this.#emitter = new _orkestrel_emitter.Emitter({
|
|
2291
|
-
on: options
|
|
2292
|
-
error: options
|
|
2309
|
+
...options?.on === void 0 ? {} : { on: options.on },
|
|
2310
|
+
...options?.error === void 0 ? {} : { error: options.error }
|
|
2293
2311
|
});
|
|
2294
2312
|
this.#loadSea();
|
|
2295
2313
|
}
|
|
@@ -2498,6 +2516,7 @@ exports.SKIP_EXTENSIONS = SKIP_EXTENSIONS;
|
|
|
2498
2516
|
exports.ShellError = ShellError;
|
|
2499
2517
|
exports.WINDOWS_SUBSYSTEM_CONSOLE = WINDOWS_SUBSYSTEM_CONSOLE;
|
|
2500
2518
|
exports.WINDOWS_SUBSYSTEM_GUI = WINDOWS_SUBSYSTEM_GUI;
|
|
2519
|
+
exports.alignELFNoteSize = alignELFNoteSize;
|
|
2501
2520
|
exports.buildELFNoteHeader = buildELFNoteHeader;
|
|
2502
2521
|
exports.compressDirectory = compressDirectory;
|
|
2503
2522
|
exports.compressFile = compressFile;
|
|
@@ -2519,6 +2538,7 @@ exports.isCompressible = isCompressible;
|
|
|
2519
2538
|
exports.isExecutableFormat = isExecutableFormat;
|
|
2520
2539
|
exports.isPEExecutable = isPEExecutable;
|
|
2521
2540
|
exports.isPlatformSupported = isPlatformSupported;
|
|
2541
|
+
exports.isPowerOfTwo = isPowerOfTwo;
|
|
2522
2542
|
exports.isSEAError = isSEAError;
|
|
2523
2543
|
exports.isShellError = isShellError;
|
|
2524
2544
|
exports.openBrowser = openBrowser;
|
|
@@ -2527,6 +2547,7 @@ exports.patchPESubsystem = patchPESubsystem;
|
|
|
2527
2547
|
exports.patchSentinelFuse = patchSentinelFuse;
|
|
2528
2548
|
exports.platformConfig = platformConfig;
|
|
2529
2549
|
exports.readU16 = readU16;
|
|
2550
|
+
exports.redactCommand = redactCommand;
|
|
2530
2551
|
exports.runShell = runShell;
|
|
2531
2552
|
exports.stripPESignature = stripPESignature;
|
|
2532
2553
|
exports.syncDirectory = syncDirectory;
|