• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-2825

benches/H03-May-2022-10090

examples/H03-May-2022-168152

src/H03-May-2022-10,9508,936

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D06-May-202074 65

.gitignoreH A D14-Nov-201931 43

.gitmodulesH A D14-Nov-201990 43

.rustfmt.tomlH A D14-Nov-201969 21

CODE_OF_CONDUCT.mdH A D14-Nov-20193.4 KiB5030

Cargo.lockH A D06-May-202027.8 KiB626556

Cargo.tomlH A D06-May-20201.2 KiB4336

Cargo.toml.orig-cargoH A D06-May-2020912 3227

LICENSEH A D14-Nov-201912 KiB220182

ORG_CODE_OF_CONDUCT.mdH A D14-Nov-20196.9 KiB140113

README.mdH A D05-Feb-20201.8 KiB7149

SECURITY.mdH A D14-Nov-20191.8 KiB3017

compare-master.shH A D05-Feb-2020313 135

format-all.shH A D14-Nov-2019213 135

test-all.shH A D14-Nov-20191.5 KiB5830

README.md

1# The WebAssembly binary file decoder in Rust
2
3**A [Bytecode Alliance](https://bytecodealliance.org/) project**
4
5![CI](https://github.com/bytecodealliance/wasmparser/workflows/CI/badge.svg)
6[![crates.io link](https://img.shields.io/crates/v/wasmparser.svg)](https://crates.io/crates/wasmparser)
7
8The decoder library provides lightweight and fast decoding/parsing of WebAssembly binary files.
9
10The other goal is minimal memory footprint. For this reason, there is no AST or IR of WebAssembly data.
11
12See also its sibling at https://github.com/wasdk/wasmparser
13
14
15## Documentation
16
17The documentation and examples can be found at the https://docs.rs/wasmparser/
18
19
20## Example
21
22```rust
23use wasmparser::WasmDecoder;
24use wasmparser::Parser;
25use wasmparser::ParserState;
26
27fn get_name(bytes: &[u8]) -> &str {
28  str::from_utf8(bytes).ok().unwrap()
29}
30
31fn main() {
32  let ref buf: Vec<u8> = read_wasm_bytes();
33  let mut parser = Parser::new(buf);
34  loop {
35    let state = parser.read();
36    match *state {
37        ParserState::BeginWasm { .. } => {
38            println!("====== Module");
39        }
40        ParserState::ExportSectionEntry { field, ref kind, .. } => {
41            println!("  Export {} {:?}", get_name(field), kind);
42        }
43        ParserState::ImportSectionEntry { module, field, .. } => {
44            println!("  Import {}::{}", get_name(module), get_name(field))
45        }
46        ParserState::EndWasm => break,
47        _ => ( /* println!(" Other {:?}", state) */ )
48    }
49  }
50}
51```
52
53
54## Fuzzing
55
56To fuzz test wasmparser.rs, switch to a nightly Rust compiler and install [cargo-fuzz]:
57
58```
59cargo install cargo-fuzz
60```
61
62Then, from the root of the repository, run:
63
64```
65cargo fuzz run parse
66```
67
68If you want to use files as seeds for the fuzzer, add them to `fuzz/corpus/parse/` and restart cargo-fuzz.
69
70[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz
71