A C++ tool that converts WebAssembly (.wasm) binaries to JavaScript, with an optional AI-powered pass using the Gemini API to rename variables and summarize functions.
- Transpiles
.wasmbinary files to readable JavaScript (IIFE or ESM format) - Reconstructs high-level control flow:
if/else,while,do/while,forloops - Resolves WebAssembly imports, exports, memories, tables, globals, and data segments
- AI mode (optional): uses Gemini to:
- Rename obscure local variables to meaningful camelCase names
- Generate one-sentence summaries for each function
- Propose human-readable function names
All dependencies are fetched automatically via CMake FetchContent:
| Library | Version | Purpose |
|---|---|---|
| wabt | 1.0.37 | WebAssembly binary parsing |
| nlohmann/json | v3.11.3 | JSON serialization for API requests |
| cpp-httplib | v0.15.3 | HTTPS client for Gemini API |
| OpenSSL | system | TLS support for HTTPS |
- CMake ≥ 3.28
- C++23-compatible compiler (MSVC 2022 or GCC 13+)
- OpenSSL (system-installed)
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Releasecmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build buildSet the GEMINI_API_KEY environment variable (not required for non-AI mode):
./WASM2JS
> enter absolute path of wasm: /path/to/module.wasm
> enter filename of the output file: output.js
> Do you want to use AI to summarize and rename the code? (y/n): n
The converted JavaScript will be saved to ./output/output.js.
Set the GEMINI_API_KEY environment variable before running:
Windows (PowerShell):
$env:GEMINI_API_KEY = "your_api_key_here"
.\WASM2JS.exeLinux/macOS:
export GEMINI_API_KEY="your_api_key_here"
./WASM2JSThen run the tool and answer y when prompted for AI mode.
Note: You can get a free Gemini API key from Google AI Studio.
The tool outputs JavaScript in IIFE format (Immediately Invoked Function Expression):
const imports = { /* ... */ };
(function() {
// Helper functions (i64, f32, f64, rotl32, rotr32, ...)
// Memory and table initialization
// Global variables
// Transpiled WebAssembly functions
return {
exportedFunc1: func42,
exportedFunc2: func7,
};
})();WASM2JS/
├── main.cpp # Entry point: CLI prompts, calls Parser
├── Parser.h # Parser class declaration, types, enums
├── Parser.cpp # Core transpilation logic
├── Utils.h # Utility functions (string ops, Gemini API client)
├── Utils.cpp # Utility function implementations
├── pch.h # Precompiled header (Windows/WinSock definitions)
└── CMakeLists.txt # Build configuration
MIT License. See LICENSE for details.