Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:Wasm-bindgen

From ReverseEngineering.wiki
Tool
On this wiki Facts · Code · Notes · Topics

wasm-bindgen (MIT/Apache-2.0) is the Rust tool that generates the JavaScript glue around a Rust-built .wasm: the output pair NAME.js plus NAME_bg.wasm, imports from __wbindgen_placeholder__, __wbg_* import names and a __wbindgen_start export.

The glue is recognisable even when the Rust code is stripped.

Recognising output

  • Two files per crate: <name>_bg.wasm and the glue (<name>.js, or <name>_bg.js plus an entry file for the bundler target). Generated code names ./{module_name}_bg.wasm and ./{module_name}_bg.js (crates/cli-support/src/js/mod.rs lines 1032, 1457-1458, 1652).
  • Initialisation API: __wbg_init (default export, async), initSync, __wbg_get_imports, and for the bundler target __wbg_set_wasm(val) (mod.rs lines 1439-1441, 1584, 1026). The glue calls wasm.__wbindgen_start() after instantiation (lines 1429, 1464).
  • In the .wasm: imports from the module __wbindgen_placeholder__ (mod.rs line 1125) with names __wbindgen_* and __wbg_<name>_<hash>; custom producers section with walrus and wasm-bindgen. See Format:WebAssembly binary format#Toolchain identification.
  • A cached TextDecoder (cachedTextDecoder) for strings read from linear memory (line 3365 and following).
  • Exports without a name get the fallback __wbindgen_export (line 7213).

Reversing

The JavaScript glue shows which Rust functions the page calls (exported methods keep their Rust names) and what each import does; the logic itself is in the .wasm, see Format:WebAssembly binary format and Tool:Rustc. Source: wasm-bindgen at 9bec40cf3a09e759ad1e3de6921f6dc5caef384b, crates/cli-support/src/js/mod.rs (read, not run).

Code & repositories

  • https://github.com/wasm-bindgen/wasm-bindgen @ 9bec40cf3a09e759ad1e3de6921f6dc5caef384b · license: MIT OR Apache-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)
    wasm-bindgen: crates/cli-support/src/js/mod.rs generates the JS glue (__wbg_init, initSync, __wbg_set_wasm, _bg.wasm names).
    Tested on: source read, not run · checked 2026-10-19