mapper

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: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEBUG        = false
	DEBUG_MAPPER = false
	DEBUG_OFFSET = false
	DEBUG_LABEL  = false
)
View Source
const DEBUG_READ = false

Variables

View Source
var (
	ErrParseStop     = errors.New("manual parse stop")
	ErrParseContinue = errors.New("manual parse continue")
)
View Source
var DEBUG_EVAL = false

Functions

func ByteCountSI

func ByteCountSI(b int64) string

func FileSize

func FileSize(f afero.File) int64

Types

type EvaluateError

type EvaluateError struct {
	// contains filtered or unexported fields
}

an expression failed to evaluate

func (EvaluateError) Error

func (e EvaluateError) Error() string

type Field

type Field struct {
	Offset int64
	Length int64

	// on-disk endianness
	Endian string

	// underlying data structure
	Format value.DataField

	// matched patterns
	MatchedPatterns []value.MatchedPattern

	// filename for the next output data
	Outfile string

	// if set, data is imported from external file
	ImportFile string
}

type FileLayout

type FileLayout struct {
	Structs []*Struct

	// pointer to its internal yaml representation, so we can access "constants"
	DS *template.DataStructure

	// default extension
	Extension string

	// lastpath/filename-without-ext, eg "archives/zip"
	BaseName string
	// contains filtered or unexported fields
}

parsed file data from a template "layout"

func MapFileToGivenTemplate

func MapFileToGivenTemplate(cfg *MapperConfig) (fl *FileLayout, err error)

maps input file to template specified in cfg.TemplateFilename

func MapFileToMatchingTemplate

func MapFileToMatchingTemplate(cfg *MapperConfig) (fl *FileLayout, err error)

maps input file to a matching template

func MapReader

func MapReader(cfg *MapReaderConfig) (*FileLayout, error)

produces a list of fields with offsets and sizes from input reader based on data structure

func (*FileLayout) DecryptData

func (fl *FileLayout) DecryptData(encData []byte) ([]byte, error)

func (*FileLayout) EvaluateExpression

func (fl *FileLayout) EvaluateExpression(in string, df *value.DataField) (int64, error)

evaluates a math expression

func (*FileLayout) EvaluateStringExpression

func (fl *FileLayout) EvaluateStringExpression(in string, df *value.DataField) (string, error)

evaluates a string expression

func (*FileLayout) ExpandVariables

func (fl *FileLayout) ExpandVariables(s string, df *value.DataField) (string, error)

replace variables with their values

func (*FileLayout) Extract

func (fl *FileLayout) Extract(outDir string) error

Write data streams to outDir

func (*FileLayout) GetAddressLengthPair

func (fl *FileLayout) GetAddressLengthPair(df *value.DataField) (int64, int64)

returns unitLength, totalLength (in bytes)

func (*FileLayout) GetFieldValue

func (fl *FileLayout) GetFieldValue(field *Field) interface{}

returns a presentation of the value in the data type (field.Format.Kind)

func (*FileLayout) GetInt

func (fl *FileLayout) GetInt(s string, df *value.DataField) (int64, error)

finds the first field named `structName`.`fieldName`

func (*FileLayout) GetLength

func (fl *FileLayout) GetLength(s string, df *value.DataField) (int, error)

finds the first field named `structName`.`fieldName` returns: length,error

func (*FileLayout) GetOffset

func (fl *FileLayout) GetOffset(query string, df *value.DataField) (int, error)

finds the first field named `structName`.`fieldName` returns: offset,error

func (*FileLayout) GetStruct

func (fl *FileLayout) GetStruct(name string) (*Struct, error)

func (*FileLayout) GetValue

func (fl *FileLayout) GetValue(s string, df *value.DataField) (string, []byte, error)

finds the first field named `structName`.`fieldName` returns: kind, bytes, error

func (*FileLayout) MappedBytes

func (fl *FileLayout) MappedBytes() int64

return the number of mapped bytes

func (*FileLayout) MatchedValue

func (fl *FileLayout) MatchedValue(s string, df *value.DataField) (string, error)

returns the pattern matched value of field named `structName`.`fieldName`

func (*FileLayout) Present

func (fl *FileLayout) Present(cfg *PresentFileLayoutConfig)

func (*FileLayout) PresentFieldValue

func (fl *FileLayout) PresentFieldValue(field *Field, b []byte) string

presents the value of the data type (field.Format.Kind) in a human-readable form

func (*FileLayout) PresentFullString

func (fl *FileLayout) PresentFullString(cfg *PresentFileLayoutConfig) string

used for tests, buffered, returns when presentation is fully rendered.

func (*FileLayout) PresentStructureTree

func (fl *FileLayout) PresentStructureTree(structs []*Struct)

func (*FileLayout) PresentType

func (fl *FileLayout) PresentType(df *value.DataField) string

presents the underlying type as it is known in the template format

func (*FileLayout) ReadVariableLengthS64

func (fl *FileLayout) ReadVariableLengthS64() (uint64, []byte, int64, error)

Codes integers in 7-bit chunks, little-endian order. The high-bit in each byte signifies if it is the last byte. used by system/macos/nibarchive

func (*FileLayout) ReadVariableLengthU32

func (fl *FileLayout) ReadVariableLengthU32() (uint32, []byte, int64, error)

this encoding is used by fonts/woff2 (UIntBase128) returns decoded value, raw bytes, byte length, error

func (*FileLayout) ReadVariableLengthU64

func (fl *FileLayout) ReadVariableLengthU64() (uint64, []byte, int64, error)

this encoding is used by archive/xz returns decoded value, raw bytes, byte length, error

type MapReaderConfig

type MapReaderConfig struct {
	F afero.File

	DS *template.DataStructure

	// initial endianness
	Endian string

	// base offset
	StartOffset int64

	Brief bool

	MeasureTime bool
}

type MapperConfig

type MapperConfig struct {
	F                afero.File
	StartOffset      int64
	TemplateFilename string
	MeasureTime      bool

	// only detect by magic, don't map
	Brief bool
}

func (*MapperConfig) MatchesMagic

func (cfg *MapperConfig) MatchesMagic(ds *template.DataStructure) (bool, string)

returns true if magic bytes and optionally file extension matches

type PresentFileLayoutConfig

type PresentFileLayoutConfig struct {
	ShowRaw           bool
	ShowInDecimal     bool
	ReportUnmapped    bool
	ReportOverlapping bool
	InUTC             bool
}

type Struct

type Struct struct {
	// unique name of this instance of the struct
	Name string

	// child nodes
	Children []*Struct

	// additional decoration
	Label string

	Fields []Field

	// slice-based counter index, 0-based
	Index int
	// contains filtered or unexported fields
}

parsed file data section from a template "struct"

Jump to

Keyboard shortcuts

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