-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract kernel/initrd from uki for grub
Extract Kernel, Initrd and Commandline from UKI for GRUB installs. Fixes: #10191 Signed-off-by: Noel Georgi <[email protected]>
- Loading branch information
Showing
9 changed files
with
176 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 pe | ||
|
||
import ( | ||
"debug/pe" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
// fileCloser is an interface that wraps the Close method. | ||
type fileCloser interface { | ||
Close() error | ||
} | ||
|
||
// AssetInfo contains the kernel, initrd, and cmdline from a PE file. | ||
type AssetInfo struct { | ||
Kernel io.ReadSeeker | ||
Initrd io.ReadSeeker | ||
Cmdline io.ReadSeeker | ||
fileCloser | ||
} | ||
|
||
// Extract extracts the kernel, initrd, and cmdline from a PE file. | ||
func Extract(ukiPath string) (assetInfo AssetInfo, err error) { | ||
peFile, err := pe.Open(ukiPath) | ||
if err != nil { | ||
return assetInfo, fmt.Errorf("failed to open PE file: %w", err) | ||
} | ||
|
||
assetInfo.fileCloser = peFile | ||
|
||
for _, section := range peFile.Sections { | ||
switch section.Name { | ||
case ".initrd": | ||
assetInfo.Initrd = section.Open() | ||
case ".cmdline": | ||
assetInfo.Cmdline = section.Open() | ||
case ".linux": | ||
assetInfo.Kernel = section.Open() | ||
} | ||
} | ||
|
||
if assetInfo.Kernel == nil { | ||
return assetInfo, fmt.Errorf("kernel not found in PE file") | ||
} | ||
|
||
if assetInfo.Initrd == nil { | ||
return assetInfo, fmt.Errorf("initrd not found in PE file") | ||
} | ||
|
||
if assetInfo.Cmdline == nil { | ||
return assetInfo, fmt.Errorf("cmdline not found in PE file") | ||
} | ||
|
||
return assetInfo, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters