efi

package
v0.0.0-...-6437eea Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

package efi implements support for parsing and reassembling EFI Firmware Volumes, as used in some Apple device firmware components.

This library is similar in functionality and scope to UEFITool or uefi-firmware-parser. However, some differences remain:

  1. This implements the small subset of EFI FV as used by Apple devices, and is only tested against them. This is in contrast to UEFITool and uefi-firmware-parser which attempt to parse all possible images out there.
  2. This implementation is in pure Go, with Tiano compression routines implemented via WebAssembly (emscripten-compiled C from EDK2). This is in contrast to uefi-firmware-parser and UEFITool which link against a binary build of the functionality from EDK2.
  3. This implementation focuses on bit-perfect reconstruction of images. A back-to-back Read-to-Serialize of any image should result in exactly the same data outputted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileType

type FileType uint8
const (
	FileTypeSecurityCore FileType = 3
	FileTypePEICore      FileType = 4
	FileTypeDXECore      FileType = 5
	FileTypeDriver       FileType = 7
	FileTypeApplication  FileType = 9
	FileTypePadding      FileType = 240
)

func (FileType) String

func (f FileType) String() string

type FirmwareFile

type FirmwareFile struct {
	FirmwareFileHeader
	Sections []Section
	// ReadOffset is the offset within the volume at which the file has been
	// encountered.
	ReadOffset int
}

FirmwareFile represents an EFI Firmware File within a Firmware Volume.

func (*FirmwareFile) Serialize

func (f *FirmwareFile) Serialize() ([]byte, error)

type FirmwareFileHeader

type FirmwareFileHeader struct {
	GUID GUID
	// ChecksumHeader is recalculated when Serialize is called.
	ChecksumHeader uint8
	// ChecksumData is recalculated when Serialize is called.
	ChecksumData uint8
	FileType     FileType
	Attributes   uint8
	// Size is recalculated when Serialize is called.
	Size  Uint24
	State uint8
}

FirmwareFileHeader as per EFI standard.

type FirmwareVolumeHeader

type FirmwareVolumeHeader struct {
	Reserved [16]byte
	GUID     GUID
	// Length is recalculated when Serialize is called.
	Length        uint64
	Signature     [4]byte
	AttributeMask uint32
	HeaderLength  uint16
	// Checksum is recalculated when Serialize is called.
	Checksum        uint16
	ExtHeaderOffset uint16
	Reserved2       uint8
	Revision        uint8
}

FirmwareVolumeHeader as per EFI spec.

type GUID

type GUID [16]byte

GUID type compatible with EFI.

func MustParseGUID

func MustParseGUID(s string) GUID

func (GUID) String

func (g GUID) String() string

type NestedReader

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

NestedReader is a io.Reader which implements carving out a subelement of itself into another io.Reader. It also allows keeping track of the position of a reader within the original backing data.

func NewNestedReader

func NewNestedReader(underlying []byte) *NestedReader

func (*NestedReader) Advance

func (r *NestedReader) Advance(count int)

func (*NestedReader) Len

func (r *NestedReader) Len() int

func (*NestedReader) Read

func (r *NestedReader) Read(out []byte) (int, error)

func (*NestedReader) Sub

func (r *NestedReader) Sub(start, length int) *NestedReader

func (*NestedReader) TellGlobal

func (r *NestedReader) TellGlobal() int

type Section

type Section interface {
	// Header returns the common header of this section.
	Header() *commonSectionHeader
	// Sub returns all Sections nested within this section, if applicable.
	Sub() []Section
	// Serialize serializes this section into a binary.
	Serialize() ([]byte, error)

	// Raw returns the inner data within this section, if this section is a
	// PE32/TE/DXE/Raw section.
	Raw() []byte
	// SetRaw overrides the inner data within this section, if this section is
	// a PE32/TE/DXE/Raw section.
	SetRaw([]byte)
}

Section is the interface implemented by all EFI Firmware Volume File Sections.

type SectionType

type SectionType uint8
const (
	SectionTypeCompression SectionType = 1
	SectionTypeGUIDDefined SectionType = 2
	SectionTypePE32        SectionType = 16
	SectionTypeTE          SectionType = 18
	SectionTypeDXEDEPEX    SectionType = 19
	SectionTypeRaw         SectionType = 25
)

func (SectionType) String

func (s SectionType) String() string

type Uint24

type Uint24 [3]uint8

Uint24 as per EFI.

func ToUint24

func ToUint24(s uint32) Uint24

func (Uint24) Uint32

func (s Uint24) Uint32() uint32

type Volume

type Volume struct {
	FirmwareVolumeHeader
	Files []*FirmwareFile
	// Custom is trailing data at the end of the Volume.
	Custom []byte
}

Volume is an EFI Firmware Volume. It contains an array of Files, all of which contain recursively nested Sections.

func ReadVolume

func ReadVolume(r *NestedReader) (*Volume, error)

Parse an EFI Firmware Volume from a NestedReader. After parsing, all files and sections within them will be available. These can then be arbitrarily modified, and Serialize can be called on the resulting Volume to rebuild a binary.

func (*Volume) Serialize

func (v *Volume) Serialize() ([]byte, error)

Directories

Path Synopsis
package compression implements EFI compression/decompression routines by calling out into edk2 Tiano{Dec,C}ompres functions compiled into WebAssembly.
package compression implements EFI compression/decompression routines by calling out into edk2 Tiano{Dec,C}ompres functions compiled into WebAssembly.

Jump to

Keyboard shortcuts

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