section

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: BSD-3-Clause Imports: 10 Imported by: 5

Documentation

Overview

Package section contains binary stream manipulation utilities.

Index

Constants

View Source
const CustomName = "name"

Variables

Unwrapped may be returned by custom section content loaders.

Functions

func CopyStandardSection added in v0.32.0

func CopyStandardSection(w io.Writer, l Loader, id ID, customLoader func(r Reader, payloadSize uint32) error) (length int64, err error)

CopyStandardSection with the given type if one is found. The returned length includes the copied section's header and payload (everything that was written). Custom sections preceding the standard section are processed by customLoader (or discarded if it's nil) - they are not included in the returned length. If another standard section type is found, it is left untouched (the reader will be backed up before the section id) and zero length is returned. If no standard section is encountered, zero length and io.EOF are returned. io.EOF is returned only when it occurs between sections.

func CustomLoader added in v0.32.0

func CustomLoader(loaders map[string]CustomContentLoader) func(Reader, uint32) error

func SkipCustomSections added in v0.32.0

func SkipCustomSections(l Loader, customLoader func(Reader, uint32) error) (err error)

SkipCustomSections until the next standard section. The skipped sections are processed by customLoader (or discarded if it's nil). If no standard section is encountered, io.EOF is returned. io.EOF is returned only when it occurs between sections.

Types

type ByteRange added in v0.32.0

type ByteRange struct {
	Start int64
	Size  uint32
}

ByteRange expresses a location and a length within a byte stream. The length is at most MaxUint32, and the inclusive start and exclusive end offsets are in range [0,MaxInt64].

func (ByteRange) End added in v0.34.0

func (r ByteRange) End() int64

End of the range (exclusive).

type CustomContentLoader added in v0.32.0

type CustomContentLoader func(sectionName string, r Reader, payloadSize uint32) error

type CustomMapping added in v0.32.0

type CustomMapping ByteRange

func (*CustomMapping) Loader added in v0.32.0

func (target *CustomMapping) Loader(sectionMap *Map) CustomContentLoader

Loader of arbitrary custom section. Remembers position, discards content.

type CustomSections added in v0.32.0

type CustomSections struct {
	Sections map[string][]byte
}

func (*CustomSections) Load added in v0.32.0

func (cs *CustomSections) Load(name string, r Reader, length uint32) (err error)

type FuncName added in v0.3.1

type FuncName struct {
	FuncName   string
	LocalNames []string
}

type ID added in v0.32.0

type ID = module.SectionID

type Loader added in v0.35.0

type Loader = loader.Loader

Loader is suitable for use with section loading functions.

func NewLoader added in v0.35.0

func NewLoader(r Reader) Loader

NewLoader creates a WebAssembly section loader.

type Map added in v0.32.0

type Map struct {
	Sections [module.NumSections]ByteRange
}

Map of section positions within the WebAssebly binary module. Map must me initialied with MakeMap or NewMap.

Section offset is always nonzero for standard sections; if the section is missing, it's the position where it would be. Section length is nonzero if the section is present.

Sections[Custom] holds information about the last (or latest) custom section. Its offset is zero if there are no custom sections.

func (*Map) PutSection added in v0.34.0

func (m *Map) PutSection(sectionID byte, sectionOffset int64, sectionSize, payloadSize uint32) error

PutSection location on the map.

type MappedNameSection added in v0.32.0

type MappedNameSection struct {
	NameSection
	Mapping ByteRange
}

func (*MappedNameSection) Loader added in v0.32.0

func (ns *MappedNameSection) Loader(sectionMap *Map) func(string, Reader, uint32) error

Loader of "name" section. Remembers position.

type NameSection

type NameSection struct {
	ModuleName string
	FuncNames  []FuncName
}

func (*NameSection) Load

func (ns *NameSection) Load(_ string, r Reader, length uint32) (err error)

Load "name" section.

type Reader added in v0.32.0

type Reader = binary.Reader

Reader is suitable for reading sections.

Jump to

Keyboard shortcuts

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