Skip to content

Commit

Permalink
utils/uefi_vars, firmware parser: add initial files for these utils
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Dec 21, 2023
1 parent b6ad5d5 commit 5625ee8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
68 changes: 68 additions & 0 deletions utils/uefi_firmware_parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package utils

import (
"context"
"os"

"github.com/metal-toolbox/ironlib/model"
)

// TODO: for a future point in time
// The fiano library is in Go and could replace the code if its capable of extracting the Logo bmp image
// https://github.com/linuxboot/fiano

const (
EnvUefiFirmwareParserUtility = "IRONLIB_UTIL_UTIL_UEFI_FIRMWARE_PARSER"
)

type UefiFirmwareParser struct {
Executor Executor
}

// Return a new UefiFirmwareParser executor
func NewUefiFirmwareParserCmd(trace bool) *UefiFirmwareParser {
utility := "uefi-firmware-parser"

// lookup env var for util
if eVar := os.Getenv(EnvUefiFirmwareParserUtility); eVar != "" {
utility = eVar
}

e := NewExecutor(utility)
e.SetEnv([]string{"LC_ALL=C.UTF-8"})

if !trace {
e.SetQuiet()
}

return &UefiFirmwareParser{Executor: e}
}

// Attributes implements the actions.UtilAttributeGetter interface
func (u *UefiFirmwareParser) Attributes() (utilName model.CollectorUtility, absolutePath string, err error) {
// Call CheckExecutable first so that the Executable CmdPath is resolved.
er := u.Executor.CheckExecutable()

return "uefi-firmware-parser", u.Executor.CmdPath(), er
}

// ExtractLogoBMP extracts the Logo BMP image.
func (u *UefiFirmwareParser) ExtractLogoBMP(ctx context.Context, path string) error {

// mkdir dump && uefi-firmware-parser -b bios_region.img -o dump -e
//
// # list out GUIDs in firmware
// uefi-firmware-parser -b bios_region.img > parsed_regions
//
// # locate the logo
// grep -i bmp parsed_regions
// File 349: 7bb28b99-61bb-11d5-9a5d-0090273fc14d (EFI_DEFAULT_BMP_LOGO_GUID) type 0x02, attr 0x00, state 0x07, size 0x13a2b (80427 bytes), (freeform)
//
// # find the section raw dump identified by the GUID
// find ./ | grep 7bb28b99-61bb-11d5-9a5d-0090273fc14d | grep raw
// ./dump/volume-23658496/file-7bb28b99-61bb-11d5-9a5d-0090273fc14d/section0/section0.raw
//
// mv ./dump/volume-23658496/file-7bb28b99-61bb-11d5-9a5d-0090273fc14d/section0/section0.raw /tmp/logo.bmp

return nil
}
3 changes: 3 additions & 0 deletions utils/uefi_vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package utils

// UEFIVarsCollector implementation goes here

0 comments on commit 5625ee8

Please sign in to comment.