Skip to content

sagar-h007/WASM-inspector-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebAssembly Inspector & Validator CLI

A production-quality CLI tool for inspecting and validating WebAssembly modules using WasmEdge.

Features

  • wasm inspect - Inspect WASM module structure

    • List imports (module, name, type)
    • List exports
    • Show memory and table definitions
    • Display custom sections
  • wasm validate - Validate modules against WebAssembly spec

    • Detect invalid sections
    • Report type mismatches
    • Find broken indices
  • wasm wasi-check - Analyze WASI usage

    • Detect WASI imports
    • List required WASI capabilities
    • Flag unsafe or privileged syscalls
  • wasm stats - Show module statistics

    • Code and data segment sizes
    • Memory limits
    • Function counts

Installation

Prerequisites

  • CMake 3.15 or later
  • C++17 compatible compiler (g++, clang++)
  • WasmEdge library installed

Installing WasmEdge

# macOS with Homebrew
brew install wasmedge

# Or install from source
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash

Building from Source

git clone https://github.com/yourusername/wasm-inspector-cli.git
cd wasm-inspector-cli
mkdir build && cd build
cmake ..
cmake --build .

Installing

sudo cmake --install .

Usage

Inspect a WASM Module

# Human-readable output
wasm inspect module.wasm

# JSON output
wasm inspect module.wasm --json

Example output:

Module: module.wasm

Imports (2):
  env.print_i32 (function: (i32) -> ())
  env.memory (memory: min=1 pages)

Exports (2):
  add (function: (i32, i32) -> (i32))
  memory (memory: min=1 pages)

Memories (1):
  [0] min=1 pages

Tables (0):
  (none)

Custom Sections (0):
  (none)

Validate a WASM Module

wasm validate module.wasm

Example output:

✓ module.wasm is valid

Or for invalid modules:

✗ module.wasm is invalid

Errors:
  [Type section] Type mismatch in function signature

Check WASI Usage

wasm wasi-check module.wasm

Example output:

WASI Usage: Yes

Required Capabilities:
  file_descriptor:
    - fd_read
    - fd_write ⚠️  PRIVILEGED
  
  filesystem:
    - path_open ⚠️  PRIVILEGED
  
  clock:
    - clock_time_get

Privileged Syscalls:
  ⚠️  fd_write
  ⚠️  path_open

Show Module Statistics

wasm stats module.wasm

Example output:

Module Statistics: module.wasm

Total File Size:  45234 bytes

Functions:        127
  Imports:        5
  Defined:        122

Memory:
  Min:            2 pages (128 KB)
  Max:            16 pages (1024 KB)

Tables:           1
  [0] min=50, max=200

JSON Output Mode

All commands support --json flag for machine-readable output:

wasm inspect module.wasm --json
{
  "module": "module.wasm",
  "imports": [
    {
      "module": "env",
      "name": "print_i32",
      "type": "function",
      "details": "(i32) -> ()"
    }
  ],
  "exports": [
    {
      "name": "add",
      "type": "function",
      "details": "(i32, i32) -> (i32)"
    }
  ],
  "memories": [],
  "tables": [],
  "custom_sections": []
}

Development

Project Structure

wasm-inspector-cli/
├── include/wasm_inspector/
│   ├── cli/              # CLI command implementations
│   └── wasm/             # WASM parsing and analysis
├── src/
│   ├── cli/              # Command implementations
│   ├── wasm/             # Core WASM functionality
│   └── main.cpp          # CLI entry point
├── tests/
│   └── fixtures/         # Test WASM modules
└── CMakeLists.txt

Building Test Fixtures

The test fixtures are provided as .wat (WebAssembly Text) files. To compile them to .wasm:

# Install WABT (WebAssembly Binary Toolkit)
brew install wabt

# Compile WAT files
cd tests/fixtures
wat2wasm simple.wat -o simple.wasm
wat2wasm with_wasi.wat -o with_wasi.wasm
wat2wasm memory_table.wat -o memory_table.wasm

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors