Converting WASM into C
Explore how to convert WebAssembly (WASM) binaries into C source code using the wasm2c tool from the WebAssembly Binary Toolkit (WABT). Gain insights into the autogenerated header and source files, runtime configurations, memory operations, and how functions are implemented in C after conversion. This lesson helps you understand the process of reverse-engineering WASM binaries into manageable C code for debugging and integration.
We'll cover the following...
WABT has a wasm2c converter that converts WASM into C source code and a header.
Let’s create a simple.wat file:
Add the following contents to simple.wat:
wat here defines a uanswer function that adds 22 and 20 to give 42 as the answer. Let's create a WebAssembly binary using wat2wasm:
This generates the simple.wasm binary. Now, convert the binary into C code using wasm2c:
This generates simple.c and simple.h.
Note: Both
simple.candsimple.hmight ...