You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript library for programmatically generating WebAssembly modules. Build WASM bytecode using a fluent builder API — define functions, memory, tables, globals, imports, and exports, then compile and instantiate at runtime.
6
+
TypeScript library for building and analyzing WebAssembly modules. Generate WASM bytecode with a fluent builder API, or point it at any `.wasm` binary to disassemble, inspect, and decompile it.
-**Disassembler** — generates WAT text format from binary, per-function or full-module
33
+
-**Instruction decoder** — decodes all opcodes including prefixed families (GC, SIMD, bulk memory, threads) with offset and length tracking
34
+
-**DWARF parser** — reads `.debug_info`, `.debug_abbrev`, `.debug_line`, `.debug_str` sections. Extracts function names, parameter/local variable names with WASM local indices, type information (structs, pointers, base types), struct field names, global variable addresses, and source file/line mappings. Supports DWARF 4 and 5.
35
+
-**Source map parser** — V3 format with VLQ decoding, maps WASM byte offsets back to source files, lines, and columns
36
+
-**Name demangling** — C++ (Itanium ABI) and Rust (v0 + legacy) symbol demangling
37
+
38
+
### Decompiler
39
+
40
+
Converts WASM functions into structured C-like pseudocode. The pipeline: decode instructions → build a control flow graph → convert to SSA → run optimization passes → compute dominance (Cooper-Harvey-Kennedy) → recover high-level control flow → lower to expression trees → emit output.
41
+
42
+
-**Control flow recovery** — if/else, while, do-while, for loops, switch/case from `br_table`, early returns, break/continue. Natural loop detection via dominance and post-dominance analysis.
43
+
-**SSA optimization** — constant folding, copy propagation, dead code elimination, double negation elimination, comparison inversion, common subexpression elimination, phi simplification. Iterates until convergence.
44
+
-**Stack frame removal** — detects the `__stack_pointer - N` shadow-stack pattern from LLVM/Emscripten, removes prologue/epilogue, cleans up all `__stack_pointer` references from output.
45
+
-**Memory patterns** — variables with 2+ distinct constant offsets become struct field access (`ptr->field_0`). Expressions like `base + (index << 2)` become array indexing (`base[index]`). With DWARF info, fields get their real names.
46
+
-**Type inference** — maps WASM types to C types, recognizes sub-word loads as casts (`load8_s` → `(byte)`, `load16_u` → `(ushort)`), integrates DWARF type information when present.
47
+
-**Variable naming** — context-aware names from definition site (loads, calls, loop counters) and use site (addresses → `ptr`, comparisons → `cond`). 326 known functions (C stdlib, POSIX, WASI, Emscripten, Rust, Go, AssemblyScript) provide parameter and return value names.
48
+
-**String literals** — resolves constant addresses against data segments and inlines the string content.
Tested against real-world binaries — Quake (944 functions), Doom (769 functions), ioquake3, all decompiled successfully.
52
+
53
+
### General
54
+
27
55
- Zero production dependencies
28
56
29
57
## Install
@@ -165,7 +193,17 @@ See the [API Reference](docs/api.md) for complete documentation.
165
193
166
194
## Playground
167
195
168
-
Try webasmjs in the browser with the [interactive playground](https://devnamedzed.github.io/webasmjs/). It includes 100+ examples covering arithmetic, control flow, memory, tables, imports, floating point, i64/BigInt, SIMD, GC types, algorithms, WAT parsing, and post-MVP features.
196
+
Try webasmjs in the browser with the [interactive playground](https://devnamedzed.github.io/webasmjs/). 100+ builder examples covering arithmetic, control flow, memory, tables, imports, floating point, i64/BigInt, SIMD, GC types, algorithms, WAT parsing, and post-MVP features.
197
+
198
+
Drop any `.wasm` file into the explorer to inspect it. The explorer provides:
0 commit comments