wasmdec is a program that converts WebAssembly binaries to C.
An online real-time WebAssembly decompiler utilizing wasmdec is avalible here
wasmdec will translate this WebAssembly binary:
(module
(func $addTwo (param i32 i32) (result i32)
(return
(i32.add (get_local 0) (get_local 1))
)
)
(export "addTwo" $addTwo)
)
To the following pseudo-C code:
int fn_addTwo(int arg0, int arg1) {
return arg0 + arg1;
}
Diep.io is a real time web game written in C++ and compiled to WebAssembly via Emscripten.
http://static.diep.io/build_<BUILD HASH>.wasm.wasm
wasmdec is capable of decompiling itself back to C.
wasm
target that uses Emscripten to compile wasmdec to WebAssemblyFrom the WebDSP repository:
WebDSP is a collection of highly performant algorithms, which are designed to be building blocks for web applications that aim to operate on media data. The methods are written in C++ and compiled to WASM, and exposed as simple vanilla Javascript functions developers can run on the client side.
A CTF write-up which uses wasmdec to reverse engineer a WASM binary
install.sh
as root.Clone the repository with
git clone https://github.com/wwwg/wasmdec.git --recursive
Make sure the recursive flag is set to clone all the submodules.
To build wasmdec and install all of it's dependencies, run sudo make all
in the wasmdec
directory. GCC 7 or higher is reccomended.
wasmdec -o (output file) (options) [input files]
Where options is one of:
-e
or --extra
: Emits extra function information as comments:
-m
or --memdump
:
-d
or --debug
: Print extra debug information to stdoutout.c