visitors

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2018 License: BSD-3-Clause Imports: 17 Imported by: 6

Documentation

Overview

Package visitors uses the Visitor interface to recursively apply an operation over the firmware image. Also, functions are exported for using the visitors through the command line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteCLI

func ExecuteCLI(f uefi.Firmware, v []uefi.Visitor) error

ExecuteCLI applies each Visitor over the firmware in sequence.

func FindFileFVPredicate

func FindFileFVPredicate(r string) (func(f uefi.Firmware) bool, error)

FindFileFVPredicate is a generic predicate for searching FVs, files and UI sections.

func FindFileGUIDPredicate

func FindFileGUIDPredicate(r guid.GUID) func(f uefi.Firmware) bool

FindFileGUIDPredicate is a generic predicate for searching file GUIDs only.

func FindFilePredicate

func FindFilePredicate(r string) (func(f uefi.Firmware) bool, error)

FindFilePredicate is a generic predicate for searching files and UI sections only.

func ListCLI

func ListCLI() string

ListCLI prints out the help entries in the visitor struct as a newline-separated string in the form name: help

func ParseCLI

func ParseCLI(args []string) ([]uefi.Visitor, error)

ParseCLI constructs a list of visitors from the given CLI argument list. TODO: display some type of help message

func RegisterCLI

func RegisterCLI(name string, help string, numArgs int, createVisitor func([]string) (uefi.Visitor, error))

RegisterCLI registers a function `createVisitor` to be called when parsing the arguments with `ParseCLI`. For a Visitor to be accessible from the command line, it should have an init function which registers a `createVisitor` function here.

Types

type Assemble

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

Assemble reconstitutes the firmware tree assuming that the leaf node buffers are accurate

func (*Assemble) Run

func (v *Assemble) Run(f uefi.Firmware) error

Run just applies the visitor.

func (*Assemble) Visit

func (v *Assemble) Visit(f uefi.Firmware) error

Visit applies the Assemble visitor to any Firmware type.

type Cat

type Cat struct {
	// Input
	Predicate func(f uefi.Firmware) bool

	// Output
	io.Writer
	Matches []uefi.Firmware
}

Cat concatenates all RAW data sections from a file into a single byte slice.

func (*Cat) Run

func (v *Cat) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Cat) Visit

func (v *Cat) Visit(f uefi.Firmware) error

Visit applies the Extract visitor to any Firmware type.

type Count

type Count struct {
	// Optionally write result as JSON.
	W io.Writer `json:"-"`

	// Output
	FirmwareTypeCount map[string]int
	FileTypeCount     map[string]int
	SectionTypeCount  map[string]int
}

Count counts the number of each firmware type.

func (*Count) Run

func (v *Count) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Count) Visit

func (v *Count) Visit(f uefi.Firmware) error

Visit applies the Count visitor to any Firmware type.

type Dump

type Dump struct {
	// Input
	Predicate func(f uefi.Firmware) bool

	// Output
	// The file is written to this writer.
	W io.Writer
}

Dump a firmware file using a GUID or a name

func (*Dump) Run

func (v *Dump) Run(f uefi.Firmware) error

Run just calls the visitor

func (*Dump) Visit

func (v *Dump) Visit(f uefi.Firmware) error

Visit uses find to dump a file to W.

type Extract

type Extract struct {
	BasePath string
	DirPath  string
	Index    *uint64
}

Extract extracts any Firmware node to DirPath

func (*Extract) Run

func (v *Extract) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Extract) Visit

func (v *Extract) Visit(f uefi.Firmware) error

Visit applies the Extract visitor to any Firmware type.

type Find

type Find struct {
	// Input
	// Only when this functions returns true will the file appear in the
	// `Matches` slice.
	Predicate func(f uefi.Firmware) bool

	// Output
	Matches []uefi.Firmware

	// JSON is written to this writer.
	W io.Writer
	// contains filtered or unexported fields
}

Find a firmware file given its name or GUID.

func (*Find) Run

func (v *Find) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Find) Visit

func (v *Find) Visit(f uefi.Firmware) error

Visit applies the Find visitor to any Firmware type.

type Flatten

type Flatten struct {
	// Optionally write result as JSON.
	W io.Writer

	// Outputted flattened tree.
	List []FlattenedFirmware
	// contains filtered or unexported fields
}

Flatten places all nodes into a single slice and removes their children. Each node contains the index of its parent (the root node's parent is itself). This format is suitable for insertion into a database.

func (*Flatten) Run

func (v *Flatten) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Flatten) Visit

func (v *Flatten) Visit(f uefi.Firmware) error

Visit applies the Flatten visitor to any Firmware type.

type FlattenedFirmware

type FlattenedFirmware struct {
	Parent int
	Type   string
	Value  uefi.Firmware
}

FlattenedFirmware appears in the Flatten.List, contains the index of the parrent and has no children.

type Insert

type Insert struct {
	// Input
	Predicate func(f uefi.Firmware) bool
	NewFile   *uefi.File
	InsertType

	// Matched File
	FileMatch uefi.Firmware
}

Insert inserts a firmware file into an FV

func (*Insert) Run

func (v *Insert) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Insert) Visit

func (v *Insert) Visit(f uefi.Firmware) error

Visit applies the Insert visitor to any Firmware type.

type InsertType

type InsertType int

InsertType defines the insert type operation that is requested

const (

	// InsertFront inserts a file at the beginning of the firmware volume,
	// which is specified by 1) FVname GUID, or (File GUID/File name) of a file
	// inside that FV.
	InsertFront InsertType = iota
	// InsertEnd inserts a file at the end of the specified firmware volume.
	InsertEnd

	// These two specify a File to insert before or after
	// InsertAfter inserts after the specified file,
	// which is specified by a File GUID or File name.
	InsertAfter
	// InsertBefore inserts before the specified file.
	InsertBefore
)

Insert Types

func (InsertType) String

func (i InsertType) String() string

String creates a string representation for the insert type.

type JSON

type JSON struct {
	// JSON is written to this writer.
	W io.Writer
}

JSON prints any Firmware node as JSON.

func (*JSON) Run

func (v *JSON) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*JSON) Visit

func (v *JSON) Visit(f uefi.Firmware) error

Visit applies the JSON visitor to any Firmware type.

type ParseDir

type ParseDir struct {
	BasePath string
}

ParseDir creates the firmware tree and reads the binaries from the provided directory

func (*ParseDir) Parse

func (v *ParseDir) Parse() (uefi.Firmware, error)

Parse parses a directory and creates the tree.

func (*ParseDir) Run

func (v *ParseDir) Run(f uefi.Firmware) error

Run is not actually implemented cause we can't fit the interface

func (*ParseDir) Visit

func (v *ParseDir) Visit(f uefi.Firmware) error

Visit applies the ParseDir visitor to any Firmware type.

type Remove

type Remove struct {
	// Input
	Predicate func(f uefi.Firmware) bool

	// Output
	Matches []uefi.Firmware
}

Remove all firmware files with the given GUID.

func (*Remove) Run

func (v *Remove) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Remove) Visit

func (v *Remove) Visit(f uefi.Firmware) error

Visit applies the Remove visitor to any Firmware type.

type ReplacePE32

type ReplacePE32 struct {
	// Input
	Predicate func(f uefi.Firmware) bool
	NewPE32   []byte

	// Output
	Matches []uefi.Firmware
}

ReplacePE32 replaces PE32 sections with NewPE32 for all files matching Predicate.

func (*ReplacePE32) Run

func (v *ReplacePE32) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*ReplacePE32) Visit

func (v *ReplacePE32) Visit(f uefi.Firmware) error

Visit applies the Extract visitor to any Firmware type.

type Save

type Save struct {
	DirPath string
}

Save calls Assemble, then outputs the top image to a file.

func (*Save) Run

func (v *Save) Run(f uefi.Firmware) error

Run just applies the visitor.

func (*Save) Visit

func (v *Save) Visit(f uefi.Firmware) error

Visit calls the assemble visitor to make sure everything is reconstructed. It then outputs the top level buffer to a file.

type Table

type Table struct {
	W *tabwriter.Writer
	// contains filtered or unexported fields
}

Table prints the GUIDS, types and sizes as a compact table.

func (*Table) Run

func (v *Table) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Table) Visit

func (v *Table) Visit(f uefi.Firmware) error

Visit applies the Table visitor to any Firmware type.

type Validate

type Validate struct {
	// An optional Writer for writing errors when validation is complete.
	// When the writer it set, Run will also call os.Exit(1) upon finding
	// an error.
	W io.Writer

	// List of validation errors.
	Errors []error
}

Validate performs extra checks on the firmware image.

func (*Validate) Run

func (v *Validate) Run(f uefi.Firmware) error

Run wraps Visit and performs some setup and teardown tasks.

func (*Validate) Visit

func (v *Validate) Visit(f uefi.Firmware) error

Visit applies the Validate visitor to any Firmware type.

Jump to

Keyboard shortcuts

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