Skip to main content

Module wasm

Module wasm 

Source
Expand description

WebAssembly binary container — parse + byte-identical write.

WASM modules are a flat sequence of sections:

  magic    : '\0' 'a' 's' 'm'         (4 bytes)
  version  : u32 little-endian        (4 bytes; 1 for current MVP)
  sections : (section_id:u8, size:LEB128, body:[u8; size])*

For round-trip byte identity we preserve every byte of the header and every section. LEB128 size encodings vary in width — LLVM pads them to 5 bytes so post-link patching can adjust section sizes without shifting the rest of the module — and WasmFile keeps the encoded form verbatim so a parse → write_to_vec cycle reproduces the input exactly.

Section interpretation (decoding function bodies, names, types, …) lives in higher layers. The format crate only offers: where each section starts, what its id is, and a handle to its raw bytes.

Structs§

Section
Metadata for one section, located by byte range into the parent WasmFile’s bytes. The header_range covers the section id byte plus the size-LEB; body_range covers just the section’s payload.
WasmFile
A parsed WASM module. bytes is the verbatim input; the sections list records where each section starts and ends so callers can read or rewrite them without re-parsing.

Enums§

Error
Errors raised by WasmFile::parse.

Constants§

MAGIC
4-byte WASM magic.
SECTION_CODE
SECTION_CUSTOM
Standard section IDs. The custom id (0) groups everything non-standard — debug info, name maps, producer metadata, …
SECTION_DATA
SECTION_DATA_COUNT
SECTION_ELEMENT
SECTION_EXPORT
SECTION_FUNCTION
SECTION_GLOBAL
SECTION_IMPORT
SECTION_MEMORY
SECTION_START
SECTION_TABLE
SECTION_TYPE

Functions§

is_wasm
Is bytes plausibly a WASM module? Just checks the first 4 bytes against MAGIC.

Type Aliases§

Result