@tauri-cordis/manifest 0.1.0 → 0.2.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/package.json +1 -1
- package/src/executable.d.mts +5 -0
- package/src/executable.mjs +33 -0
- package/src/index.d.mts +1 -0
- package/src/index.mjs +1 -0
- package/src/package.d.mts +1 -1
- package/src/package.mjs +4 -17
- package/src/zip.d.mts +1 -1
- package/src/zip.mjs +2 -11
package/package.json
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type ExecutableKind = "PE" | "ELF" | "Mach-O" | "Java class" | "WebAssembly" | "Java archive";
|
|
2
|
+
|
|
3
|
+
export declare const EXECUTABLE_EXTENSIONS: readonly string[];
|
|
4
|
+
export declare function zipEntryNames(data: Uint8Array): string[];
|
|
5
|
+
export declare function executableKind(data: Uint8Array): ExecutableKind | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const EXECUTABLE_EXTENSIONS = [
|
|
2
|
+
".exe", ".dll", ".sys", ".scr", ".com", ".msi", ".so", ".dylib", ".bin",
|
|
3
|
+
".elf", ".app", ".appimage", ".deb", ".rpm", ".pkg", ".dmg", ".wasm", ".jar", ".class",
|
|
4
|
+
];
|
|
5
|
+
|
|
6
|
+
const MACHO = new Set([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xbebafeca, 0xcafebabf, 0xbfbafeca]);
|
|
7
|
+
const isJarEntry = (name) => name === "META-INF/MANIFEST.MF" || name.toLowerCase().endsWith(".class");
|
|
8
|
+
const toBuffer = (data) => (Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength));
|
|
9
|
+
|
|
10
|
+
export function zipEntryNames(data) {
|
|
11
|
+
const buf = toBuffer(data);
|
|
12
|
+
const names = new Set();
|
|
13
|
+
for (const [signature, nameAt, lengthAt] of [[Buffer.from([0x50, 0x4b, 0x03, 0x04]), 30, 26], [Buffer.from([0x50, 0x4b, 0x01, 0x02]), 46, 28]]) {
|
|
14
|
+
for (let at = buf.indexOf(signature); at >= 0 && at + nameAt <= buf.length; at = buf.indexOf(signature, at + 4)) {
|
|
15
|
+
const length = buf.readUInt16LE(at + lengthAt);
|
|
16
|
+
if (at + nameAt + length <= buf.length) names.add(buf.toString("utf8", at + nameAt, at + nameAt + length));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...names];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function executableKind(data) {
|
|
23
|
+
const buf = toBuffer(data);
|
|
24
|
+
if (buf.length >= 2 && buf[0] === 0x4d && buf[1] === 0x5a) return "PE";
|
|
25
|
+
if (buf.length < 4) return null;
|
|
26
|
+
const magic = buf.readUInt32BE(0);
|
|
27
|
+
if (magic === 0x7f454c46) return "ELF";
|
|
28
|
+
if (magic === 0xcafebabe) return buf.length >= 8 && buf.readUInt32BE(4) >= 45 ? "Java class" : "Mach-O";
|
|
29
|
+
if (MACHO.has(magic)) return "Mach-O";
|
|
30
|
+
if (magic === 0x0061736d) return "WebAssembly";
|
|
31
|
+
if (magic === 0x504b0304 && zipEntryNames(buf).some(isJarEntry)) return "Java archive";
|
|
32
|
+
return null;
|
|
33
|
+
}
|
package/src/index.d.mts
CHANGED
package/src/index.mjs
CHANGED
package/src/package.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginManifest } from "./manifest.mjs";
|
|
2
2
|
import type { PackageEntry } from "./zip.mjs";
|
|
3
3
|
|
|
4
|
+
export { EXECUTABLE_EXTENSIONS, executableKind, type ExecutableKind } from "./executable.mjs";
|
|
4
5
|
export { PackageError } from "./zip.mjs";
|
|
5
6
|
export type { PackageEntry } from "./zip.mjs";
|
|
6
7
|
|
|
@@ -46,7 +47,6 @@ export declare const BLOCKED_EXTENSIONS: readonly string[];
|
|
|
46
47
|
|
|
47
48
|
export declare function resolvePackageOptions(options?: PackageOptions): ResolvedPackageOptions;
|
|
48
49
|
export declare function checkPackagePath(path: unknown): { code: string; message: string } | null;
|
|
49
|
-
export declare function executableKind(data: Uint8Array): "PE" | "Mach-O" | "ELF" | "WebAssembly" | "Java class" | "Java archive" | null;
|
|
50
50
|
export declare function normalizeText(path: string, data: Uint8Array): Uint8Array;
|
|
51
51
|
export declare function sha256Hex(data: Uint8Array | string): string;
|
|
52
52
|
export declare function packageDigest(entries: readonly PackageEntry[], options?: PackageOptions): string;
|
package/src/package.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { EXECUTABLE_EXTENSIONS, executableKind } from "./executable.mjs";
|
|
4
5
|
import { isSafeRelativePath } from "./manifest.mjs";
|
|
5
|
-
import { PackageError, createZip, readZip
|
|
6
|
+
import { PackageError, createZip, readZip } from "./zip.mjs";
|
|
6
7
|
|
|
8
|
+
export { EXECUTABLE_EXTENSIONS, executableKind } from "./executable.mjs";
|
|
7
9
|
export { PackageError } from "./zip.mjs";
|
|
8
10
|
|
|
9
11
|
export const DEFAULT_NAMESPACE = "fuyu";
|
|
@@ -12,7 +14,7 @@ export const MAX_UNPACKED_BYTES = 100 * 1024 * 1024;
|
|
|
12
14
|
export const MAX_FILES = 5000;
|
|
13
15
|
export const MANIFEST_FILE = "package.json";
|
|
14
16
|
export const TEXT_EXTENSIONS = [".js", ".mjs", ".cjs", ".json", ".css", ".html", ".htm", ".md", ".txt", ".svg", ".map", ".yml", ".yaml", ".xml", ".csv"];
|
|
15
|
-
export const BLOCKED_EXTENSIONS = [".node",
|
|
17
|
+
export const BLOCKED_EXTENSIONS = [".node", ...EXECUTABLE_EXTENSIONS];
|
|
16
18
|
|
|
17
19
|
const extensionOf = (path) => {
|
|
18
20
|
const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
|
|
@@ -42,21 +44,6 @@ export function checkPackagePath(path) {
|
|
|
42
44
|
return null;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const MACHO = new Set([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xbebafeca, 0xcafebabf, 0xbfbafeca]);
|
|
46
|
-
const isJarEntry = (name) => name === "META-INF/MANIFEST.MF" || name.toLowerCase().endsWith(".class");
|
|
47
|
-
|
|
48
|
-
export function executableKind(data) {
|
|
49
|
-
if (data.length >= 2 && data[0] === 0x4d && data[1] === 0x5a) return "PE";
|
|
50
|
-
if (data.length < 4) return null;
|
|
51
|
-
const magic = data.readUInt32BE(0);
|
|
52
|
-
if (magic === 0x7f454c46) return "ELF";
|
|
53
|
-
if (magic === 0xcafebabe) return data.length >= 8 && data.readUInt32BE(4) >= 45 ? "Java class" : "Mach-O";
|
|
54
|
-
if (MACHO.has(magic)) return "Mach-O";
|
|
55
|
-
if (magic === 0x0061736d) return "WebAssembly";
|
|
56
|
-
if (magic === 0x504b0304 && zipEntryNames(data).some(isJarEntry)) return "Java archive";
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
47
|
const strictUtf8 = new TextDecoder("utf-8", { fatal: true });
|
|
61
48
|
|
|
62
49
|
export function normalizeText(path, data) {
|
package/src/zip.d.mts
CHANGED
|
@@ -11,4 +11,4 @@ export declare class PackageError extends Error {
|
|
|
11
11
|
|
|
12
12
|
export declare function createZip(entries: readonly PackageEntry[]): Uint8Array;
|
|
13
13
|
export declare function readZip(zip: Uint8Array, limits: { maxFiles: number; maxUnpackedBytes: number }): PackageEntry[];
|
|
14
|
-
export
|
|
14
|
+
export { zipEntryNames } from "./executable.mjs";
|
package/src/zip.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { crc32, deflateRawSync, inflateRawSync } from "node:zlib";
|
|
2
2
|
|
|
3
|
+
export { zipEntryNames } from "./executable.mjs";
|
|
4
|
+
|
|
3
5
|
const LOCAL = 0x04034b50;
|
|
4
6
|
const CENTRAL = 0x02014b50;
|
|
5
7
|
const END = 0x06054b50;
|
|
@@ -64,17 +66,6 @@ export function createZip(entries) {
|
|
|
64
66
|
return Buffer.concat([...locals, directory, end]);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export function zipEntryNames(data) {
|
|
68
|
-
const names = new Set();
|
|
69
|
-
for (const [signature, nameAt, lengthAt] of [[Buffer.from([0x50, 0x4b, 0x03, 0x04]), 30, 26], [Buffer.from([0x50, 0x4b, 0x01, 0x02]), 46, 28]]) {
|
|
70
|
-
for (let at = data.indexOf(signature); at >= 0 && at + nameAt <= data.length; at = data.indexOf(signature, at + 4)) {
|
|
71
|
-
const length = data.readUInt16LE(at + lengthAt);
|
|
72
|
-
if (at + nameAt + length <= data.length) names.add(data.toString("utf8", at + nameAt, at + nameAt + length));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return [...names];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
69
|
function findEnd(zip) {
|
|
79
70
|
const earliest = Math.max(0, zip.length - 22 - 0xffff);
|
|
80
71
|
for (let at = zip.length - 22; at >= earliest; at -= 1) {
|