Tool:Emscripten
Appearance
| On this wiki | Facts · Code · Notes · Topics |
|---|
Emscripten (MIT / NCSA) compiles C and C++ to WebAssembly and emits a JavaScript glue file with a Module object, a wasmImports table and a createWasm function that fetches and instantiates the .wasm next to it.
The glue is how to name the functions of an Emscripten .wasm whose own names were minified (Format:WebAssembly binary format#Toolchain identification).
Glue markers (src/shell.js and src/preamble.js at 5f63ff2e)
var Module = typeof <EXPORT_NAME> != 'undefined' ? <EXPORT_NAME> : {}at the top (shell.js lines 27-37; EXPORT_NAME defaults to Module).Module['locateFile']hook used to find the .wasm (shell.js line 176);wasmBinaryFileandfindWasmBinarypick the file name (preamble.js lines 408-445); a secondary.deferred.wasmor.<moduleID>.wasmname for split modules (lines 503-506).createWasm()builds the import object with'env': wasmImports(preamble.js lines 724, 740), callsWebAssembly.instantiateStreamingwhere allowed (589, 680) and storeswasmExports = instance.exports, then runswasmExports['__wasm_call_ctors'](172).- In minified release builds the import module is
aand the names a, b, c; thewasmImportsobject in the glue is the only map back to real functions.
Reversing
Read wasmImports for the libc and syscall stubs the program uses, then the exported wrapper calls (_main, _malloc, ...) to give names to the exports. Unverified: names of wrappers in a fully minified glue were not checked on a sample here.
Source: emscripten-core/emscripten at 5f63ff2e370da7e6fffd8f54379860bdd18118f9 (read, not run).
Code & repositories
- https://github.com/emscripten-core/emscripten @
5f63ff2e370da7e6fffd8f54379860bdd18118f9· license: MIT OR NCSA (declared by the contributor for the files used; GitHub reports MIT (read from LICENSE; GitHub's API was busy) for the repository)
Emscripten: src/shell.js and src/preamble.js are the JS glue templates (Module, wasmBinaryFile, createWasm, wasmImports).
Tested on: source read, not run · checked 2026-10-19