#wasm #edit #transform #parser #instrument

bin+lib wasm-edit

Edit and instrument already compiled Wasm binaries

6 releases

0.1.6 Jan 24, 2023
0.1.5 Dec 13, 2022
0.1.3 Nov 15, 2022

#594 in WebAssembly

Download history 10/week @ 2022-11-24 9/week @ 2022-12-01 58/week @ 2022-12-08 18/week @ 2022-12-15 12/week @ 2022-12-22 9/week @ 2022-12-29 11/week @ 2023-01-05 11/week @ 2023-01-12 45/week @ 2023-01-19 20/week @ 2023-01-26 56/week @ 2023-02-02 49/week @ 2023-02-09 51/week @ 2023-02-16 24/week @ 2023-02-23 8/week @ 2023-03-02 9/week @ 2023-03-09

101 downloads per month
Used in dwarfdump-wasm

MIT license

115KB
3K SLoC

wasm-edit

Edit and instrument already compiled Wasm binaries

Install

cargo install wasm-edit

Edit the main memory

Change the initial memory amount (in pages):

wasm-edit edit-memory --initial-memory=1000 < input.wasm > output.wasm

Trace calls to memory.grow

Trace calls to the memory.grow instruction:

wasm-edit instrument-memory < input.wasm > output.wasm

Requires Wasi, but doesn't require any change on the host. Tested with Rust and theoretically working with C/C++ (clang).

Coredump generation

Add the coredump generation:

wasm-edit coredump < input.wasm > output.wasm

When WebAssembly encounters a unreachable instruction it will unwind the stack, collect informations and generate a coredump.

The coredump struct is stored at a fixed location, this might conflict with other transformations like asyncify.

Collect the entire WebAssembly memory and use wasmgdb to analyze.

Running into stack overflow

Some Wasm binaries have very recursive flow of control, increase the maximum stack size:

$ ulimit -s 160000

Dependencies

~5MB
~110K SLoC