Zum Inhalt springen

WABT - WebAssembly Binary Toolkit Cheatsheet

WABT - WebAssembly Binary Toolkit Cheatsheet

WABT (ausgesprochen „wabbit”) ist das Referenz-WebAssembly Binary Toolkit — eine Suite von Kommandozeilenwerkzeugen für die Arbeit mit wasm auf niedriger Ebene. Es konvertiert zwischen dem Binärformat .wasm und dem menschenlesbaren Textformat .wat, disassembliert und dumpt Module, validiert sie, produziert eine C-ähnliche Dekompilierung und interpretiert/führt wasm aus. Es ist die Grundwerkzeugkiste für sowohl wasm-Entwicklung als auch Reverse Engineering.

Installation

PlatformCommand
macOS (Homebrew)brew install wabt
Debian/Ubuntusudo apt install wabt
Arch Linuxsudo pacman -S wabt
npmnpm install -g wabt
From sourcebuild with CMake from the WebAssembly/wabt repo
Verifywat2wasm --version

The Core Tools

ToolKonvertiert / macht
wat2wasmText .wat → Binär .wasm
wasm2watBinär .wasm → Text .wat (Disassemble)
wasm-objdumpDump Sections, Opcodes, Symbole
wasm-decompileErzeuge lesbaren C-ähnlichen Pseudocode
wasm-validateValidiere ein Modul
wasm-interpInterpretiere/führe ein Modul aus (Stack Machine)
wasm2cKonvertiere wasm → C-Quelle
wasm-stripEntferne Sections (z.B. Namen) aus einem Modul

Text ↔ Binary

# Assemble text to binary
wat2wasm module.wat -o module.wasm

# Disassemble binary to text (the RE starting point)
wasm2wat module.wasm -o module.wat

# Keep debug names / custom sections while disassembling
wasm2wat --generate-names module.wasm
OptionEffekt
-o FILEAusgabedatei
--generate-namesSynthesiere Namen für unbenannte Funcs/Locals
--enable-FEATURESchalte ein wasm-Proposal ein (z.B. --enable-threads)
-vAusführlich

Inspecting a Module (objdump)

# Full section + disassembly dump
wasm-objdump -x module.wasm      # headers/sections
wasm-objdump -d module.wasm      # disassemble code
wasm-objdump -s module.wasm      # section contents (hex)
FlagZeigt
-hSection Headers
-xDetails aller Sections
-dDisassemblierte Funktionskörper
-sRohes Section-Inhalte
-j SECTIONAuf eine Section limitieren

Decompiling (Readable Output)

# C-like decompilation — much easier to read than WAT
wasm-decompile module.wasm -o module.dcmp

wasm-decompile rekonstruiert strukturierten Kontrollfluss und typisierte Locals, was es zu einer schnellen Möglichkeit macht, zu verstehen, was ein Modul tut während der Triage.

Validate & Run

CommandZweck
wasm-validate module.wasmBestätige, dass das Modul wohlgeformt ist
wasm-interp module.wasm --run-all-exportsFühre exportierte Funktionen aus
wasm2c module.wasm -o module.cEmittiere C zum Kompilieren/Analysieren

Reverse-Engineering Workflow

# 1) Disassemble with names
wasm2wat --generate-names target.wasm -o target.wat

# 2) Dump imports/exports to understand capabilities
wasm-objdump -x target.wasm | grep -E "import|export"

# 3) Get readable pseudocode
wasm-decompile target.wasm -o target.dcmp

# 4) Hunt for strings/URLs in data sections
wasm-objdump -s target.wasm | less

Feature Flags (Proposals)

FlagAktiviert
--enable-threadsThreads/Atomare Operationen
--enable-simdSIMD
--enable-bulk-memoryBulk Memory Operations
--enable-reference-typesReferenztypen
--enable-allAlle unterstützten Proposals

Verwende diese, wenn ein Modul neuere wasm-Features verwendet und die Standard-Tools es ablehnen.

ToolRolle
WABTKonvertiere/Inspektiere/Validiere/Dekompiliere wasm
diswasmHigher-Level Pseudocode Decompiler
wasm-toolsRust Low-Level Manipulation
BinaryenCompiler/Optimizer Toolchain (wasm-dis, wasm-opt)

Resources