template

package
v0.0.0-...-dad441a Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEBUG_PATTERNS = false
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant

type Constant struct {
	Name  string
	Value []byte
}

type DataStructure

type DataStructure struct {

	// constants derived from eq & bit pattern matches
	Constants []Constant

	// evaluated file structs
	EvaluatedStructs []EvaluatedStruct

	Layout []value.DataField

	Magic []Magic

	// default endian
	Endian string

	// if template lacks magic bytes
	NoMagic bool

	// extensions, used to match if no_magic is true
	Extensions []string

	// used to match if no_magic is true
	Filenames []string

	// lastpath/filename-without-ext, eg "archives/zip"
	BaseName string
}

structure of a evaluated ./templates/ yaml file. see Template for the raw structure corresponding to the yaml file

func NewDataStructureFrom

func NewDataStructureFrom(template *Template, basename string) (*DataStructure, error)

func UnmarshalTemplateIntoDataStructure

func UnmarshalTemplateIntoDataStructure(b []byte, basename string) (*DataStructure, error)

func (*DataStructure) FindStructure

func (ds *DataStructure) FindStructure(name string) (*EvaluatedStruct, error)

looks up layout name from sections

type EvaluatedStruct

type EvaluatedStruct struct {
	Name string

	Expressions []Expression
}

a "structs" node

type Expression

type Expression struct {
	Field value.DataField

	Pattern value.DataPattern

	// represents a branch such as "if <expression>" child nodes
	Children []Expression

	// represents u8/u16/u32/u64 child patterns (eq, bit, default)
	MatchPatterns []MatchPattern
}

holds a parsed expression

func (*Expression) EvaluateMatchPatterns

func (es *Expression) EvaluateMatchPatterns(b []byte, endian string) ([]value.MatchedPattern, error)

matches data stream with bit patterns

type HexString

type HexString []byte

func (*HexString) UnmarshalYAML

func (e *HexString) UnmarshalYAML(unmarshal func(interface{}) error) error

Implements the Unmarshaler interface of the yaml pkg.

type HexStringU64

type HexStringU64 uint64

func (*HexStringU64) UnmarshalYAML

func (e *HexStringU64) UnmarshalYAML(unmarshal func(interface{}) error) error

Implements the Unmarshaler interface of the yaml pkg.

type Magic

type Magic struct {
	Offset HexStringU64
	Match  HexString
	Endian string

	// Optional: if set, a list of extensions that must match in addition to the magic signature.
	Extensions []string
}

type MatchPattern

type MatchPattern struct {
	// pattern description
	Label string

	// eq, bit
	Operation string

	Pattern string
}

func ParseMatchPattern

func ParseMatchPattern(item yaml.MapItem) (*MatchPattern, error)

parses a key-value pattern field such as "eq 025f: TYPE_ONE"

type Template

type Template struct {
	// list of url references for file format
	References []string

	// list of common extensions
	Extensions []string

	// used to match if no_magic is true
	Filenames []string

	// kind of file (archive, image ...)
	Kind string

	// mime type
	Mime string

	// descriptive file format name
	Name string

	// endianness (big, little), can be overridden in a struct declaration
	Endian string

	// if template lacks magic bytes
	NoMagic bool `yaml:"no_magic"`

	// the format uses more than one data file
	MultiFile bool `yaml:"multi_file"`

	// magic id:s
	Magic []Magic

	// file structs
	Structs []yaml.MapItem

	// struct layout
	Layout []string
}

Template represents the structure of a templates/*.yml file

type ValidationError

type ValidationError struct {
	Message string
}

the input file failed to match a required marker

func (ValidationError) Error

func (r ValidationError) Error() string

Jump to

Keyboard shortcuts

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