Skip to content
A simple event-driven library for parsing WebAssembly binary files
Rust Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Use actions/checkout@v1 to support submodules checkout (#154) Dec 3, 2019
benches Fix mutable global validation Aug 19, 2019
examples Multi value (#103) Jun 24, 2019
fuzz
src
tests
testsuite @ 6d29716
.gitignore
.gitmodules
.rustfmt.toml Add a minimal .rustfmt.toml so that IDEs know to apply rustfmt. Sep 28, 2018
CODE_OF_CONDUCT.md
Cargo.toml
LICENSE Change wasmparser's license to "Apache-2.0 WITH LLVM-exception". Oct 9, 2018
ORG_CODE_OF_CONDUCT.md
README.md Make it a Bytecode Alliance project (#136) Nov 12, 2019
SECURITY.md Make it a Bytecode Alliance project (#136) Nov 12, 2019
compare-master.sh
format-all.sh
test-all.sh

README.md

The WebAssembly binary file decoder in Rust

A Bytecode Alliance project

Build Status crates.io link

The decoder library provides lightweight and fast decoding/parsing of WebAssembly binary files.

The other goal is minimal memory footprint. For this reason, there is no AST or IR of WebAssembly data.

See also its sibling at https://github.com/wasdk/wasmparser

Documentation

The documentation and examples can be found at the https://docs.rs/wasmparser/

Example

use wasmparser::WasmDecoder;
use wasmparser::Parser;
use wasmparser::ParserState;

fn get_name(bytes: &[u8]) -> &str {
  str::from_utf8(bytes).ok().unwrap()
}

fn main() {
  let ref buf: Vec<u8> = read_wasm_bytes();
  let mut parser = Parser::new(buf);
  loop {
    let state = parser.read();
    match *state {
        ParserState::BeginWasm { .. } => {
            println!("====== Module");
        }
        ParserState::ExportSectionEntry { field, ref kind, .. } => {
            println!("  Export {} {:?}", get_name(field), kind);
        }
        ParserState::ImportSectionEntry { module, field, .. } => {
            println!("  Import {}::{}", get_name(module), get_name(field))
        }
        ParserState::EndWasm => break,
        _ => ( /* println!(" Other {:?}", state) */ )
    }
  }
}

Fuzzing

To fuzz test wasmparser.rs, switch to a nightly Rust compiler and install cargo-fuzz:

cargo install cargo-fuzz

Then, from the root of the repository, run:

cargo fuzz run parse

If you want to use files as seeds for the fuzzer, add them to fuzz/corpus/parse/ and restart cargo-fuzz.

You can’t perform that action at this time.