Search code examples
ccompiler-constructiondecompileremscripten

Is it possible, to compile an exe to javascript?


There are some C decompilers, and using emscripten and LLVM it is possible to build a C/C++ code to the web.

So is it possible somehow, to decompile the exe, and compile it to HTML and JS?


Solution

  • This is (usually) not possible.

    The part of taking the .exe, decompiling it, then recompiling it into JavaScript alone is technically possible once someone writes such a tool.

    The problem however is that most compiled applications link to a mess of libraries, which are required for them to run. In browsers JavaScript is running in an isolated environment, providing a very different interface to that provided when running a binary on your operating system. It is much like if you wanted to run that .exe (a Windows application) on Linux. While it is possible (Wine), it is not something straightforward, and for that matter, nobody would like to wait for a package that large like Wine to download before your decompiled application embedded into a web page would start.

    Emscripten and the likes compile C into JavaScript knowing the differences of interfaces, much like you can create C code (with the help of cross-platform libraries such as SDL for example) which compiles for both Linux and Windows without changes. But the binaries still are not interchangeable: the decompiled .exe of this cross platform program would still be a Windows application.