A MoonBit-native WebAssembly binary inspection and analysis library.
Dependencies
git clone https://github.com/clbbbb/moonbit-wasm-inspect.git
cd moonbit-wasm-inspect
moon check --deny-warn
moon test --deny-warn///|
import {
"clbbbb/moonbit-wasm-inspect" @inspect,
}moon run cmd/main inspect path/to/module.wasm
moon run cmd/main inspect --json path/to/module.wasm
moon run cmd/main validate path/to/module.wasm
moon run cmd/main validate --json path/to/module.wasm
moon run cmd/main features path/to/module.wasm
moon run cmd/main diff left.wasm right.wasmmoon run examples/basicmatch @inspect.parse_module(bytes) {
Err(error) => println(error.message())
Ok(binary) => match @inspect.decode_module(binary) {
Err(error) => println(error.message())
Ok(decoded) => println(@inspect.render_decoded(decoded))
}
}pub enum DecodeError {
UnexpectedEof(Int)
InvalidLeb128(Int, String)
InvalidHeader(String)
InvalidSection(Int, Int, String)
UnsupportedFeature(String, Int)
InvalidUtf8(Int)
ValidationError(Int, String)
}pub struct DecodedModule {
binary : Module
types : Array[FunctionType]
imports : Array[Import]
function_types : Array[Int]
tables : Array[TableInfo]
memories : Array[MemoryInfo]
globals : Array[GlobalInfo]
exports : Array[Export]
start_function : Int?
code_bodies : Array[CodeBody]
element_segments : Array[ElementSegment]
data_segments : Array[DataSegment]
data_count : Int?
tags : Array[TagInfo]
warnings : Array[String]
}pub enum ExternalKind {
FunctionExternal
TableExternal
MemoryExternal
GlobalExternal
TagExternal
} derive(Eq)pub struct FunctionName {
index : Int
name : String
}pub struct InstructionStats {
instruction_count : Int
control_depth : Int
control_block_count : Int
branch_count : Int
call_count : Int
called_functions : Array[Int]
memory_access_count : Int
local_access_count : Int
constant_count : Int
bulk_memory_instruction_count : Int
simd_instruction_count : Int
}pub struct Limits {
minimum : Int
maximum : Int?
shared : Bool
memory64 : Bool
}pub struct ModuleStats {
byte_length : Int
section_count : Int
custom_section_count : Int
payload_bytes : Int
}pub struct NameSection {
module_name : String?
function_names : Array[FunctionName]
unknown_subsection_ids : Array[Int]
}pub struct SectionDifference {
label : String
left_size : Int?
right_size : Int?
}pub enum SectionKind {
Custom
Type
Import
Function
Table
Memory
Global
Export
Start
Element
Code
Data
DataCount
Tag
} derive(Eq)pub struct Span {
start : Int
end : Int
}pub enum ValueType {
I32
I64
F32
F64
V128
FuncRef
ExternRef
}pub enum WasmFeature {
MultiMemory
Memory64
Threads
BulkMemory
ReferenceTypes
ExceptionHandling
Simd
}A MoonBit-native WebAssembly binary inspection and analysis library.
Dependencies