@ejfkdev/pycdc 0.0.0-stage → 0.8.2-trust.1

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 CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @ejfkdev/pycdc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Prebuilt [pycdc](https://github.com/ejfkdev/pycdc) binaries. The postinstall script
4
+ downloads the matching release asset and verifies its SHA-256; tar.gz and zip
5
+ assets are unpacked locally. If install scripts are disabled, a launcher
6
+ fetches the binary on first use instead.
7
+
8
+ ```bash
9
+ npm install -g @ejfkdev/pycdc
10
+ pycdc --help
11
+ ```
12
+
13
+ Commands:
14
+ - `pycdc`
15
+ - `pycdas`
16
+
17
+ Supported platforms: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-arm64, win32-x64. Linux builds target glibc;
18
+ Alpine/musl users should install from source instead.
19
+
20
+ Each command accepts `<COMMAND>_BINARY_PATH` (for example
21
+ `PYCDC_BINARY_PATH`) to use a local
22
+ binary and skip the download.
package/bin/pycdas.js ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Generated by tool/sync.py. Keeps the npm shim portable while the real
5
+ // binary stays a native executable.
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+ const os = require("node:os");
9
+ const { spawn, spawnSync } = require("node:child_process");
10
+
11
+ const NAME = "pycdas";
12
+ const ENV_PREFIX = "PYCDAS";
13
+ const exe = process.platform === "win32" ? `${NAME}.exe` : NAME;
14
+ let bin = process.env[`${ENV_PREFIX}_BINARY_PATH`] || path.join(__dirname, exe);
15
+
16
+ if (!process.env[`${ENV_PREFIX}_BINARY_PATH`] && !fs.existsSync(bin)) {
17
+ console.error(`${NAME}: binary not installed; fetching it now...`);
18
+ const installer = spawnSync(
19
+ process.execPath,
20
+ [path.join(__dirname, "..", "install.js")],
21
+ { stdio: "inherit" }
22
+ );
23
+ if (installer.status !== 0 || !fs.existsSync(bin)) {
24
+ console.error(
25
+ `${NAME}: automatic install failed. Reinstall without --ignore-scripts, ` +
26
+ `or set ${ENV_PREFIX}_BINARY_PATH to a ${NAME} binary.`
27
+ );
28
+ process.exit(127);
29
+ }
30
+ }
31
+
32
+ if (!fs.existsSync(bin)) {
33
+ console.error(
34
+ `${NAME}: binary not found at ${bin}. ` +
35
+ `Check ${ENV_PREFIX}_BINARY_PATH or reinstall the package.`
36
+ );
37
+ process.exit(127);
38
+ }
39
+
40
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
41
+
42
+ child.on("error", (error) => {
43
+ console.error(`${NAME}: failed to start ${bin}: ${error.message}`);
44
+ process.exit(127);
45
+ });
46
+
47
+ child.on("exit", (code, signal) => {
48
+ if (signal) {
49
+ const number = os.constants.signals[signal] || 0;
50
+ process.exit(128 + number);
51
+ }
52
+ process.exit(code === null ? 1 : code);
53
+ });
package/bin/pycdc.js ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Generated by tool/sync.py. Keeps the npm shim portable while the real
5
+ // binary stays a native executable.
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+ const os = require("node:os");
9
+ const { spawn, spawnSync } = require("node:child_process");
10
+
11
+ const NAME = "pycdc";
12
+ const ENV_PREFIX = "PYCDC";
13
+ const exe = process.platform === "win32" ? `${NAME}.exe` : NAME;
14
+ let bin = process.env[`${ENV_PREFIX}_BINARY_PATH`] || path.join(__dirname, exe);
15
+
16
+ if (!process.env[`${ENV_PREFIX}_BINARY_PATH`] && !fs.existsSync(bin)) {
17
+ console.error(`${NAME}: binary not installed; fetching it now...`);
18
+ const installer = spawnSync(
19
+ process.execPath,
20
+ [path.join(__dirname, "..", "install.js")],
21
+ { stdio: "inherit" }
22
+ );
23
+ if (installer.status !== 0 || !fs.existsSync(bin)) {
24
+ console.error(
25
+ `${NAME}: automatic install failed. Reinstall without --ignore-scripts, ` +
26
+ `or set ${ENV_PREFIX}_BINARY_PATH to a ${NAME} binary.`
27
+ );
28
+ process.exit(127);
29
+ }
30
+ }
31
+
32
+ if (!fs.existsSync(bin)) {
33
+ console.error(
34
+ `${NAME}: binary not found at ${bin}. ` +
35
+ `Check ${ENV_PREFIX}_BINARY_PATH or reinstall the package.`
36
+ );
37
+ process.exit(127);
38
+ }
39
+
40
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
41
+
42
+ child.on("error", (error) => {
43
+ console.error(`${NAME}: failed to start ${bin}: ${error.message}`);
44
+ process.exit(127);
45
+ });
46
+
47
+ child.on("exit", (code, signal) => {
48
+ if (signal) {
49
+ const number = os.constants.signals[signal] || 0;
50
+ process.exit(128 + number);
51
+ }
52
+ process.exit(code === null ? 1 : code);
53
+ });
package/install.js ADDED
@@ -0,0 +1,340 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Generated by tool/sync.py. Downloads the matching GitHub release binary
5
+ // (raw or archived), verifies its SHA-256, and installs it next to this file.
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+ const https = require("node:https");
9
+ const zlib = require("node:zlib");
10
+ const crypto = require("node:crypto");
11
+ const { version } = require("./package.json");
12
+
13
+ const ASSETS = {
14
+ "darwin-arm64": {
15
+ bins: {
16
+ "pycdas": {
17
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-aarch64-macos",
18
+ sha256: "a7aeed99eb8cd298c1c5f9705b32824346ed06d25cee2b83ea8bd142c92b665c",
19
+ archive: "raw",
20
+ member: null,
21
+ env_prefix: "PYCDAS",
22
+ },
23
+ "pycdc": {
24
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-aarch64-macos",
25
+ sha256: "baba4cde955fc30c36e8275c2d091a2fe852e03440c8559399f57c16f7bacf1c",
26
+ archive: "raw",
27
+ member: null,
28
+ env_prefix: "PYCDC",
29
+ },
30
+ },
31
+ },
32
+ "darwin-x64": {
33
+ bins: {
34
+ "pycdas": {
35
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-x86_64-macos",
36
+ sha256: "81c24e01126361d647ba63cff1ab4b5dc5df78f9398772531250010b36f21410",
37
+ archive: "raw",
38
+ member: null,
39
+ env_prefix: "PYCDAS",
40
+ },
41
+ "pycdc": {
42
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-x86_64-macos",
43
+ sha256: "bc3c36ba6a9847595adca2ef43cd0616159a5aeae02afcdff0dc29f67b4d4d2f",
44
+ archive: "raw",
45
+ member: null,
46
+ env_prefix: "PYCDC",
47
+ },
48
+ },
49
+ },
50
+ "linux-arm64": {
51
+ bins: {
52
+ "pycdas": {
53
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-aarch64-linux",
54
+ sha256: "3d45013086cfc01fc75667177c9d5af733028015c80e9a2d8d06f077fc674940",
55
+ archive: "raw",
56
+ member: null,
57
+ env_prefix: "PYCDAS",
58
+ },
59
+ "pycdc": {
60
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-aarch64-linux",
61
+ sha256: "6d717ca386dfd03905c9d1adba2274672eed2a286c1345e19ad0f9fd9a4c5347",
62
+ archive: "raw",
63
+ member: null,
64
+ env_prefix: "PYCDC",
65
+ },
66
+ },
67
+ },
68
+ "linux-x64": {
69
+ bins: {
70
+ "pycdas": {
71
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-x86_64-linux",
72
+ sha256: "04ee19b0f4b19472509f2da2e03857b9c66a680f265974318aa2a6557318cadd",
73
+ archive: "raw",
74
+ member: null,
75
+ env_prefix: "PYCDAS",
76
+ },
77
+ "pycdc": {
78
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-x86_64-linux",
79
+ sha256: "d6ddaca319e78f74f196a9533e5144d48c4a7fe7723b895d4c4428febe2c9be8",
80
+ archive: "raw",
81
+ member: null,
82
+ env_prefix: "PYCDC",
83
+ },
84
+ },
85
+ },
86
+ "win32-arm64": {
87
+ bins: {
88
+ "pycdas": {
89
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-aarch64-windows.exe",
90
+ sha256: "0fe56f0df6fe9a6557bbd008d5f044a2aaf348b1486f155501a59344381d6c24",
91
+ archive: "raw",
92
+ member: null,
93
+ env_prefix: "PYCDAS",
94
+ },
95
+ "pycdc": {
96
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-aarch64-windows.exe",
97
+ sha256: "f16fdb7eba59ed0817d6b1935d66537a435bbe55a07c5aca9838dcd00f4eb924",
98
+ archive: "raw",
99
+ member: null,
100
+ env_prefix: "PYCDC",
101
+ },
102
+ },
103
+ },
104
+ "win32-x64": {
105
+ bins: {
106
+ "pycdas": {
107
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdas-x86_64-windows.exe",
108
+ sha256: "41eab99c458dd78b0e581fa197a6e39d699338acd3c11d10e0a08670bec923ba",
109
+ archive: "raw",
110
+ member: null,
111
+ env_prefix: "PYCDAS",
112
+ },
113
+ "pycdc": {
114
+ url: "https://github.com/ejfkdev/pycdc/releases/download/v0.8.2/pycdc-x86_64-windows.exe",
115
+ sha256: "75cd88161a00b9a46a9a06ac1f7c9965d90d2df1f0f28c7d084a67799501fbdc",
116
+ archive: "raw",
117
+ member: null,
118
+ env_prefix: "PYCDC",
119
+ },
120
+ },
121
+ },
122
+ };
123
+ const PROXY = process.env.EJFKDEV_DOWNLOAD_PROXY || "";
124
+
125
+ function requestUrl(url) {
126
+ if (!PROXY) return url;
127
+ return `${PROXY.replace(/\/+$/, "")}/${url}`;
128
+ }
129
+
130
+ function fail(message) {
131
+ console.error(`${message}`);
132
+ process.exit(1);
133
+ }
134
+
135
+ function isMusl() {
136
+ if (process.platform !== "linux") return false;
137
+ try {
138
+ return !process.report.getReport().header.glibcVersionRuntime;
139
+ } catch (_) {
140
+ return (
141
+ fs.existsSync("/lib/ld-musl-x86_64.so.1") ||
142
+ fs.existsSync("/lib/ld-musl-aarch64.so.1")
143
+ );
144
+ }
145
+ }
146
+
147
+ function download(url, dest, redirects) {
148
+ if (redirects === undefined) redirects = 0;
149
+ return new Promise((resolve, reject) => {
150
+ const request = https.get(
151
+ requestUrl(url),
152
+ {
153
+ headers: { "User-Agent": `ejfkdev-npm-installer/${version}` },
154
+ timeout: 120000,
155
+ },
156
+ (response) => {
157
+ const status = response.statusCode || 0;
158
+ if (status >= 300 && status < 400 && response.headers.location) {
159
+ response.resume();
160
+ if (redirects >= 10) {
161
+ reject(new Error(`too many redirects for ${url}`));
162
+ return;
163
+ }
164
+ const next = new URL(response.headers.location, url).toString();
165
+ download(next, dest, redirects + 1).then(resolve, reject);
166
+ return;
167
+ }
168
+ if (status !== 200) {
169
+ response.resume();
170
+ reject(new Error(`HTTP ${status} for ${url}`));
171
+ return;
172
+ }
173
+ const hash = crypto.createHash("sha256");
174
+ const out = fs.createWriteStream(dest, { mode: 0o755 });
175
+ response.on("data", (chunk) => hash.update(chunk));
176
+ response.on("error", reject);
177
+ out.on("error", reject);
178
+ out.on("finish", () => resolve(hash.digest("hex")));
179
+ response.pipe(out);
180
+ }
181
+ );
182
+ request.on("error", reject);
183
+ request.on("timeout", () => {
184
+ request.destroy(new Error(`download timed out for ${url}`));
185
+ });
186
+ });
187
+ }
188
+
189
+ async function downloadWithRetry(url, dest) {
190
+ let last;
191
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
192
+ try {
193
+ return await download(url, dest, 0);
194
+ } catch (error) {
195
+ last = error;
196
+ fs.rmSync(dest, { force: true });
197
+ if (attempt < 3) {
198
+ console.error(`download failed (${error.message}); retrying (${attempt}/3)...`);
199
+ await new Promise((resolve) => setTimeout(resolve, attempt * 2000));
200
+ }
201
+ }
202
+ }
203
+ throw last;
204
+ }
205
+
206
+ // Minimal tar.gz reader: enough for release archives with regular files.
207
+ function extractTarGz(buffer, member) {
208
+ const tar = zlib.gunzipSync(buffer);
209
+ let offset = 0;
210
+ while (offset + 512 <= tar.length) {
211
+ const header = tar.subarray(offset, offset + 512);
212
+ let empty = true;
213
+ for (const byte of header) {
214
+ if (byte !== 0) {
215
+ empty = false;
216
+ break;
217
+ }
218
+ }
219
+ if (empty) break;
220
+ let name = header.subarray(0, 100).toString("utf8").replace(/\0.*$/, "");
221
+ const prefix = header.subarray(345, 500).toString("utf8").replace(/\0.*$/, "");
222
+ if (prefix) name = `${prefix}/${name}`;
223
+ const sizeText = header.subarray(124, 136).toString("ascii").replace(/\0.*$/, "").trim();
224
+ const size = parseInt(sizeText, 8) || 0;
225
+ const type = String.fromCharCode(header[156] || 48);
226
+ if ((type === "0" || type === "\0" || type === "7") &&
227
+ path.posix.basename(name) === member) {
228
+ const start = offset + 512;
229
+ return tar.subarray(start, start + size);
230
+ }
231
+ offset += 512 + Math.ceil(size / 512) * 512;
232
+ }
233
+ throw new Error(`archive does not contain ${member}`);
234
+ }
235
+
236
+ // Minimal zip reader: central-directory walk, stored and deflated entries.
237
+ function extractZip(buffer, member) {
238
+ let eocd = -1;
239
+ const stop = Math.max(0, buffer.length - 65557);
240
+ for (let i = buffer.length - 22; i >= stop; i -= 1) {
241
+ if (buffer.readUInt32LE(i) === 0x06054b50) {
242
+ eocd = i;
243
+ break;
244
+ }
245
+ }
246
+ if (eocd < 0) throw new Error("not a zip archive (no end record)");
247
+ const count = buffer.readUInt16LE(eocd + 10);
248
+ let offset = buffer.readUInt32LE(eocd + 16);
249
+ for (let i = 0; i < count; i += 1) {
250
+ if (buffer.readUInt32LE(offset) !== 0x02014b50) {
251
+ throw new Error("corrupt zip central directory");
252
+ }
253
+ const method = buffer.readUInt16LE(offset + 10);
254
+ const compressedSize = buffer.readUInt32LE(offset + 20);
255
+ const nameLength = buffer.readUInt16LE(offset + 28);
256
+ const extraLength = buffer.readUInt16LE(offset + 30);
257
+ const commentLength = buffer.readUInt16LE(offset + 32);
258
+ const localOffset = buffer.readUInt32LE(offset + 42);
259
+ const name = buffer.subarray(offset + 46, offset + 46 + nameLength).toString("utf8");
260
+ if (path.posix.basename(name) === member) {
261
+ if (buffer.readUInt32LE(localOffset) !== 0x04034b50) {
262
+ throw new Error("corrupt zip local header");
263
+ }
264
+ const localNameLength = buffer.readUInt16LE(localOffset + 26);
265
+ const localExtraLength = buffer.readUInt16LE(localOffset + 28);
266
+ const start = localOffset + 30 + localNameLength + localExtraLength;
267
+ const data = buffer.subarray(start, start + compressedSize);
268
+ if (method === 0) return data;
269
+ if (method === 8) return zlib.inflateRawSync(data);
270
+ throw new Error(`unsupported zip compression method ${method}`);
271
+ }
272
+ offset += 46 + nameLength + extraLength + commentLength;
273
+ }
274
+ throw new Error(`archive does not contain ${member}`);
275
+ }
276
+
277
+ async function installBin(name, meta, binDir) {
278
+ const ext = process.platform === "win32" ? ".exe" : "";
279
+ const dest = path.join(binDir, `${name}${ext}`);
280
+ const tmp = path.join(binDir, `.${name}-download-${process.pid}`);
281
+ fs.mkdirSync(binDir, { recursive: true });
282
+
283
+ const local = process.env[`${meta.env_prefix}_BINARY_PATH`];
284
+ if (local) {
285
+ fs.copyFileSync(local, dest);
286
+ if (process.platform !== "win32") fs.chmodSync(dest, 0o755);
287
+ console.log(`${name}: installed from ${local}`);
288
+ return;
289
+ }
290
+
291
+ try {
292
+ const actual = await downloadWithRetry(meta.url, tmp);
293
+ if (actual !== meta.sha256) {
294
+ throw new Error(
295
+ `sha256 mismatch for ${meta.url}: expected ${meta.sha256}, got ${actual}`
296
+ );
297
+ }
298
+ if (meta.archive === "raw") {
299
+ fs.rmSync(dest, { force: true });
300
+ fs.renameSync(tmp, dest);
301
+ } else {
302
+ const buffer = fs.readFileSync(tmp);
303
+ const extracted =
304
+ meta.archive === "zip"
305
+ ? extractZip(buffer, meta.member)
306
+ : extractTarGz(buffer, meta.member);
307
+ fs.rmSync(dest, { force: true });
308
+ fs.writeFileSync(dest, extracted, { mode: 0o755 });
309
+ }
310
+ if (process.platform !== "win32") fs.chmodSync(dest, 0o755);
311
+ console.log(`${name} ${version} installed`);
312
+ } catch (error) {
313
+ fs.rmSync(tmp, { force: true });
314
+ fail(
315
+ `${name}: ${error.message}\n Download it manually from ${meta.url} and set ` +
316
+ `${meta.env_prefix}_BINARY_PATH.`
317
+ );
318
+ }
319
+ }
320
+
321
+ async function main() {
322
+ const key = `${process.platform}-${process.arch}`;
323
+ const entry = ASSETS[key];
324
+ if (!entry) {
325
+ fail(
326
+ `no prebuilt binary for ${key}; supported: ${Object.keys(ASSETS).join(", ")}.`
327
+ );
328
+ }
329
+ if (isMusl()) {
330
+ fail(
331
+ `this package ships glibc builds and Alpine/musl is not supported. ` +
332
+ `Install from source: https://github.com/ejfkdev/pycdc`
333
+ );
334
+ }
335
+ for (const [name, meta] of Object.entries(entry.bins)) {
336
+ await installBin(name, meta, path.join(__dirname, "bin"));
337
+ }
338
+ }
339
+
340
+ main().catch((error) => fail(error && error.stack ? error.stack : String(error)));
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@ejfkdev/pycdc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.8.2-trust.1",
4
+ "description": "Python bytecode decompiler and disassembler",
5
+ "license": "MIT",
6
+ "author": "ejfkdev",
7
+ "homepage": "https://github.com/ejfkdev/pycdc",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ejfkdev/release-automation.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ejfkdev/pycdc/issues"
14
+ },
15
+ "bin": {
16
+ "pycdc": "bin/pycdc.js",
17
+ "pycdas": "bin/pycdas.js"
18
+ },
19
+ "files": [
20
+ "bin/pycdc.js",
21
+ "bin/pycdas.js",
22
+ "install.js"
23
+ ],
24
+ "scripts": {
25
+ "postinstall": "node install.js"
26
+ },
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "os": [
31
+ "darwin",
32
+ "linux",
33
+ "win32"
34
+ ],
35
+ "cpu": [
36
+ "arm64",
37
+ "x64"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "keywords": [
43
+ "python",
44
+ "bytecode",
45
+ "decompiler",
46
+ "disassembler",
47
+ "reverse-engineering",
48
+ "cli"
49
+ ]
50
+ }