Transpile WebAssembly executable to i386 ELF which is impossible to run but which looks nice in decompiler.
As you can guess from name, this was made with IDA Hex-Rays in mind, WebAssembly decompilers already exist (JEB).
Based on modified wasm2c tool from WABT.
git clone https://github.com/vient/wasm2ida
./wasm2ida/wasm2ida.py -h- Mark all funcs as noinline
- Create stubs for imported funcs, link with them
- Check that module use only one memory block
- Check that module does not import memory blocks
- Merge memory sections in compile time to one array in
.wasm_datasection - Interpet memory offsets as raw pointers,
.wasm_datais mapped to 0 - Insert UD2 after
wasm_rt_trap - ... it would be nice if IDA somehow detected automatically that
wasm_rt_trapis noreturn and not rely on__builtin_trap - Use C++ mangling instead of WebAssembly one so IDA will set correct function types automatically
- Do something with
w2c_g0register, all local variables need to be allocated on x86 stack
- Mulpiple memory blocks
- Extern memories
- Extern tables