wasmfile

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const ALIGN_DATA = 8
View Source
const WasmHeader uint32 = 0x6d736100
View Source
const WasmVersion uint32 = 0x00000001

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeEntry

type CodeEntry struct {
	Locals         []types.ValType
	PCValid        bool
	CodeSectionPtr uint64
	CodeSectionLen uint64
	Expression     []*expression.Expression
}

CodeEntry

func (*CodeEntry) DecodeWat

func (e *CodeEntry) DecodeWat(d string, wf *WasmFile) error

func (*CodeEntry) EncodeBinary

func (c *CodeEntry) EncodeBinary(w io.Writer) error

func (*CodeEntry) InsertAfterRelocating

func (ce *CodeEntry) InsertAfterRelocating(wf *WasmFile, to string) error

func (*CodeEntry) InsertFuncEnd

func (ce *CodeEntry) InsertFuncEnd(wf *WasmFile, to string) error

func (*CodeEntry) InsertFuncStart

func (ce *CodeEntry) InsertFuncStart(wf *WasmFile, to string) error

func (*CodeEntry) ModifyAllCalls

func (ce *CodeEntry) ModifyAllCalls(m map[int]int)

func (*CodeEntry) ModifyAllGlobals

func (ce *CodeEntry) ModifyAllGlobals(m map[int]int)

func (*CodeEntry) ModifyUnresolvedFunctions

func (ce *CodeEntry) ModifyUnresolvedFunctions(m map[string]string)

func (*CodeEntry) ReplaceInstr

func (ce *CodeEntry) ReplaceInstr(wf *WasmFile, from string, to string) error

func (*CodeEntry) ResolveFunctions

func (ce *CodeEntry) ResolveFunctions(wf *WasmFile) error

func (*CodeEntry) ResolveGlobals

func (ce *CodeEntry) ResolveGlobals(wf *WasmFile) error

func (*CodeEntry) ResolveLengths

func (ce *CodeEntry) ResolveLengths(wf *WasmFile) error

func (*CodeEntry) ResolveRelocations

func (ce *CodeEntry) ResolveRelocations(wf *WasmFile, base_pointer int) error

type CustomEntry

type CustomEntry struct {
	Name string
	Data []byte
}

CustomEntry

type DataEntry

type DataEntry struct {
	MemIndex int
	Offset   []*expression.Expression
	Data     []byte
}

DataEntry

func (*DataEntry) DecodeWat

func (e *DataEntry) DecodeWat(d string, wf *WasmFile) error

func (*DataEntry) EncodeBinary

func (c *DataEntry) EncodeBinary(w io.Writer) error

func (*DataEntry) GetStringEncodedData

func (d *DataEntry) GetStringEncodedData() string

type ElemEntry

type ElemEntry struct {
	TableIndex int
	Offset     []*expression.Expression
	Indexes    []uint64
}

ElemEntry

func (*ElemEntry) DecodeWat

func (e *ElemEntry) DecodeWat(d string, wf *WasmFile) error

func (*ElemEntry) EncodeBinary

func (c *ElemEntry) EncodeBinary(w io.Writer) error

type ExportEntry

type ExportEntry struct {
	Name  string
	Type  types.ExportType
	Index int
}

ExportEntry

func (*ExportEntry) DecodeWat

func (e *ExportEntry) DecodeWat(d string, wf *WasmFile) error

func (*ExportEntry) EncodeBinary

func (c *ExportEntry) EncodeBinary(w io.Writer) error

type FunctionEntry

type FunctionEntry struct {
	TypeIndex int
}

FunctionEntry

func (*FunctionEntry) DecodeWat

func (e *FunctionEntry) DecodeWat(d string, wf *WasmFile) error

func (*FunctionEntry) EncodeBinary

func (f *FunctionEntry) EncodeBinary(w io.Writer) error

type GlobalEntry

type GlobalEntry struct {
	Type       types.ValType
	Mut        byte
	Expression []*expression.Expression
}

GlobalEntry

func (*GlobalEntry) DecodeWat

func (e *GlobalEntry) DecodeWat(d string, wf *WasmFile) error

func (*GlobalEntry) EncodeBinary

func (c *GlobalEntry) EncodeBinary(w io.Writer) error

type ImportEntry

type ImportEntry struct {
	Module string
	Name   string
	Type   types.ExportType
	Index  int
}

ImportEntry

func (*ImportEntry) DecodeWat

func (e *ImportEntry) DecodeWat(d string, wf *WasmFile) error

func (*ImportEntry) EncodeBinary

func (ie *ImportEntry) EncodeBinary(w io.Writer) error

type MemoryEntry

type MemoryEntry struct {
	LimitMin int
	LimitMax int
}

MemoryEntry

func (*MemoryEntry) DecodeWat

func (e *MemoryEntry) DecodeWat(d string) error

func (*MemoryEntry) EncodeBinary

func (c *MemoryEntry) EncodeBinary(w io.Writer) error

type TableEntry

type TableEntry struct {
	TableType byte
	LimitMin  int
	LimitMax  int
}

TableEntry

func (*TableEntry) DecodeWat

func (e *TableEntry) DecodeWat(d string) error

func (*TableEntry) EncodeBinary

func (c *TableEntry) EncodeBinary(w io.Writer) error

type TypeEntry

type TypeEntry struct {
	Param  []types.ValType
	Result []types.ValType
}

TypeEntry

func (*TypeEntry) Clone

func (t *TypeEntry) Clone() *TypeEntry

func (*TypeEntry) DecodeWat

func (e *TypeEntry) DecodeWat(d string) error

func (*TypeEntry) EncodeBinary

func (te *TypeEntry) EncodeBinary(w io.Writer) error

func (*TypeEntry) Equals

func (te *TypeEntry) Equals(te2 *TypeEntry) bool

type WasmFile

type WasmFile struct {
	// Each section of the wasm file
	Function []*FunctionEntry
	Type     []*TypeEntry
	Custom   []*CustomEntry
	Export   []*ExportEntry
	Import   []*ImportEntry
	Table    []*TableEntry
	Global   []*GlobalEntry
	Memory   []*MemoryEntry
	Code     []*CodeEntry
	Data     []*DataEntry
	Elem     []*ElemEntry

	Debug *debug.WasmDebug
}

func New

func New(filename string) (*WasmFile, error)

Create a new WasmFile from a file

func NewEmpty

func NewEmpty() *WasmFile

func NewFromWat

func NewFromWat(filename string) (*WasmFile, error)

Create a new WasmFile from a file

func (*WasmFile) AddData

func (wf *WasmFile) AddData(name string, data []byte)

func (*WasmFile) AddDataFrom

func (wf *WasmFile) AddDataFrom(addr int32, wfSource *WasmFile) int32

func (*WasmFile) AddExports

func (wf *WasmFile) AddExports(wfsource *WasmFile)

func (*WasmFile) AddFuncsFrom

func (wf *WasmFile) AddFuncsFrom(wfSource *WasmFile, remap_callback func(remap map[int]int))

func (*WasmFile) AddGlobal

func (wf *WasmFile) AddGlobal(name string, t types.ValType, expr string)

func (*WasmFile) AddTypeMaybe

func (wf *WasmFile) AddTypeMaybe(te *TypeEntry) int

*

  • AddTypeMaybe adds a type unless the exact type is already there. *

func (*WasmFile) DecodeBinary

func (wf *WasmFile) DecodeBinary(data []byte) (err error)

*

  • Decode a wasm binary into a WasmFile *

func (*WasmFile) DecodeWat

func (wf *WasmFile) DecodeWat(data []byte) (err error)

func (*WasmFile) EncodeBinary

func (wf *WasmFile) EncodeBinary(w io.Writer) error

func (*WasmFile) EncodeWat

func (wf *WasmFile) EncodeWat(w io.Writer) error

func (*WasmFile) FindFunction

func (wf *WasmFile) FindFunction(pc uint64) int

func (*WasmFile) GetCustomSectionData

func (wf *WasmFile) GetCustomSectionData(name string) []byte

func (*WasmFile) LookupImport

func (wf *WasmFile) LookupImport(n string) int

func (*WasmFile) ParseSectionCode

func (wf *WasmFile) ParseSectionCode(data []byte) error

*

  • Parse a Code section *

func (*WasmFile) ParseSectionCustom

func (wf *WasmFile) ParseSectionCustom(data []byte) error

*

  • Parse a Custom section *

func (*WasmFile) ParseSectionData

func (wf *WasmFile) ParseSectionData(data []byte) error

*

  • Parse a Data section *

func (*WasmFile) ParseSectionDataCount

func (wf *WasmFile) ParseSectionDataCount(data []byte) error

*

  • Parse a DataCount section *

func (*WasmFile) ParseSectionElem

func (wf *WasmFile) ParseSectionElem(data []byte) error

*

  • Parse an Elem section *

func (*WasmFile) ParseSectionExport

func (wf *WasmFile) ParseSectionExport(data []byte) error

*

  • Parse an Export section *

func (*WasmFile) ParseSectionFunction

func (wf *WasmFile) ParseSectionFunction(data []byte) error

*

  • Parse a Function section *

func (*WasmFile) ParseSectionGlobal

func (wf *WasmFile) ParseSectionGlobal(data []byte) error

*

  • Parse a Global section *

func (*WasmFile) ParseSectionImport

func (wf *WasmFile) ParseSectionImport(data []byte) error

*

  • Parse an Import section *

func (*WasmFile) ParseSectionMemory

func (wf *WasmFile) ParseSectionMemory(data []byte) error

*

  • Parse a Memory section *

func (*WasmFile) ParseSectionStart

func (wf *WasmFile) ParseSectionStart(data []byte) error

*

  • Parse a Start section *

func (*WasmFile) ParseSectionTable

func (wf *WasmFile) ParseSectionTable(data []byte) error

*

  • Parse a Table section *

func (*WasmFile) ParseSectionType

func (wf *WasmFile) ParseSectionType(data []byte) error

*

  • Parse a Type section *

func (*WasmFile) RedirectImport

func (wf *WasmFile) RedirectImport(fromModule string, from string, to string)

*

  • This will redirect all calls for an imported function to another function.
  • The imported function will be removed.
  • The target function must already exist, with a name.

func (*WasmFile) RegisterNextDataName

func (wf *WasmFile) RegisterNextDataName(n string)

func (*WasmFile) RegisterNextFunctionName

func (wf *WasmFile) RegisterNextFunctionName(n string)

func (*WasmFile) RegisterNextGlobalName

func (wf *WasmFile) RegisterNextGlobalName(n string)

func (*WasmFile) SetGlobal

func (wf *WasmFile) SetGlobal(name string, t types.ValType, expr string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL