.WASM
WebAssembly module
Introduction
A .wasm file is a compiled WebAssembly module: compact bytecode for a
simple, portable virtual machine. Every major web browser runs it beside JavaScript,
and standalone runtimes run it outside the browser. Compilers for C, C++, Rust, Go and
other languages can produce it.
The same module can be written as text in the .wat format, which tools
convert to and from the binary.
Software
- Every major web browser: Chrome, Firefox, Safari and Edge
- Node.js (Windows, macOS, Linux)
- Wasmtime (Windows, macOS, Linux)
- Wasmer (Windows, macOS, Linux)
- WABT, with
wasm2watandwasm-objdump(Windows, macOS, Linux) - Binaryen, with the
wasm-optoptimiser (Windows, macOS, Linux) - Ghidra, with a WebAssembly extension (Windows, macOS, Linux)
Structure
A module starts with an 8-byte header: the magic bytes 00 61 73 6D
(\0asm) and the version, 1, as a little-endian 32-bit number. Then come
sections. Each is one byte of section ID, its size as an unsigned LEB128 number, and its
contents. The standard sections appear at most once each and in a fixed order: type,
import, function, table, memory, global, export, start, element, data count, code and
data. Custom sections (ID 0) can appear anywhere and hold extras such as function names
for debuggers.
0magic00 61 73 6D4 bytes4version01 00 00 004 bytes8sections, one after anothervaries+0id: 1 type, 2 import, 3 function … 10 code, 11 data1 byte+1size of the contents, LEB1281 to 5 bytes…contentssize bytes