preprocess-wasm-bytes 0.1.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/README.md ADDED
@@ -0,0 +1,83 @@
1
+ License: UNLICENSED — Not licensed for use; all rights reserved.
2
+
3
+ # preprocess-wasm-bytes
4
+
5
+ Exports a single function: `preprocess_wasm_bytes(bytes: Uint8Array): Promise<Uint8Array>`
6
+
7
+ It scans the WASM binary (imports/exports/globals/memories/tables/element segments) and produces a new WASM binary with additional exports added for:
8
+
9
+ - functions referenced by element segments / `ref.func` in const-exprs
10
+ - mutable globals
11
+ - all memories
12
+ - all tables
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm i preprocess-wasm-bytes
18
+ ```
19
+
20
+ ## Usage (Node / ESM)
21
+ ```js
22
+ import fs from "node:fs";
23
+ import { preprocess_wasm_bytes } from "preprocess-wasm-bytes";
24
+
25
+ const bytes = new Uint8Array(fs.readFileSync("input.wasm"));
26
+ const out = await preprocess_wasm_bytes(bytes);
27
+
28
+ fs.writeFileSync("output.wasm", out);
29
+ ```
30
+
31
+ ## Usage (Browser bundlers)
32
+ ```js
33
+ import { preprocess_wasm_bytes } from "preprocess-wasm-bytes";
34
+
35
+ const res = await fetch("/module.wasm");
36
+ const bytes = new Uint8Array(await res.arrayBuffer());
37
+ const out = await preprocess_wasm_bytes(bytes);
38
+ ```
39
+
40
+ ## Debug logging
41
+ ```js
42
+ globalThis.__WASM_PREPROCESS_DEBUG__ = true;
43
+ ```
44
+ Set that before calling preprocess_wasm_bytes(...).
45
+
46
+ ## Build and publish
47
+ Verify the build output exists (your `npm run build:lib` showing no output is normal when there are no errors):
48
+
49
+ ```bash
50
+ ls -la dist
51
+ ```
52
+
53
+ You should see at least: index.js, index.d.ts, and their sourcemaps, plus preprocess_wasm_bytes.js and preprocess_wasm_bytes.d.ts.
54
+
55
+ Run the smoke test against dist/:
56
+
57
+ ```bash
58
+ npm run gen:sample-wasm
59
+ npm run build:lib
60
+ node --input-type=module -e "import fs from 'node:fs'; import { preprocess_wasm_bytes } from './dist/index.js'; const b=new Uint8Array(fs.readFileSync('public/sample.wasm')); const out=await preprocess_wasm_bytes(b); console.log('ok', {inBytes:b.length, outBytes:out.length});"
61
+ ```
62
+
63
+ Confirm what npm will publish:
64
+
65
+ ```bash
66
+ npm pack --dry-run
67
+ ```
68
+
69
+ This should include only dist/ and README.md (per the files field).
70
+
71
+ Fix npm auth and publish (publish failed due to token/auth; you must re-auth on your machine):
72
+
73
+ ```bash
74
+ npm whoami
75
+ # if not logged in:
76
+ npm login
77
+ # optionally confirm registry:
78
+ npm config get registry
79
+ # then:
80
+ npm publish
81
+ ```
82
+
83
+ If npm publish ever reports “You cannot publish over the previously published versions”, bump version and re-run npm publish (but your attempt failed due to auth, so 0.1.0 should still be fine).
@@ -0,0 +1,2 @@
1
+ export { preprocess_wasm_bytes } from "./preprocess_wasm_bytes.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // Copyright (c) 2025 justing2k5. All rights reserved.
2
+ export { preprocess_wasm_bytes } from "./preprocess_wasm_bytes.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function preprocess_wasm_bytes(wasmBytes: Uint8Array): Promise<Uint8Array>;
2
+ //# sourceMappingURL=preprocess_wasm_bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preprocess_wasm_bytes.d.ts","sourceRoot":"","sources":["../src/preprocess_wasm_bytes.ts"],"names":[],"mappings":"AAonBA,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAmEtF"}
@@ -0,0 +1,596 @@
1
+ // Copyright (c) 2025 justing2k5. All rights reserved.
2
+ // src/preprocess_wasm_bytes.ts
3
+ //
4
+ // What changed vs your last version:
5
+ // - We now *directly parse the WASM binary* to find all function indices referenced by the **element section**
6
+ // (covers active/passive/declarative + elem expressions). This avoids any @webassemblyjs AST-shape quirks.
7
+ // - We also parse the binary export section to learn existing export names/indices (so we never collide).
8
+ // - We export **all tables** (0..totalTables-1) unconditionally.
9
+ // - Debug logging is OFF by default. Toggle it via:
10
+ // globalThis.__WASM_PREPROCESS_DEBUG__ = true/false
11
+ const DEFAULT_DEBUG = false;
12
+ function debugEnabled() {
13
+ const v = globalThis.__WASM_PREPROCESS_DEBUG__;
14
+ return typeof v === "boolean" ? v : DEFAULT_DEBUG;
15
+ }
16
+ function dbg(...args) {
17
+ if (debugEnabled())
18
+ console.log("[wasm-preprocess]", ...args);
19
+ }
20
+ /**
21
+ * Some dependencies (notably @webassemblyjs/* and their transitive deps) expect
22
+ * node-ish globals in browser bundles. We only install minimal shims if missing.
23
+ * This runs BEFORE loading @webassemblyjs/*.
24
+ */
25
+ let _didEnsureNodeLikeGlobals = false;
26
+ async function ensureNodeLikeGlobals() {
27
+ if (_didEnsureNodeLikeGlobals)
28
+ return;
29
+ _didEnsureNodeLikeGlobals = true;
30
+ const g = globalThis;
31
+ g.global ??= g;
32
+ g.process ??= { env: {} };
33
+ if (!g.Buffer) {
34
+ const mod = await import("buffer");
35
+ g.Buffer = mod.Buffer;
36
+ }
37
+ }
38
+ function toExactArrayBuffer(bytes) {
39
+ const { buffer, byteOffset, byteLength } = bytes;
40
+ if (buffer instanceof ArrayBuffer) {
41
+ if (byteOffset === 0 && byteLength === buffer.byteLength)
42
+ return buffer;
43
+ return buffer.slice(byteOffset, byteOffset + byteLength);
44
+ }
45
+ // SharedArrayBuffer case: copy into a new ArrayBuffer
46
+ const out = new ArrayBuffer(byteLength);
47
+ new Uint8Array(out).set(bytes);
48
+ return out;
49
+ }
50
+ function uniqueName(base, used, fallback) {
51
+ const cleanBase = base && typeof base === "string" ? base : fallback;
52
+ if (!used.has(cleanBase)) {
53
+ used.add(cleanBase);
54
+ return cleanBase;
55
+ }
56
+ let i = 1;
57
+ while (used.has(`${cleanBase}__${i}`))
58
+ i++;
59
+ const out = `${cleanBase}__${i}`;
60
+ used.add(out);
61
+ return out;
62
+ }
63
+ /* =======================================================================================
64
+ * Minimal WASM binary reader (just enough for exports/imports/tables/mems/globals/elems)
65
+ * ======================================================================================= */
66
+ const utf8 = new TextDecoder("utf-8");
67
+ function fail(msg) {
68
+ throw new Error(`[wasm-preprocess] ${msg}`);
69
+ }
70
+ function readU32Leb(bytes, pos, end) {
71
+ let result = 0;
72
+ let shift = 0;
73
+ for (let i = 0; i < 5; i++) {
74
+ if (pos >= end)
75
+ fail("unexpected EOF while reading u32 leb");
76
+ const b = bytes[pos++];
77
+ result |= (b & 0x7f) << shift;
78
+ if ((b & 0x80) === 0)
79
+ return { value: result >>> 0, pos };
80
+ shift += 7;
81
+ }
82
+ fail("u32 leb too long");
83
+ }
84
+ function skipLeb(bytes, pos, end, maxBytes) {
85
+ for (let i = 0; i < maxBytes; i++) {
86
+ if (pos >= end)
87
+ fail("unexpected EOF while skipping leb");
88
+ const b = bytes[pos++];
89
+ if ((b & 0x80) === 0)
90
+ return pos;
91
+ }
92
+ fail("leb too long");
93
+ }
94
+ function readName(bytes, pos, end) {
95
+ const r = readU32Leb(bytes, pos, end);
96
+ const len = r.value;
97
+ pos = r.pos;
98
+ const next = pos + len;
99
+ if (next > end)
100
+ fail("unexpected EOF while reading name");
101
+ const s = utf8.decode(bytes.subarray(pos, next));
102
+ return { value: s, pos: next };
103
+ }
104
+ /**
105
+ * Parse a const expr and collect any ref.func immediates.
106
+ * NOTE: For our purposes we only fully support the common const-expr opcodes.
107
+ * For unknown opcodes we fail fast (with a useful error).
108
+ */
109
+ function parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, ctx) {
110
+ while (true) {
111
+ if (pos >= end)
112
+ fail(`unexpected EOF in const expr (${ctx})`);
113
+ const op = bytes[pos++];
114
+ switch (op) {
115
+ case 0x0b: // end
116
+ return pos;
117
+ case 0xd2: {
118
+ // ref.func <funcidx:u32>
119
+ const r = readU32Leb(bytes, pos, end);
120
+ outFuncs.add(r.value);
121
+ pos = r.pos;
122
+ break;
123
+ }
124
+ case 0xd0:
125
+ // ref.null <reftype>
126
+ if (pos >= end)
127
+ fail(`unexpected EOF after ref.null (${ctx})`);
128
+ pos += 1;
129
+ break;
130
+ case 0x23:
131
+ // global.get <globalidx:u32>
132
+ pos = skipLeb(bytes, pos, end, 5);
133
+ break;
134
+ case 0x41:
135
+ // i32.const <varint32>
136
+ pos = skipLeb(bytes, pos, end, 5);
137
+ break;
138
+ case 0x42:
139
+ // i64.const <varint64>
140
+ pos = skipLeb(bytes, pos, end, 10);
141
+ break;
142
+ case 0x43:
143
+ // f32.const <4 bytes>
144
+ if (pos + 4 > end)
145
+ fail(`unexpected EOF after f32.const (${ctx})`);
146
+ pos += 4;
147
+ break;
148
+ case 0x44:
149
+ // f64.const <8 bytes>
150
+ if (pos + 8 > end)
151
+ fail(`unexpected EOF after f64.const (${ctx})`);
152
+ pos += 8;
153
+ break;
154
+ // Accept a few ref ops that have no immediates (rare in const exprs, but safe to skip)
155
+ case 0xd1: // ref.is_null
156
+ case 0xd3: // ref.eq
157
+ case 0xd4: // ref.as_non_null
158
+ break;
159
+ default:
160
+ fail(`unsupported opcode 0x${op.toString(16)} in const expr (${ctx}). ` +
161
+ `If your modules use extended-const-exprs, we can add more opcode support.`);
162
+ }
163
+ }
164
+ }
165
+ function parseLimitsU32(bytes, pos, end, ctx) {
166
+ if (pos >= end)
167
+ fail(`unexpected EOF in limits (${ctx})`);
168
+ const flags = bytes[pos++];
169
+ // Core variants:
170
+ // 0x00: min
171
+ // 0x01: min, max
172
+ // Additional variants exist in newer proposals (shared/memory64), but we just skip in a tolerant way.
173
+ if (flags === 0x00) {
174
+ pos = skipLeb(bytes, pos, end, 5);
175
+ return pos;
176
+ }
177
+ if (flags === 0x01 || flags === 0x03) {
178
+ // treat 0x03 (shared) same shape for skipping: min + max
179
+ pos = skipLeb(bytes, pos, end, 5);
180
+ pos = skipLeb(bytes, pos, end, 5);
181
+ return pos;
182
+ }
183
+ // Some proposals introduce more flags; best-effort: read min + max.
184
+ dbg(`limits(${ctx}) uses uncommon flags 0x${flags.toString(16)}; best-effort skipping min+max`);
185
+ pos = skipLeb(bytes, pos, end, 5);
186
+ pos = skipLeb(bytes, pos, end, 5);
187
+ return pos;
188
+ }
189
+ function parseTableType(bytes, pos, end) {
190
+ if (pos >= end)
191
+ fail("unexpected EOF in tabletype");
192
+ // reftype byte
193
+ pos += 1;
194
+ pos = parseLimitsU32(bytes, pos, end, "tabletype.limits");
195
+ return pos;
196
+ }
197
+ function parseMemType(bytes, pos, end) {
198
+ // memtype is limits
199
+ pos = parseLimitsU32(bytes, pos, end, "memtype.limits");
200
+ return pos;
201
+ }
202
+ function parseGlobalType(bytes, pos, end) {
203
+ if (pos + 2 > end)
204
+ fail("unexpected EOF in globaltype");
205
+ // valtype byte
206
+ pos += 1;
207
+ // mutability byte: 0 const, 1 var
208
+ const mut = bytes[pos++];
209
+ return { pos, mutable: mut === 1 };
210
+ }
211
+ /**
212
+ * Element section parsing based on the spec forms 0..7:
213
+ * https://webassembly.github.io/spec/core/binary/modules.html#element-section
214
+ */
215
+ function parseElementSectionCollectFuncIdxs(bytes, start, end, outFuncs) {
216
+ let pos = start;
217
+ const rCount = readU32Leb(bytes, pos, end);
218
+ const count = rCount.value;
219
+ pos = rCount.pos;
220
+ dbg(`element section: ${count} segment(s)`);
221
+ for (let i = 0; i < count; i++) {
222
+ const rForm = readU32Leb(bytes, pos, end);
223
+ const form = rForm.value;
224
+ pos = rForm.pos;
225
+ const segCollected = [];
226
+ const addFunc = (idx) => {
227
+ outFuncs.add(idx);
228
+ segCollected.push(idx);
229
+ };
230
+ const readFuncIdxVec = () => {
231
+ const rN = readU32Leb(bytes, pos, end);
232
+ const n = rN.value;
233
+ pos = rN.pos;
234
+ for (let k = 0; k < n; k++) {
235
+ const rF = readU32Leb(bytes, pos, end);
236
+ pos = rF.pos;
237
+ addFunc(rF.value);
238
+ }
239
+ };
240
+ const readExprVec = (ctx) => {
241
+ const rN = readU32Leb(bytes, pos, end);
242
+ const n = rN.value;
243
+ pos = rN.pos;
244
+ for (let k = 0; k < n; k++) {
245
+ pos = parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, ctx);
246
+ }
247
+ };
248
+ switch (form) {
249
+ case 0: {
250
+ // 0: u32, offset expr, vec(funcidx) (active, table 0, funcref implicit)
251
+ pos = parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, `elem[${i}].offset(form0)`);
252
+ readFuncIdxVec();
253
+ break;
254
+ }
255
+ case 1: {
256
+ // 1: u32, elemkind, vec(funcidx) (passive)
257
+ if (pos >= end)
258
+ fail("unexpected EOF reading elemkind (form1)");
259
+ pos += 1; // elemkind
260
+ readFuncIdxVec();
261
+ break;
262
+ }
263
+ case 2: {
264
+ // 2: u32, tableidx, offset expr, elemkind, vec(funcidx) (active, explicit table)
265
+ pos = readU32Leb(bytes, pos, end).pos; // tableidx
266
+ pos = parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, `elem[${i}].offset(form2)`);
267
+ if (pos >= end)
268
+ fail("unexpected EOF reading elemkind (form2)");
269
+ pos += 1; // elemkind
270
+ readFuncIdxVec();
271
+ break;
272
+ }
273
+ case 3: {
274
+ // 3: u32, elemkind, vec(funcidx) (declarative)
275
+ if (pos >= end)
276
+ fail("unexpected EOF reading elemkind (form3)");
277
+ pos += 1; // elemkind
278
+ readFuncIdxVec();
279
+ break;
280
+ }
281
+ case 4: {
282
+ // 4: u32, offset expr, vec(expr) (active, table 0, funcref implicit)
283
+ pos = parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, `elem[${i}].offset(form4)`);
284
+ readExprVec(`elem[${i}].init(form4)`);
285
+ break;
286
+ }
287
+ case 5: {
288
+ // 5: u32, reftype, vec(expr) (passive)
289
+ if (pos >= end)
290
+ fail("unexpected EOF reading reftype (form5)");
291
+ pos += 1; // reftype
292
+ readExprVec(`elem[${i}].init(form5)`);
293
+ break;
294
+ }
295
+ case 6: {
296
+ // 6: u32, tableidx, offset expr, vec(expr) (active, funcref implicit)
297
+ pos = readU32Leb(bytes, pos, end).pos; // tableidx
298
+ pos = parseConstExprCollectRefFuncs(bytes, pos, end, outFuncs, `elem[${i}].offset(form6)`);
299
+ readExprVec(`elem[${i}].init(form6)`);
300
+ break;
301
+ }
302
+ case 7: {
303
+ // 7: u32, reftype, vec(expr) (declarative)
304
+ if (pos >= end)
305
+ fail("unexpected EOF reading reftype (form7)");
306
+ pos += 1; // reftype
307
+ readExprVec(`elem[${i}].init(form7)`);
308
+ break;
309
+ }
310
+ default:
311
+ fail(`unknown element segment form ${form} (expected 0..7)`);
312
+ }
313
+ if (debugEnabled()) {
314
+ const uniq = Array.from(new Set(segCollected)).sort((a, b) => a - b);
315
+ dbg(` elem[${i}] form=${form} collected funcidx:`, uniq);
316
+ }
317
+ }
318
+ if (pos !== end) {
319
+ // Not necessarily fatal, but useful signal.
320
+ dbg(`element section: parsed ${pos - start} bytes, expected ${end - start} bytes (diff=${end - pos})`);
321
+ }
322
+ }
323
+ function parseExportSection(bytes, start, end, exportNames, alreadyExported) {
324
+ let pos = start;
325
+ const rCount = readU32Leb(bytes, pos, end);
326
+ const count = rCount.value;
327
+ pos = rCount.pos;
328
+ for (let i = 0; i < count; i++) {
329
+ const nm = readName(bytes, pos, end);
330
+ const name = nm.value;
331
+ pos = nm.pos;
332
+ if (pos >= end)
333
+ fail("unexpected EOF in export entry kind");
334
+ const kind = bytes[pos++];
335
+ const rIdx = readU32Leb(bytes, pos, end);
336
+ const idx = rIdx.value;
337
+ pos = rIdx.pos;
338
+ exportNames.add(name);
339
+ switch (kind) {
340
+ case 0: // func
341
+ alreadyExported.Func.add(idx);
342
+ break;
343
+ case 1: // table
344
+ alreadyExported.Table.add(idx);
345
+ break;
346
+ case 2: // mem
347
+ alreadyExported.Memory.add(idx);
348
+ break;
349
+ case 3: // global
350
+ alreadyExported.Global.add(idx);
351
+ break;
352
+ default:
353
+ // ignore unknown kinds (future-proof)
354
+ break;
355
+ }
356
+ }
357
+ dbg("existing export names:", Array.from(exportNames).sort());
358
+ dbg("existing exported indices:", {
359
+ Func: Array.from(alreadyExported.Func).sort((a, b) => a - b),
360
+ Table: Array.from(alreadyExported.Table).sort((a, b) => a - b),
361
+ Memory: Array.from(alreadyExported.Memory).sort((a, b) => a - b),
362
+ Global: Array.from(alreadyExported.Global).sort((a, b) => a - b),
363
+ });
364
+ }
365
+ function scanWasmBinary(wasmBytes) {
366
+ const bytes = wasmBytes;
367
+ const endAll = bytes.length;
368
+ if (endAll < 8)
369
+ fail("WASM too small");
370
+ if (bytes[0] !== 0x00 || bytes[1] !== 0x61 || bytes[2] !== 0x73 || bytes[3] !== 0x6d) {
371
+ fail("bad WASM magic");
372
+ }
373
+ // version bytes[4..8) (ignored)
374
+ let pos = 8;
375
+ const exportNames = new Set();
376
+ const alreadyExported = {
377
+ Func: new Set(),
378
+ Table: new Set(),
379
+ Memory: new Set(),
380
+ Global: new Set(),
381
+ };
382
+ const funcsToExport = new Set();
383
+ let importTables = 0, localTables = 0;
384
+ let importMemories = 0, localMemories = 0;
385
+ let importGlobals = 0, localGlobals = 0;
386
+ const mutableGlobalsToExport = new Set();
387
+ const noteSection = (id) => {
388
+ switch (id) {
389
+ case 2:
390
+ return "import";
391
+ case 4:
392
+ return "table";
393
+ case 5:
394
+ return "memory";
395
+ case 6:
396
+ return "global";
397
+ case 7:
398
+ return "export";
399
+ case 9:
400
+ return "element";
401
+ default:
402
+ return `section(${id})`;
403
+ }
404
+ };
405
+ while (pos < endAll) {
406
+ const id = bytes[pos++];
407
+ const rSize = readU32Leb(bytes, pos, endAll);
408
+ const size = rSize.value;
409
+ pos = rSize.pos;
410
+ const start = pos;
411
+ const end = start + size;
412
+ if (end > endAll)
413
+ fail(`section ${id} size out of bounds`);
414
+ try {
415
+ if (id === 2) {
416
+ // import section
417
+ let p = start;
418
+ const rCount = readU32Leb(bytes, p, end);
419
+ const n = rCount.value;
420
+ p = rCount.pos;
421
+ for (let i = 0; i < n; i++) {
422
+ // module/name
423
+ p = readName(bytes, p, end).pos;
424
+ p = readName(bytes, p, end).pos;
425
+ if (p >= end)
426
+ fail("unexpected EOF in import kind");
427
+ const kind = bytes[p++];
428
+ switch (kind) {
429
+ case 0: // func
430
+ p = readU32Leb(bytes, p, end).pos; // typeidx
431
+ break;
432
+ case 1: // table
433
+ p = parseTableType(bytes, p, end);
434
+ importTables++;
435
+ break;
436
+ case 2: // mem
437
+ p = parseMemType(bytes, p, end);
438
+ importMemories++;
439
+ break;
440
+ case 3: {
441
+ // global
442
+ const gt = parseGlobalType(bytes, p, end);
443
+ p = gt.pos;
444
+ if (gt.mutable)
445
+ mutableGlobalsToExport.add(importGlobals);
446
+ importGlobals++;
447
+ break;
448
+ }
449
+ case 4: // tag (future-proof)
450
+ p = readU32Leb(bytes, p, end).pos;
451
+ break;
452
+ default:
453
+ dbg(`unknown import kind ${kind}; cannot safely skip (bailing import parse)`);
454
+ // safest: bail parsing this section
455
+ i = n;
456
+ break;
457
+ }
458
+ }
459
+ dbg("imports:", { importTables, importMemories, importGlobals });
460
+ }
461
+ else if (id === 4) {
462
+ // table section
463
+ let p = start;
464
+ const rCount = readU32Leb(bytes, p, end);
465
+ const n = rCount.value;
466
+ p = rCount.pos;
467
+ for (let i = 0; i < n; i++)
468
+ p = parseTableType(bytes, p, end);
469
+ localTables += n;
470
+ dbg("tables:", { localTables, totalTables: importTables + localTables });
471
+ }
472
+ else if (id === 5) {
473
+ // memory section
474
+ let p = start;
475
+ const rCount = readU32Leb(bytes, p, end);
476
+ const n = rCount.value;
477
+ p = rCount.pos;
478
+ for (let i = 0; i < n; i++)
479
+ p = parseMemType(bytes, p, end);
480
+ localMemories += n;
481
+ dbg("memories:", { localMemories, totalMemories: importMemories + localMemories });
482
+ }
483
+ else if (id === 6) {
484
+ // global section
485
+ let p = start;
486
+ const rCount = readU32Leb(bytes, p, end);
487
+ const n = rCount.value;
488
+ p = rCount.pos;
489
+ let globalIndex = importGlobals;
490
+ for (let i = 0; i < n; i++) {
491
+ const gt = parseGlobalType(bytes, p, end);
492
+ p = gt.pos;
493
+ if (gt.mutable)
494
+ mutableGlobalsToExport.add(globalIndex);
495
+ // init expr (also collect ref.func if present)
496
+ p = parseConstExprCollectRefFuncs(bytes, p, end, funcsToExport, `global[${globalIndex}].init`);
497
+ globalIndex++;
498
+ }
499
+ localGlobals += n;
500
+ dbg("globals:", {
501
+ localGlobals,
502
+ totalGlobals: importGlobals + localGlobals,
503
+ mutableGlobals: Array.from(mutableGlobalsToExport).sort((a, b) => a - b),
504
+ });
505
+ }
506
+ else if (id === 7) {
507
+ // export section
508
+ parseExportSection(bytes, start, end, exportNames, alreadyExported);
509
+ }
510
+ else if (id === 9) {
511
+ // element section (the big one we care about for function refs)
512
+ parseElementSectionCollectFuncIdxs(bytes, start, end, funcsToExport);
513
+ }
514
+ }
515
+ catch (e) {
516
+ dbg(`parse error in ${noteSection(id)}:`, e);
517
+ // keep going; we'll still try to add exports using whatever we found
518
+ }
519
+ pos = end;
520
+ }
521
+ const totalTables = importTables + localTables;
522
+ const totalMemories = importMemories + localMemories;
523
+ dbg("binary scan summary:", {
524
+ funcsToExport: Array.from(funcsToExport).sort((a, b) => a - b),
525
+ mutableGlobalsToExport: Array.from(mutableGlobalsToExport).sort((a, b) => a - b),
526
+ totalTables,
527
+ totalMemories,
528
+ });
529
+ return {
530
+ exportNames,
531
+ alreadyExported,
532
+ funcsToExport,
533
+ mutableGlobalsToExport,
534
+ totalMemories,
535
+ totalTables,
536
+ };
537
+ }
538
+ /* =======================================================================================
539
+ * Main entry
540
+ * ======================================================================================= */
541
+ export async function preprocess_wasm_bytes(wasmBytes) {
542
+ await ensureNodeLikeGlobals();
543
+ const [{ decode }, astMod, { addWithAST }] = await Promise.all([
544
+ import("@webassemblyjs/wasm-parser"),
545
+ import("@webassemblyjs/ast"),
546
+ import("@webassemblyjs/wasm-edit"),
547
+ ]);
548
+ const t = astMod;
549
+ // Binary scan is authoritative for "what should be exported"
550
+ const { exportNames, alreadyExported, funcsToExport, mutableGlobalsToExport, totalMemories, totalTables, } = scanWasmBinary(wasmBytes);
551
+ // Decode AST for editing
552
+ const ast = decode(wasmBytes, {
553
+ ignoreCodeSection: false,
554
+ ignoreDataSection: true,
555
+ });
556
+ const newNodes = [];
557
+ // 1) Export functions found via element section / ref.func const-exprs
558
+ const funcList = Array.from(funcsToExport).sort((a, b) => a - b);
559
+ for (const idx of funcList) {
560
+ if (alreadyExported.Func.has(idx))
561
+ continue;
562
+ const name = uniqueName(`__f${idx}`, exportNames, `__f${idx}`);
563
+ newNodes.push(t.moduleExport(name, t.moduleExportDescr("Func", t.indexLiteral(idx))));
564
+ alreadyExported.Func.add(idx);
565
+ }
566
+ // 2) Export mutable globals
567
+ const globList = Array.from(mutableGlobalsToExport).sort((a, b) => a - b);
568
+ for (const idx of globList) {
569
+ if (alreadyExported.Global.has(idx))
570
+ continue;
571
+ const name = uniqueName(`__global_${idx}`, exportNames, `__global_${idx}`);
572
+ newNodes.push(t.moduleExport(name, t.moduleExportDescr("Global", t.indexLiteral(idx))));
573
+ alreadyExported.Global.add(idx);
574
+ }
575
+ // 3) Export all memories
576
+ for (let idx = 0; idx < totalMemories; idx++) {
577
+ if (alreadyExported.Memory.has(idx))
578
+ continue;
579
+ const name = uniqueName(`__memory_${idx}`, exportNames, `__memory_${idx}`);
580
+ newNodes.push(t.moduleExport(name, t.moduleExportDescr("Memory", t.indexLiteral(idx))));
581
+ alreadyExported.Memory.add(idx);
582
+ }
583
+ // 4) Export all tables (unconditional)
584
+ for (let idx = 0; idx < totalTables; idx++) {
585
+ if (alreadyExported.Table.has(idx))
586
+ continue;
587
+ const name = uniqueName(`__table_${idx}`, exportNames, `__table_${idx}`);
588
+ newNodes.push(t.moduleExport(name, t.moduleExportDescr("Table", t.indexLiteral(idx))));
589
+ alreadyExported.Table.add(idx);
590
+ }
591
+ if (newNodes.length === 0)
592
+ return wasmBytes;
593
+ const out = addWithAST(ast, toExactArrayBuffer(wasmBytes), newNodes);
594
+ return new Uint8Array(out);
595
+ }
596
+ //# sourceMappingURL=preprocess_wasm_bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preprocess_wasm_bytes.js","sourceRoot":"","sources":["../src/preprocess_wasm_bytes.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,+BAA+B;AAC/B,EAAE;AACF,qCAAqC;AACrC,+GAA+G;AAC/G,6GAA6G;AAC7G,0GAA0G;AAC1G,iEAAiE;AACjE,oDAAoD;AACpD,wDAAwD;AAIxD,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,SAAS,YAAY;IACnB,MAAM,CAAC,GAAI,UAAkB,CAAC,yBAAyB,CAAC;IACxD,OAAO,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;AACpD,CAAC;AACD,SAAS,GAAG,CAAC,GAAG,IAAW;IACzB,IAAI,YAAY,EAAE;QAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,IAAI,yBAAyB,GAAG,KAAK,CAAC;AACtC,KAAK,UAAU,qBAAqB;IAClC,IAAI,yBAAyB;QAAE,OAAO;IACtC,yBAAyB,GAAG,IAAI,CAAC;IAEjC,MAAM,CAAC,GAAQ,UAAiB,CAAC;IACjC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACf,CAAC,CAAC,OAAO,KAAK,EAAE,G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C,CAAC;IACrE,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "preprocess-wasm-bytes",
3
+ "version": "0.1.0",
4
+ "description": "Preprocess a WebAssembly binary by adding exports for table-referenced functions, mutable globals, memories, and tables.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "scripts": {
21
+ "gen:sample-wasm": "node scripts/gen-sample-wasm.mjs",
22
+ "dev": "npm run gen:sample-wasm && vite",
23
+ "build": "npm run gen:sample-wasm && vite build",
24
+ "preview": "vite preview",
25
+
26
+ "clean": "node -e \"import('node:fs').then(fs=>fs.rmSync('dist',{recursive:true,force:true}))\"",
27
+ "build:lib": "npm run clean && tsc -p tsconfig.lib.json",
28
+ "prepublishOnly": "npm run build:lib"
29
+ },
30
+ "dependencies": {
31
+ "@webassemblyjs/ast": "^1.14.1",
32
+ "@webassemblyjs/wasm-edit": "^1.14.1",
33
+ "@webassemblyjs/wasm-parser": "^1.14.1",
34
+ "buffer": "^6.0.3"
35
+ },
36
+ "devDependencies": {
37
+ "typescript": "^5.9.3",
38
+ "vite": "^7.2.6",
39
+ "wabt": "^1.0.39"
40
+ },
41
+ "engines": {
42
+ "node": ">=20.19.0"
43
+ }
44
+ }