mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-28 15:01:13 +01:00
This is intemediate step to move parts of the `ukify` down to the main Talos source tree, and call it from `talosctl` binary. The next step will be to integrate it into the imager and move `.uki` build out of the Dockerfile. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
39 lines
840 B
Go
39 lines
840 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"
|
|
"log"
|
|
|
|
"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) {
|
|
log.Printf("section size: %d", section.Size)
|
|
|
|
data, err := section.Data()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return data[:section.VirtualSize], nil
|
|
}
|
|
}
|
|
|
|
return nil, fmt.Errorf("could not find SBAT section")
|
|
}
|