Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to decompile Web Assembly (wasm) files to a specific programming language?

Tags:

webassembly

Currently most programming languages, can compile to WebAssembly (officially or through an external package).

So I'm wondering... is it possible to decompile the web assembly file? So we can have the code written in one language that can compile to .wasm, and decompile it using another language? And then, generate .java, .js, .py, .go and etc, from the .wasm file. Is it possible?

like image 919
KadoBOT Avatar asked Jun 11 '19 10:06

KadoBOT


People also ask

Is it possible to decompile Wasm?

The WASM files can be decompiled using the WebAssembly-to-C decompiler.

Can you reverse engineer WebAssembly?

Conclusion. We have now successfully reverse engineered our first simple Wasm program. The example was extremely simplistic, but we have to start with the basics. In the process of reversing we learned how Wasm interacts with the outside environment by calling imported functions that are declared in JavaScript.

What language is best for Wasm?

The State of WebAssembly 2022 survey of Wasm developers shows Rust on top, with Blazor and Python on the rise. The Rust programming language is the most frequently used language for developing WebAssembly applications, according to a recent survey.

What languages can be compiled to Wasm?

Since it's a well-defined format, any language can have Wasm as a compilation target. Consequently, there are now around 40 high-level programming languages that support WebAssembly, including C and C++, Python, Go, Rust, Java, and PHP.


3 Answers

There is a converter from webassembly binaries to C.

https://github.com/WebAssembly/wabt/tree/master/wasm2c

As written in the other answer it will not look anything of the original source file, but at least it should be able to transfer the logic to C which then again also could be used with other languages by wrapping it into a library.

like image 118
Peter Salomonsen Avatar answered Sep 28 '22 13:09

Peter Salomonsen


There are no WebAssembly disassemblers that I am aware of at the moment. One significant obstacle to this is that a great deal of information is discarded in the compilation process. The languages you are interested in (JavaScript, Java, Python, Go) have constructs like strings, classes, structs, etc ... none of which exist at the WebAssembly level. Furthermore, function and variables names are not (typically) present in the resulting WebAssembly module.

While you could create a tool that would 'translate' a WebAssembly module into a Java, Python, Go or JavaScript program that when executed it exhibited the correct behaviour, it would look nothing like the original program that was compiled to WebAssembly.

like image 38
ColinE Avatar answered Sep 28 '22 15:09

ColinE


@KadoBOT you can use wasm-decompile.exe to decompile your wasm file https://github.com/WebAssembly/wabt

like image 42
Praveer Kumar Avatar answered Sep 28 '22 14:09

Praveer Kumar