Andrey Smirnov e0f383598e
chore: clean up the output of the imager
Use `Progress`, and options to pass around the way messages are written.

Fixed some tiny issues in the code, but otherwise no functional changes.

To make colored output work with `docker run`, switched back image
generation to use volume mount for output (old mode is still
functioning, but it's not the default, and it works when docker is not
running on the same host).

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2023-08-07 16:00:14 +04:00

36 lines
784 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package uki
import (
"debug/pe"
"fmt"
"github.com/siderolabs/talos/internal/pkg/secureboot"
)
// GetSBAT returns the SBAT section from the PE file.
func GetSBAT(path string) ([]byte, error) {
pefile, err := pe.Open(path)
if err != nil {
return nil, err
}
defer pefile.Close() //nolint:errcheck
for _, section := range pefile.Sections {
if section.Name == string(secureboot.SBAT) {
data, err := section.Data()
if err != nil {
return nil, err
}
return data[:section.VirtualSize], nil
}
}
return nil, fmt.Errorf("could not find SBAT section")
}