Files
fastfetch/src/detection/bootmgr/bootmgr.c
T

45 lines
1.7 KiB
C
Raw Normal View History

2024-05-16 11:12:52 +08:00
#include "efi_helper.h"
2024-05-15 21:36:15 +08:00
2026-03-29 09:28:49 +08:00
static inline uint8_t evBits(uint16_t val, uint8_t mask, uint8_t shift) {
2024-05-15 21:36:15 +08:00
return (uint8_t) ((val & (mask << shift)) >> shift);
}
2026-03-29 09:28:49 +08:00
static void ffEfiUcs2ToUtf8(const uint16_t* const chars, FFstrbuf* result) {
for (uint32_t i = 0; chars[i]; i++) {
if (chars[i] <= 0x007f) {
2024-05-15 21:36:15 +08:00
ffStrbufAppendC(result, (char) chars[i]);
2026-03-29 09:28:49 +08:00
} else if (chars[i] > 0x007f && chars[i] <= 0x07ff) {
2024-05-15 21:36:15 +08:00
ffStrbufAppendC(result, (char) (0xc0 | evBits(chars[i], 0x1f, 6)));
ffStrbufAppendC(result, (char) (0x80 | evBits(chars[i], 0x3f, 0)));
2026-03-29 09:28:49 +08:00
} else {
2024-05-15 21:36:15 +08:00
ffStrbufAppendC(result, (char) (0xe0 | evBits(chars[i], 0xf, 12)));
ffStrbufAppendC(result, (char) (0x80 | evBits(chars[i], 0x3f, 6)));
ffStrbufAppendC(result, (char) (0x80 | evBits(chars[i], 0x3f, 0)));
}
}
}
2024-05-16 11:12:52 +08:00
2026-03-29 09:28:49 +08:00
bool ffEfiFillLoadOption(const FFEfiLoadOption* efiOption, FFBootmgrResult* result) {
2024-05-16 11:12:52 +08:00
uint32_t descLen = 0;
2026-03-29 09:28:49 +08:00
while (efiOption->Description[descLen]) {
++descLen;
}
2024-05-16 11:12:52 +08:00
2026-03-29 09:28:49 +08:00
if (descLen) {
2024-05-16 11:12:52 +08:00
ffEfiUcs2ToUtf8(efiOption->Description, &result->name);
2026-03-29 09:28:49 +08:00
}
2024-05-16 11:12:52 +08:00
for (
2024-10-25 14:48:11 +08:00
ffEfiDevicePathProtocol* filePathList = (ffEfiDevicePathProtocol*) &efiOption->Description[descLen + 1];
2024-05-16 11:12:52 +08:00
filePathList->Type != 0x7F; // End of Hardware Device Path
2026-03-29 09:28:49 +08:00
filePathList = (ffEfiDevicePathProtocol*) ((uint8_t*) filePathList + filePathList->Length)) {
if (filePathList->Type == 4 && filePathList->SubType == 4) {
2024-05-16 11:12:52 +08:00
// https://uefi.org/specs/UEFI/2.10/10_Protocols_Device_Path_Protocol.html#file-path-media-device-path
ffEfiUcs2ToUtf8((uint16_t*) filePathList->SpecificDevicePathData, &result->firmware);
return true;
}
}
return false;
}